diff --git a/InterfaceAdminPlugin.inc.php b/InterfaceAdminPlugin.inc.php index 45a7789..abd9622 100644 --- a/InterfaceAdminPlugin.inc.php +++ b/InterfaceAdminPlugin.inc.php @@ -17,10 +17,6 @@ * Code displayed when loading the plugin */ -if ($config['InterfaceAdminPlugin_snmp_RW'] != '') { - echo ('The InterfaceAdminPlugin is up and running, and RW community is defined in the config.php'); -} else { - echo ('In order to use this Plugin, please define your device SNMP Write community in the config.php file, using the following code :
$config["InterfaceAdminPlugin_snmp_RW"] = "MyLittleRWCommunity";'); -} +echo ('The InterfaceAdminPlugin is up and running'); ?> diff --git a/forms/enable-port.inc.php b/forms/enable-port.inc.php index ef10cd4..8023b96 100644 --- a/forms/enable-port.inc.php +++ b/forms/enable-port.inc.php @@ -62,7 +62,7 @@ * Let's do the SNMP Set to the device * */ - $res = snmp_set($device[hostname], ".1.3.6.1.2.1.2.2.1.7.$port[ifIndex]", 'i', 1); + $res = snmp_set($device, ".1.3.6.1.2.1.2.2.1.7.$port[ifIndex]", 'i', 1); /* * Return the results of the call @@ -72,7 +72,7 @@ if ($res == false) { $message = 'Could not enable '.$port['ifName'].' port'; } elseif ($res == 'community') { - $message = 'Community for WR SNMP not provided in config.php'; + $message = 'Community in LibreNMS is probably ReadOnly. No answer from device with current community'; $status = 'error'; } elseif ($res == 'multiple-oid') { diff --git a/forms/shutdown-port.inc.php b/forms/shutdown-port.inc.php index b3cd125..9902262 100644 --- a/forms/shutdown-port.inc.php +++ b/forms/shutdown-port.inc.php @@ -62,7 +62,7 @@ * Let's do the SNMP Set to the device * */ - $res = snmp_set($device[hostname], ".1.3.6.1.2.1.2.2.1.7.$port[ifIndex]", 'i', 2); + $res = snmp_set($device, ".1.3.6.1.2.1.2.2.1.7.$port[ifIndex]", 'i', 2); /* @@ -72,7 +72,7 @@ if ($res == false) { $message = 'Could not disable '.$port['ifName'].' port'; } elseif ($res == 'community') { - $message = 'Community for WR SNMP not provided in config.php'; + $message = 'Community in LibreNMS is probably ReadOnly. No answer from device with current community'; $status = 'error'; } elseif ($res == 'multiple-oid') { diff --git a/include/snmp.inc.php b/include/snmp.inc.php index 3cd7835..d74f495 100644 --- a/include/snmp.inc.php +++ b/include/snmp.inc.php @@ -12,9 +12,12 @@ * the source code distribution for details. */ + +include "../../../includes/snmp.inc.php"; + /* function snmp_set($device, $oid, $type, $value, $options = null, $mib = null, $mibdir = null) * - * Execute SNMP Set on device, using $config['InterfaceAdminPlugin_snmp_RW'] + * Execute SNMP Set on device, using default LibreNMS community settings for current device */ function snmp_set($device, $oid, $type, $value, $options = null) @@ -27,26 +30,25 @@ function snmp_set($device, $oid, $type, $value, $options = null) return 'multiple-oid'; } - if (!isset($config['InterfaceAdminPlugin_snmp_RW']) || $config['InterfaceAdminPlugin_snmp_RW'] == '') { - //echo ('No SNMP Write Community provided in config file ( $config["InterfaceAdminPlugin_snmp_RW"])'); - return 'community'; - } - - $community = $config['InterfaceAdminPlugin_snmp_RW']; + $snmpAuth = snmp_gen_auth($device); $value=addslashes($value); - $cmd= "snmpset -v2c $options -c $community $device $oid $type '".$value."'"; + $cmd= "snmpset $snmpAuth $options ".' '.$device[transport].':'.$device[hostname].':'.$device[port]." $oid $type '".$value."'"; $data = trim(external_exec($cmd), "\" \n\r"); $res = $data; recordSnmpStatistic('snmpset', $time_start); if (preg_match('/(No Such Instance|No Such Object|No more variables left|Authentication failure)/i', $data)) { return false; - } elseif ($data || $data === '0') { - return $res; - } else { - return false; + } elseif (preg_match('/(No Access)/i', $data)) { + return 'community'; + } elseif ($data || $data === '0') { + return $data; + } elseif ($data =='') { + return 'community'; + } else { + return false; //$cmd." :". $data.":"; } - return false; + return $data; }//end snmp_set() ?>