MCPcopy Index your code
hub / github.com/Juniper/netconf-java / main

Method main

examples/snmp_config.java:62–98  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

60
61public class snmp_config {
62 public static void main(String[] args) throws IOException,
63 ParserConfigurationException, SAXException {
64
65 XMLBuilder builder = new XMLBuilder();
66 XML trapGroupConfig = builder.createNewConfig("snmp");
67 XML trapGroup = trapGroupConfig.addPath("trap-group");
68 trapGroup.append("group-name", "new-trap-receiver");
69 XML categories = trapGroup.append("categories");
70 categories.append("chassis");
71 categories.append("link");
72 trapGroup.append("destination-port", "162");
73 XML targets = trapGroup.append("targets");
74 targets.append("name", "10.0.0.1");
75
76 Device device = CreateDevice.createDevice();
77 device.connect();
78
79 //Lock the configuration first
80 boolean isLocked = device.lockConfig();
81 if (!isLocked) {
82 System.out.println("Could not lock configuration. Exit now.");
83 return;
84 }
85
86 //Load and commit the configuration
87 try {
88 device.loadXMLConfiguration(trapGroupConfig.toString(), "merge");
89 device.commit();
90 } catch (LoadException | CommitException e) {
91 System.out.println(e.getMessage());
92 return;
93 }
94
95 //Unlock the configuration and close the device.
96 device.unlockConfig();
97 device.close();
98 }
99}

Callers

nothing calls this directly

Calls 11

createNewConfigMethod · 0.95
addPathMethod · 0.95
appendMethod · 0.95
createDeviceMethod · 0.95
connectMethod · 0.95
lockConfigMethod · 0.95
loadXMLConfigurationMethod · 0.95
toStringMethod · 0.95
commitMethod · 0.95
unlockConfigMethod · 0.95
closeMethod · 0.95

Tested by

no test coverage detected