[nic] Patch - Specifiy SNMP Community Name
Thomas O'Brien
thomas at creativebusinessystems.com
Thu Sep 23 16:21:51 PDT 2004
Hello,
These is my first attempt to change/patch any PHP code so go easy on me ;) These
patches are against NIC CVS and it allows the SNMP Community name to be
specified in /nic/config/devices.php. The only thing I couldn't figure out is
how to get the Community name to default to 'public' if one is *not* specified
in /nic/config/devices.php.
Thomas
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
-------------- next part --------------
Index: devices.php.dist
===================================================================
RCS file: /repository/nic/config/devices.php.dist,v
retrieving revision 1.4
diff -u -r1.4 devices.php.dist
--- devices.php.dist 11 Aug 2003 09:27:46 -0000 1.4
+++ devices.php.dist 23 Sep 2004 23:06:10 -0000
@@ -9,6 +9,7 @@
* subsytem: The subsystem on the device that is being checked
* hostname: The is the name that is displayed to the user for the device
* hostspec: The address used to connect to the device
+ * community: The SNMP Community to use. Default is 'public' and cannot be ''
*
* Common Params to most devices.
* port: The port used to connect to the device
@@ -25,6 +26,7 @@
$devices['proxy1']['params'] = array();
$devices['proxy1']['params']['hostspec'] = 'proxy.example.com';
$devices['proxy1']['params']['port'] = '161'; // Squid SNMP port
+$devices['proxy1']['params']['community'] = 'public';
$devices['proxy1']['params']['port'] = '3128'; // Squid listening port
$devices['proxy1']['params']['hostname'] = 'proxy.example.com';
$devices['proxy1']['params']['subsystem'] = 'Proxy';
@@ -36,6 +38,7 @@
$devices['printer1']['params'] = array();
$devices['printer1']['params']['hostspec'] = 'printer.example.com';
$devices['printer1']['params']['port'] = '161';
+$devices['printer1']['params']['community'] = 'public';
$devices['printer1']['params']['hostname'] = 'HP 2100 TN Printer';
$devices['printer1']['params']['subsystem'] = 'Printer';
@@ -46,6 +49,7 @@
$devices['server1']['params'] = array();
$devices['server1']['params']['hostspec'] = 'win2k.example.com';
$devices['server1']['params']['port'] = '161';
+$devices['server1']['params']['community'] = 'public';
$devices['server1']['params']['hostname'] = 'Windows 2000 System';
$devices['server1']['params']['subsystem'] = 'Win2k';
@@ -129,5 +133,7 @@
$devices['ap1']['driver'] = 'xi1510';
$devices['ap1']['params'] = array();
$devices['ap1']['params']['hostspec'] = 'ap1.example.com';
+$devices['ap1']['params']['port'] = '161';
+$devices['ap1']['params']['community'] = 'public';
$devices['ap1']['params']['hostname'] = 'AP-One';
$devices['ap1']['params']['subsystem'] = 'Access Point';
-------------- next part --------------
Index: SNMP.php
===================================================================
RCS file: /repository/nic/lib/Device/SNMP.php,v
retrieving revision 1.3
diff -u -r1.3 SNMP.php
--- SNMP.php 20 May 2004 16:03:00 -0000 1.3
+++ SNMP.php 23 Sep 2004 23:08:44 -0000
@@ -52,7 +52,7 @@
foreach ($this->oids as $oid) {
$details[$oid['name']] = array();
- $details[$oid['name']]['value'] = @snmpget($this->params['hostspec'] . ':' . $this->params['port'], "public", $oid['oid'], $this->params['timeout'], 2);
+ $details[$oid['name']]['value'] = @snmpget($this->params['hostspec'] . ':' . $this->params['port'], $this->params['community'], $oid['oid'], $this->params['timeout'], 2);
$details[$oid['name']]['value'] = $this->_cleanResponce($responce);
@@ -83,7 +83,7 @@
foreach ($this->oids as $oid) {
if ($oid['storeable']) {
$details[$oid['name']] = array();
- $responce = @snmpget($this->params['hostspec'] . ':' . $this->params['port'], "public", $oid['oid'], $this->params['timeout'], 2);
+ $responce = @snmpget($this->params['hostspec'] . ':' . $this->params['port'], $this->params['community'], $oid['oid'], $this->params['timeout'], 2);
$details[$oid['name']]['value'] = $this->_cleanResponce($responce);
if (!array_key_exists('data_type', $oid)) {
-------------- next part --------------
Index: jetdirect.php
===================================================================
RCS file: /repository/nic/lib/Device/jetdirect.php,v
retrieving revision 1.2
diff -u -r1.2 jetdirect.php
--- jetdirect.php 20 May 2004 16:03:00 -0000 1.2
+++ jetdirect.php 23 Sep 2004 23:08:20 -0000
@@ -142,7 +142,7 @@
}
function getStatus() {
- $deviceStatus = @snmpget ($this->params['hostspec'] . ':' . $this->params['port'], "public", ".1.3.6.1.4.1.11.2.3.9.1.1.3.0", $this->params['timeout']);
+ $deviceStatus = @snmpget ($this->params['hostspec'] . ':' . $this->params['port'], $this->params['community'], ".1.3.6.1.4.1.11.2.3.9.1.1.3.0", $this->params['timeout']);
$deviceStatus = $this->_cleanResponce($deviceStatus);
$status = array();
-------------- next part --------------
Index: squid.php
===================================================================
RCS file: /repository/nic/lib/Device/squid.php,v
retrieving revision 1.4
diff -u -r1.4 squid.php
--- squid.php 20 May 2004 16:03:00 -0000 1.4
+++ squid.php 23 Sep 2004 23:09:16 -0000
@@ -194,7 +194,7 @@
}
/*
- $uptime = @snmpget ($this->params['hostspec'] . ':' . $this->params['port'], "public", ".1.3.6.1.4.1.3495.1.1.3.0", $this->params['timeout'], 5);
+ $uptime = @snmpget ($this->params['hostspec'] . ':' . $this->params['port'], $this->params['community'], ".1.3.6.1.4.1.3495.1.1.3.0", $this->params['timeout'], 5);
$status = array();
$status['status'] = ($uptime === false) ? NIC_STATUS_FAULT : NIC_STATUS_NORMAL;
-------------- next part --------------
Index: win2k.php
===================================================================
RCS file: /repository/nic/lib/Device/win2k.php,v
retrieving revision 1.2
diff -u -r1.2 win2k.php
--- win2k.php 20 May 2004 16:03:00 -0000 1.2
+++ win2k.php 23 Sep 2004 23:09:39 -0000
@@ -182,7 +182,7 @@
$status['status'] = NIC_STATUS_NORMAL;
$status['message'] = '';
- $uptime = @snmpget($this->params['hostspec'] . ':' . $this->params['port'], "public", ".1.3.6.1.2.1.1.3.0", $this->params['timeout'], 2);
+ $uptime = @snmpget($this->params['hostspec'] . ':' . $this->params['port'], $this->params['community'], ".1.3.6.1.2.1.1.3.0", $this->params['timeout'], 2);
if ($uptime === false) {
$status['status'] = NIC_STATUS_FAULT;
-------------- next part --------------
Index: xi1510.php
===================================================================
RCS file: /repository/nic/lib/Device/xi1510.php,v
retrieving revision 1.2
diff -u -r1.2 xi1510.php
--- xi1510.php 20 May 2004 16:03:00 -0000 1.2
+++ xi1510.php 23 Sep 2004 23:10:04 -0000
@@ -183,7 +183,7 @@
$status['status'] = NIC_STATUS_NORMAL;
$status['message'] = '';
- $uptime = @snmpget ($this->params['hostspec'] . ':' . $this->params['port'], "public", ".1.3.6.1.2.1.1.3.0", $this->params['timeout'], 2);
+ $uptime = @snmpget ($this->params['hostspec'] . ':' . $this->params['port'], $this->params['community'], ".1.3.6.1.2.1.1.3.0", $this->params['timeout'], 2);
if ($uptime === false) {
$status['status'] = NIC_STATUS_FAULT;
More information about the nic
mailing list