What is SNMP builder? SNMP Builder is an add-in for Zabbix. It provides new web interface components to browse MIB trees and values. SNMP OIDs can then be automatically converted into Zabbix items and inserted into a template. The underlying snmpbuilder script uses calls to NetSNMP in order to communicate with devices on the network.
Maintainers: Zabbix forum members
Original Author: giapnguyen
Digest of Zabbix forum thread concerning SNMP builder: fmrapid
Snmpbuilder is a series of snmp commands. So if the underlying snmp commands fails, it fails too. Most common problems are with MIB files and MIB directories.
SNMPbuilder can be compatible with Versions: 1.8.1, 1.8.2, 1.8.3, 1.8.4RC1. Note: Additionnal patches listed below are required to achieve compatibility with 1.8.2-3 and 1.8.4RC1. It is hoped that someone will spend an hour to merge all patches and update the github code repository.
Active Forum for help on using the add-in
http://www.zabbix.com/forum/showthread.php?t=15088&page=15
Before asking for help, make sure you have patched the script, have tested that the snmp queries work and that the MIB can be loaded.
Debugging
jhgrc forum member noted the following to help debug what is going on with SNMP Builder.
I added a little debugging to snmp_builder.php and also added -LE 2 (do not log message below certain priority level”)
I inserted debug to all snmpcommands (snmpget & snmptranslate) and from log lines I can now see the commands.
Code:
file_put_contents('/tmp/snmpbuilder.log', ”<!– $cmd –>\n”, FILE_APPEND);
Suggested by the original author giapnguyen:
Other suggested improvements by forum members including yours truly.
Code contributions and patches to make the add-in work.
Running zabbix 1.8.2 on CentOs. The following need to be corrected before running snmpbuilder:
1. correct path to JS files:
$page['scripts'] = array('../snmp_builder/Tree.js','../snmp_builder/snmp_builder.js','../snmp_builder/DynTable.js','scriptaculous/effects.js','scriptaculous/dragdrop.js');
Please use Firefox and Firebug to verify that JS files are loading correctly
For some reason the following javascripts need to be added in this specific order.
2. Make sure the JSON module is installed:
yum -y install php-pecl-json
don't forget to restart httpd
3. The a part of the tree showed up but I had an error with snmptranslate which was installed but could not be executed, so I had to change all exec paths to the code:
/usr/local/bin/snmptranslate
How to provided by Alixen
In order to have a working SNMP builder with 1.8.4rc1 PHP frontend, the following patches are required:
# diff -u snmp_builder.php.org snmp_builder.php --- snmp_builder.php.org 2010-10-26 14:27:58.000000000 +0200 +++ snmp_builder.php 2010-10-26 14:28:17.000000000 +0200 @@ -33,7 +33,7 @@ $page["title"] = "SNMP Builder"; $page['file'] = 'snmp_builder.php'; -$page['scripts'] = array('../snmp_builder/Tree.js','../snmp_builder/snmp_builder.js','../snmp_builder/DynTable.js','scriptaculous.js?load=effects,dragdrop'); +$page['scripts'] = array('Tree.js','snmp_builder.js','DynTable.js','effects.js','dragdrop.js'); $page['hist_arg'] = array(); $page['type'] = detect_page_type(); include_once('include/page_header.php');
and
# diff -u jsLoader.php.org jsLoader.php --- jsLoader.php.org 2010-10-26 14:20:11.000000000 +0200 +++ jsLoader.php 2010-10-26 14:22:06.000000000 +0200 @@ -13,6 +13,9 @@ // available scriptas 'scriptFileName' => 'path relative to js/' $availableJScripts = array( + 'Tree.js' => '../snmp_builder/', + 'snmp_builder.js' => '../snmp_builder/', + 'DynTable.js' => '../snmp_builder/', 'common.js' => '', 'menu.js' => '', 'prototype.js' => '',
Patch provided by Alixen
In order to make “Save” in “Item List” work, I had to make one more patch: Code:
# diff -u snmp_builder.php.org snmp_builder.php --- snmp_builder.php.org 2010-10-26 17:10:31.000000000 +0200 +++ snmp_builder.php 2010-10-28 17:44:47.000000000 +0200 @@ -563,7 +566,7 @@ $template = array(); foreach (CTemplate::get($options) as $key => $value) { - array_push($template, array('key' => $key, 'host' => $value['host'])); + array_push($template, array('key' => $value['hostid'], 'host' => $value['host'])); } return $template;
Otherwise, item list cannot be saved in template.
With this patch and those I have already published, SNMP Builder is fully functional on 1.8.4rc1.
The following also needs to be patched to adress the issue of escaping data passed to the underlying snmp commands. This patched was created by jhgrc.
function get_oid_from_name($name) { $name = preg_replace('/"/','\\\\"',$name); file_put_contents('/tmp/snmpbuilder.log', "<!-- snmptranslate -LE 1 -M -m ALL -On $name -->\n", FILE_APPEND); echo "<!-- snmptranslate -LE 1 -M -m ALL -On $name -->\n"; $oid = exec("snmptranslate -LE 1 -M ".MIBS_ALL_PATH." -m ALL -On $name"); if (preg_match('/[0123456789\.]+/', $oid)) return $oid; else return null; }
Now I am able to save keys to Zabbix items. And snmp_builder.php works at least in my case. I have not used it to add router interfaces, but I guess those should work as I've just added escape characters to shell commands
" => \\" (but PHP requires " => \\\\")
Here is a quick fix for my case. But does it break something else?
// idx is number or string thank danrog if (preg_match('/^[0-9]+$/', $idx)) { $cmd = "snmpget -LE 2 -v 2c -c $community -M ".MIBS_ALL_PATH." -m ALL $server_ip $oid.$idx"; } else { #$cmd = "snmpget -LE 2 -v 2c -c $community -M ".MIBS_ALL_PATH." -m ALL $server_ip $oid.\"".$idx."\""; $cmd = "snmpget -LE 2 -v 2c -c $community -M ".MIBS_ALL_PATH." -m ALL $server_ip $oid.$idx"; } $cmd = preg_replace('/"/','\\\\"',$cmd); file_put_contents('/tmp/snmpbuilder.log', "<!-- $cmd -->\n", FILE_APPEND); echo "<!-- $cmd -->\n"; $results = exec($cmd);
- I removes the double quotes in original non-numeric-oid snmpget - Replaces all found double quotes with escaped ones - Some debugging (file & generated html-code)
Patch for missing MIB trees, where snmp_builder.php options to snmptable are listed in the wrong sequence.
SNMP Builder show MIBs tree, but don't show mib tables.
In httpd-error.log:
Must have exactly one table name USAGE: snmptable [OPTIONS] AGENT TABLE-OID Version: 5.4.2.1 Web: http://www.net-snmp.org/ Email: net-snmp-coders@lists.sourceforge.net OPTIONS: -h, --help display this help message ................................................[all keys for snmptable command] Must have exactly one table name USAGE: snmptable [OPTIONS] AGENT TABLE-OID Version: 5.4.2.1 Web: http://www.net-snmp.org/ Email: net-snmp-coders@lists.sourceforge.net OPTIONS:
This problem is connected with the fact that the script snmp_builder.php option to snmptable were listed in the wrong sequence. Verified in:
> snmptable -v 2c -c public -M /usr/local/share/snmp/mibs/ -m CISCO-RTTMON-MIB 172.17.10.1 rttMonCtrlOperTable -Ci -CH -Cf \",\" Must have exactly one table name USAGE: snmptable [OPTIONS] AGENT TABLE-OID Version: 5.4.2.1 Web: http://www.net-snmp.org/ Email: net-snmp-coders@lists.sourceforge.net
, but:
> snmptable -v 2c -c public -M /usr/local/share/snmp/mibs/ -m CISCO-RTTMON-MIB -Ci -CH -Cf \",\" 172.17.10.1 rttMonCtrlOperTable 1","0:0:01:53.85","","0:0:00:00.00","10816","true","false","false","32442","2147483647 seconds","active","false 2","0:0:01:53.87","","0:0:00:00.00","10816","false","false","false","100710","2147483647 seconds","active","false 3","0:0:01:53.89","","0:0:00:00.00","10816","false","false","false","32143","2147483647 seconds","active","false 4","0:0:01:53.91","","0:0:00:00.00","10592","false","false","false","60158","2147483647 seconds","active","false
So I changed the line:
exec("snmptable -v 2c -c $community -M ".MIBS_ALL_PATH." -m ALL $server_ip $oid -Ci -Ch -Cf \",\"", $results);
like so:
exec("snmptable -v 2c -c $community -M ".MIBS_ALL_PATH." -Ci -Ch -Cf \",\" -m ALL $server_ip $oid ", $results);
and:
exec("snmptable -v 2c -c $community -M ".MIBS_ALL_PATH." -m ALL $server_ip $oid -Ci -CH -Cf \",\"", $results);
like so:
exec("snmptable -v 2c -c $community -M ".MIBS_ALL_PATH." -Ci -CH -Cf \",\" -m ALL $server_ip $oid ", $results);
in file snmp_builder.php (lines 489 and 492). I hope this helps and you
Other patches and improvements:
To make it work on the latest 1.8.3 (and probably 1.8.2) do following changes:
in the file snmp_builder.php change
$page['scripts'] = array('../snmp_builder/Tree.js','../snmp_builder/snmp_builder.js','../snmp_builder/DynTable.js','scriptaculou s.js?load=effects,dragdrop');
to the
$page['scripts'] = array('Tree.js','snmp_builder.js','DynTable.js','effects.js','dragdrop.js');
in the file jsLoader.php change
'class.curl.js' => '', 'class.rpc.js' => '', 'class.pmaster.js' => '' );
to the
'class.curl.js' => '', 'class.rpc.js' => '', 'class.pmaster.js' => '', 'Tree.js' => '../snmp_builder/', 'snmp_builder.js' => '../snmp_builder/', 'DynTable.js' => '../snmp_builder/' );
Also, to allow using of the different SNMP port instead of default 161 one in the Server: text box file snmp_builder.php change
if (!preg_match('/^[0-9,\.]+$/i', $_REQUEST['server_ip']))
to the
if (!preg_match('/^[:0-9,\.]+$/i', $_REQUEST['server_ip']))
Than you can use addresses like 192.168.1.1:8161