(String[] args)
| 60 | |
| 61 | public 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 | } |
nothing calls this directly
no test coverage detected