See www.zabbix.com for the official Zabbix site.

Snmp builder

From Zabbix.org
Jump to: navigation, search
SNMP Builder

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

Features
  • MIB Browser: you can select default MIB files or your own device MIBs to get an OID tree. Click on the tree to retrieve value and information about a OID. Click to transform the OID to a Zabbix item.
  • MIB Browser: uses snmpv2c to connect to remote devices using netSNMP module. To use snmpv1, modify the scripted SNMP calls to use v1 instead of v2c. v1/v2 change is not exposed in the php interface.
  • OID Table support: it assume that a OID whose name's end with string 'Table' is a OID Table. OID Table will retrieve with all it's indexes. Click on the cell to select the index as Zabbix's item. If my above assumption is wrong, you can use the checkbox .view as table. to switch between table and normal view.
  • Column selection: On OID Table, click on a header will select a whole column as Zabbix's items. It's useful if you create SNMP template for a 48 ports switch 8-).
  • Auto convert: This is implemented as a simple conversion from SNMP to Zabbix item.

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: Additional 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.

All patches for Version 2.0.2 are merged on http://github.com/atimonin/snmpbuilder (see README)

Getting Started
 - Install the script as described in the Readme at: https://github.com/giapnguyen/snmpbuilder
 - Make sure php-pecl-json package is installed
 - Make sure NetSNMP is installed
 - Apply all required patches listed in the last section
 - Test SNMP access to you device from the command-line, see the section on testing and debugging.
 - Test SNMP loading of the MIB file. Many MIBs are actually broken from the start and need to be fixed.
 - Fire up the Zabbix web interface and use the SNMP builder pages to create new items based on SNMP OIDs
Getting Help

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 and testing

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', "\n", FILE_APPEND);


Suggested improvements for code contributors and integrators to SNMP Builder

Suggested by the original author giapnguyen:

  • Enter an oid to create zabbix item; sometimes you know an OID and don't want to navigate a tree to add new one. Use snmpbuilder to convert oid into item automatically.
  • Search OIDs by description, OID name and so on
  • Goto mass update after submit items.
  • Edit item lists: Auto convert not work every cases. It would be useful to edit item parameters (unit, delta, interval) before creating the Zabbix item?
  • Detect default MIB directory (edit MIB_ALL_PATH no more)

Other suggested improvements by forum members including yours truly.

  • Provided a toggle in the PHP interface to change from snmpv1 to snmpv2.
  • Provide debugging output for SNMP command-lines directly into the PHP interface (like Cacti does). One of the patches below enables advanced debugging, but this should be configuration via php interface and the output integrated into a web page.
  • Provide more intelligence in parsing common errors. Missing MIB files, missing root, quotes not escaped
  • Have snmpbuilder check to see if the Zabbix version is supported and issue a warning if it is not or may not be.
Patches and hacks

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.

 * DynTable.js
 * snmp_builder.js
 * Tree.js 

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 address 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