Difference between revisions of "SimpleGraph-SNMP"
Jump to navigation
Jump to search
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | =SimpleGraphModule= | ||
+ | |||
{{SimpleGraphModule | {{SimpleGraphModule | ||
|name=SNMP | |name=SNMP | ||
|logo=File:snmp.png | |logo=File:snmp.png | ||
+ | |modulename=snmp | ||
+ | |systemname=SNMPSystem | ||
+ | |url=https://en.wikipedia.org/wiki/Simple_Network_Management_Protocol | ||
+ | |apiname=SNMP4J Simple Network Monitoring Protocol SNMP Java API | ||
+ | |apiurl=http://www.snmp4j.org/ | ||
|documentation=makes Simple Network Monitoring Protocol accessible via SNMP4J | |documentation=makes Simple Network Monitoring Protocol accessible via SNMP4J | ||
− | |||
|storemode=property | |storemode=property | ||
|viewmode=hidden | |viewmode=hidden | ||
Line 13: | Line 19: | ||
<source lang='java'> | <source lang='java'> | ||
String pageCount=".1.3.6.1.2.1.43.10.2.1.4.1"; | String pageCount=".1.3.6.1.2.1.43.10.2.1.4.1"; | ||
− | String | + | String[] printers = { "printer1", "printer2", "printer3"}; // replace with your printer's hostnames |
− | SNMPSystem ss=new SNMPSystem(); | + | for (String printer:printers) { |
− | + | SNMPSystem ss=new SNMPSystem(); | |
− | + | ss.connect(printer); | |
− | + | SimpleNode snmpNode=ss.moveTo(pageCount); | |
− | + | if (snmpNode != null) { | |
− | + | String pages = snmpNode.property("value").toString(); | |
+ | System.out.println(String.format("%40s %8s pages", printer, pages)); | ||
+ | } | ||
} | } | ||
</source> | </source> | ||
=== Result === | === Result === | ||
<pre> | <pre> | ||
− | + | printer1 46592 pages | |
+ | printer2 35713 pages | ||
+ | printer3 16905 pages | ||
</pre> | </pre> | ||
Latest revision as of 10:50, 21 February 2018
SimpleGraphModule
SimpleGraph SNMP module
The SimpleGraph SNMP module makes Simple Network Monitoring Protocol accessible via SNMP4J see SNMP4J Simple Network Monitoring Protocol SNMP Java API.
Sources
- System: SNMPSystem.java
- JUnit-Test: TestSNMPSystem.java
Example
Goal
You'd like to find out the pageCounters of some printers in your network.
JUnit TestCase
String pageCount=".1.3.6.1.2.1.43.10.2.1.4.1";
String[] printers = { "printer1", "printer2", "printer3"}; // replace with your printer's hostnames
for (String printer:printers) {
SNMPSystem ss=new SNMPSystem();
ss.connect(printer);
SimpleNode snmpNode=ss.moveTo(pageCount);
if (snmpNode != null) {
String pages = snmpNode.property("value").toString();
System.out.println(String.format("%40s %8s pages", printer, pages));
}
}
Result
printer1 46592 pages printer2 35713 pages printer3 16905 pages
Explanation
The moveTo function will perform an SNMP walk on the given oid (and it's subtree) and make available the values converted as objects with the proper datatype.
Links
- https://en.wikipedia.org/wiki/Simple_Network_Management_Protocol
- https://stackoverflow.com/questions/22655567/how-to-find-counters-of-printers-through-snmp
- https://stackoverflow.com/questions/16168610/how-to-use-snmp-with-java
- http://www.snmp4j.org/html/download.html
- https://mvnrepository.com/artifact/org.snmp4j/snmp4j/2.5.11