1 25 package org.jrobin.mrtg.client; 26 27 import org.apache.xmlrpc.XmlRpcClient; 28 import org.apache.xmlrpc.XmlRpcException; 29 import org.jrobin.mrtg.MrtgConstants; 30 31 import java.io.IOException ; 32 import java.util.Date ; 33 import java.util.Hashtable ; 34 import java.util.Vector ; 35 36 class RpcClient implements MrtgConstants { 37 38 private XmlRpcClient webClient; 39 40 RpcClient(String host) throws IOException { 41 webClient = new XmlRpcClient(host, SERVER_PORT); 42 } 43 44 Hashtable getMrtgInfo() throws IOException , XmlRpcException { 45 Vector params = new Vector (); 46 return (Hashtable ) webClient.execute("mrtg.getMrtgInfo", params); 47 } 48 49 byte[] getPngGraph(RouterInfo routerInfo, LinkInfo linkInfo, Date start, Date stop) 50 throws IOException , XmlRpcException { 51 Vector params = new Vector (); 52 params.add(routerInfo.getHost()); 53 params.add(linkInfo.getIfDescr()); 54 params.add(start); 55 params.add(stop); 56 return (byte[]) webClient.execute("mrtg.getPngGraph", params); 57 } 58 59 int addRouter(RouterInfo routerInfo) 60 throws IOException , XmlRpcException { 61 Vector params = new Vector (); 62 params.add(routerInfo.getHost()); 63 params.add(routerInfo.getCommunity()); 64 params.add(routerInfo.getDescr()); 65 params.add(new Boolean (routerInfo.isActive())); 66 return ((Integer ) webClient.execute("mrtg.addRouter", params)).intValue(); 67 } 68 69 int updateRouter(RouterInfo routerInfo) 70 throws IOException , XmlRpcException { 71 Vector params = new Vector (); 72 params.add(routerInfo.getHost()); 73 params.add(routerInfo.getCommunity()); 74 params.add(routerInfo.getDescr()); 75 params.add(new Boolean (routerInfo.isActive())); 76 return ((Integer ) webClient.execute("mrtg.updateRouter", params)).intValue(); 77 } 78 79 int deleteRouter(RouterInfo routerInfo) throws IOException , XmlRpcException { 80 Vector params = new Vector (); 81 params.add(routerInfo.getHost()); 82 return ((Integer ) webClient.execute("mrtg.removeRouter", params)).intValue(); 83 } 84 85 Vector getAvailableLinks(RouterInfo routerInfo) 86 throws IOException , XmlRpcException { 87 Vector params = new Vector (); 88 params.add(routerInfo.getHost()); 89 Vector result = (Vector ) webClient.execute("mrtg.getAvailableLinks", params); 90 return result; 91 } 92 93 int addLink(RouterInfo routerInfo, LinkInfo linkInfo) throws XmlRpcException, IOException { 94 Vector params = new Vector (); 95 params.add(routerInfo.getHost()); 96 params.add(linkInfo.getIfDescr()); 97 params.add(linkInfo.getDescr()); 98 params.add(new Integer (linkInfo.getSamplingInterval())); 99 params.add(new Boolean (linkInfo.isActive())); 100 return ((Integer ) webClient.execute("mrtg.addLink", params)).intValue(); 101 } 102 103 int updateLink(RouterInfo routerInfo, LinkInfo linkInfo) 104 throws XmlRpcException, IOException { 105 Vector params = new Vector (); 106 params.add(routerInfo.getHost()); 107 params.add(linkInfo.getIfDescr()); 108 params.add(linkInfo.getDescr()); 109 params.add(new Integer (linkInfo.getSamplingInterval())); 110 params.add(new Boolean (linkInfo.isActive())); 111 return ((Integer ) webClient.execute("mrtg.updateLink", params)).intValue(); 112 } 113 114 int removeLink(RouterInfo routerInfo, LinkInfo linkInfo) 115 throws XmlRpcException, IOException { 116 Vector params = new Vector (); 117 params.add(routerInfo.getHost()); 118 params.add(linkInfo.getIfDescr()); 119 return ((Integer ) webClient.execute("mrtg.removeLink", params)).intValue(); 120 } 121 } 122 | Popular Tags |