| 
									
										
										
										
											2009-10-28 13:49:37 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-25 17:30:18 +00:00
										 |  |  | #-r RETRIES            set the number of retries
 | 
					
						
							|  |  |  | #-t TIMEOUT            set the request timeout (in seconds)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #$config['snmp']['timeout'] = 300; # timeout in ms
 | 
					
						
							|  |  |  | #$config['snmp']['retries'] = 6; # how many times to retry the query
 | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2010-02-13 21:45:39 +00:00
										 |  |  | function snmp_get ($device, $oid, $options = NULL, $mib = NULL, $mibdir = NULL)  | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-02-08 03:36:07 +00:00
										 |  |  |   global $debug; global $config; global $runtime_stats; | 
					
						
							| 
									
										
										
										
											2010-02-13 21:45:39 +00:00
										 |  |  |   $cmd  = $config['snmpget'] . " -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port']; | 
					
						
							|  |  |  |   if($options) { $cmd .= " " . $options; } | 
					
						
							|  |  |  |   if($mib) { $cmd .= " -m " . $mib; } | 
					
						
							| 
									
										
										
										
											2010-07-02 19:58:13 +00:00
										 |  |  |   if($mibdir) { $cmd .= " -M " . $mibdir; } else { $cmd .= " -M ".$config['mibdir']; } | 
					
						
							| 
									
										
										
										
											2010-07-05 12:29:37 +00:00
										 |  |  |   #$cmd .= " -t " . $config['snmp']['timeout'] . " -r " . $config['snmp']['retries'];
 | 
					
						
							| 
									
										
										
										
											2010-02-13 21:45:39 +00:00
										 |  |  |   $cmd .= " ".$oid; | 
					
						
							|  |  |  |   if($debug) { echo("$cmd\n"); } | 
					
						
							|  |  |  |   $data = trim(shell_exec($cmd)); | 
					
						
							|  |  |  |   $runtime_stats['snmpget']++; | 
					
						
							|  |  |  |   if($debug) { echo("$data\n"); } | 
					
						
							|  |  |  |   if (is_string($data) && (preg_match("/No Such (Object|Instance)/i", $data) || preg_match("/No more variables left/i", $data))) | 
					
						
							|  |  |  |   { $data = false; } else { return $data; } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function snmp_walk($device, $oid, $options = NULL, $mib = NULL, $mibdir = NULL)  | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   global $debug; global $config; global $runtime_stats; | 
					
						
							| 
									
										
										
										
											2010-06-25 17:30:18 +00:00
										 |  |  |   if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) | 
					
						
							| 
									
										
										
										
											2010-06-16 12:46:52 +00:00
										 |  |  |   {  | 
					
						
							|  |  |  |     $snmpcommand = $config['snmpwalk']; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     $snmpcommand = $config['snmpbulkwalk']; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   $cmd  = $snmpcommand . " -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port']; | 
					
						
							| 
									
										
										
										
											2010-02-13 21:45:39 +00:00
										 |  |  |   if($options) { $cmd .= " $options "; } | 
					
						
							|  |  |  |   if($mib) { $cmd .= " -m $mib"; } | 
					
						
							| 
									
										
										
										
											2010-07-02 19:58:13 +00:00
										 |  |  |   if($mibdir) { $cmd .= " -M " . $mibdir; } else { $cmd .= " -M ".$config['mibdir']; } | 
					
						
							| 
									
										
										
										
											2010-07-05 12:29:37 +00:00
										 |  |  |   #$cmd .= " -t " . $config['snmp']['timeout'] . " -r " . $config['snmp']['retries'];
 | 
					
						
							| 
									
										
										
										
											2010-02-13 21:45:39 +00:00
										 |  |  |   $cmd .= " ".$oid; | 
					
						
							| 
									
										
										
										
											2010-02-08 03:36:07 +00:00
										 |  |  |   if($debug) { echo("$cmd\n"); } | 
					
						
							|  |  |  |   $data = trim(shell_exec($cmd)); | 
					
						
							|  |  |  |   $runtime_stats['snmpwalk']++; | 
					
						
							|  |  |  |   if($debug) { echo("$data\n"); } | 
					
						
							| 
									
										
										
										
											2010-02-13 21:45:39 +00:00
										 |  |  |   if (is_string($data) && (preg_match("/No Such (Object|Instance)/i", $data) || preg_match("/No more variables left/i", $data))) | 
					
						
							|  |  |  |   { $data = false; } else { return $data; } | 
					
						
							| 
									
										
										
										
											2010-02-08 03:36:07 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-13 21:45:39 +00:00
										 |  |  | function snmp_cache_cip($oid, $device, $array, $mib = 0)  | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-10-28 13:49:37 +00:00
										 |  |  |   global $config; | 
					
						
							| 
									
										
										
										
											2010-06-25 17:30:18 +00:00
										 |  |  |   if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) | 
					
						
							| 
									
										
										
										
											2010-06-16 12:46:52 +00:00
										 |  |  |   {  | 
					
						
							|  |  |  |     $snmpcommand = $config['snmpwalk']; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     $snmpcommand = $config['snmpbulkwalk']; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-06-25 17:30:18 +00:00
										 |  |  |   $cmd  = $snmpcommand . " -O snQ -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port']; | 
					
						
							|  |  |  |   if($mib) { $cmd .= " -m $mib"; } | 
					
						
							| 
									
										
										
										
											2010-07-02 19:58:13 +00:00
										 |  |  |   $cmd .= " -M ".$config['install_dir']."/mibs/"; | 
					
						
							| 
									
										
										
										
											2010-07-05 12:29:37 +00:00
										 |  |  |   #$cmd .= " -t " . $config['snmp']['timeout'] . " -r " . $config['snmp']['retries'];
 | 
					
						
							| 
									
										
										
										
											2010-06-25 17:30:18 +00:00
										 |  |  |   $cmd .= " ".$oid; | 
					
						
							| 
									
										
										
										
											2009-10-28 13:49:37 +00:00
										 |  |  |   $data = trim(shell_exec($cmd)); | 
					
						
							|  |  |  |   $device_id = $device['device_id']; | 
					
						
							|  |  |  |   #echo("Caching: $oid\n");
 | 
					
						
							|  |  |  |   foreach(explode("\n", $data) as $entry) { | 
					
						
							| 
									
										
										
										
											2010-06-12 15:17:38 +00:00
										 |  |  |     list ($this_oid, $this_value) = preg_split("/=/", $entry); | 
					
						
							| 
									
										
										
										
											2009-10-28 13:49:37 +00:00
										 |  |  |     $this_oid = trim($this_oid); | 
					
						
							|  |  |  |     $this_value = trim($this_value); | 
					
						
							|  |  |  |     $this_oid = substr($this_oid, 30); | 
					
						
							|  |  |  |     list($ifIndex,$dir,$a,$b,$c,$d,$e,$f) = explode(".", $this_oid); | 
					
						
							|  |  |  |     $h_a = zeropad(dechex($a)); | 
					
						
							|  |  |  |     $h_b = zeropad(dechex($b)); | 
					
						
							|  |  |  |     $h_c = zeropad(dechex($c)); | 
					
						
							|  |  |  |     $h_d = zeropad(dechex($d)); | 
					
						
							|  |  |  |     $h_e = zeropad(dechex($e)); | 
					
						
							|  |  |  |     $h_f = zeropad(dechex($f)); | 
					
						
							|  |  |  |     $mac = "$h_a$h_b$h_c$h_d$h_e$h_f"; | 
					
						
							|  |  |  |     if($dir == "1") { $dir = "input"; } elseif($dir == "2") { $dir = "output"; } | 
					
						
							|  |  |  |     if($mac && $dir) { | 
					
						
							|  |  |  |       $array[$device_id][$ifIndex][$mac][$oid][$dir] = $this_value; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return $array; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function snmp_cache_ifIndex($device) { | 
					
						
							| 
									
										
										
										
											2010-02-13 21:45:39 +00:00
										 |  |  |   global $config; | 
					
						
							| 
									
										
										
										
											2010-06-25 17:30:18 +00:00
										 |  |  |   if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) | 
					
						
							| 
									
										
										
										
											2010-06-16 12:46:52 +00:00
										 |  |  |   {  | 
					
						
							|  |  |  |     $snmpcommand = $config['snmpwalk']; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     $snmpcommand = $config['snmpbulkwalk']; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-06-25 17:30:18 +00:00
										 |  |  |   $cmd  = $snmpcommand . " -O Qs -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port']; | 
					
						
							| 
									
										
										
										
											2010-07-02 19:58:13 +00:00
										 |  |  |   $cmd .= " -M ".$config['install_dir']."/mibs/"; | 
					
						
							|  |  |  |   $cmd .= " -m IF-MIB ifIndex";   | 
					
						
							| 
									
										
										
										
											2010-07-05 12:29:37 +00:00
										 |  |  |   #$cmd .= " -t " . $config['snmp']['timeout'] . " -r " . $config['snmp']['retries'];
 | 
					
						
							| 
									
										
										
										
											2009-10-28 13:49:37 +00:00
										 |  |  |   $data = trim(shell_exec($cmd)); | 
					
						
							|  |  |  |   $device_id = $device['device_id']; | 
					
						
							|  |  |  |   foreach(explode("\n", $data) as $entry) { | 
					
						
							| 
									
										
										
										
											2010-06-12 15:17:38 +00:00
										 |  |  |     list ($this_oid, $this_value) = preg_split("/=/", $entry); | 
					
						
							| 
									
										
										
										
											2009-10-28 13:49:37 +00:00
										 |  |  |     list ($this_oid, $this_index) = explode(".", $this_oid); | 
					
						
							|  |  |  |     $this_index = trim($this_index); | 
					
						
							|  |  |  |     $this_oid = trim($this_oid); | 
					
						
							|  |  |  |     $this_value = trim($this_value); | 
					
						
							| 
									
										
										
										
											2009-11-12 14:53:09 +00:00
										 |  |  |     if(!strstr($this_value, "at this OID") && $this_index) { | 
					
						
							| 
									
										
										
										
											2009-10-28 13:49:37 +00:00
										 |  |  |       $array[] = $this_value; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return $array; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-13 21:45:39 +00:00
										 |  |  | function snmpwalk_cache_oid($poll_oid, $device, $array, $mib = NULL, $mibdir = NULL) { | 
					
						
							| 
									
										
										
										
											2010-03-11 21:58:50 +00:00
										 |  |  |   global $config; global $debug; | 
					
						
							| 
									
										
										
										
											2010-02-13 21:45:39 +00:00
										 |  |  |   $data = snmp_walk($device, $poll_oid, "-OQUs", $mib, $mibdir); | 
					
						
							| 
									
										
										
										
											2009-11-10 19:28:24 +00:00
										 |  |  |   $device_id = $device['device_id']; | 
					
						
							|  |  |  |   foreach(explode("\n", $data) as $entry) { | 
					
						
							|  |  |  |     list($oid,$value) = explode("=", $entry); | 
					
						
							|  |  |  |     $oid = trim($oid); $value = trim($value); | 
					
						
							|  |  |  |     list($oid, $index) = explode(".", $oid); | 
					
						
							| 
									
										
										
										
											2010-01-16 23:58:27 +00:00
										 |  |  |     if (!strstr($value, "at this OID") && isset($oid) && isset($index)) { | 
					
						
							| 
									
										
										
										
											2009-11-10 19:28:24 +00:00
										 |  |  |       $array[$device_id][$index][$oid] = $value; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return $array; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-21 05:08:58 +00:00
										 |  |  | function snmpwalk_cache_multi_oid($device, $oid, $array, $mib = NULL, $mibdir = NULL) { | 
					
						
							|  |  |  |   $data = snmp_walk($device, $oid, "-OQUs", $mib, $mibdir); | 
					
						
							|  |  |  |   foreach(explode("\n", $data) as $entry) { | 
					
						
							|  |  |  |     list($oid,$value) = explode("=", $entry); | 
					
						
							|  |  |  |     $oid = trim($oid); $value = trim($value); | 
					
						
							|  |  |  |     $oid_parts = explode(".", $oid); | 
					
						
							|  |  |  |     $oid = $oid_parts['0']; | 
					
						
							|  |  |  |     $index = $oid_parts['1']; | 
					
						
							|  |  |  |     if(isset($oid_parts['2'])) { $index .= ".".$oid_parts['2']; } | 
					
						
							|  |  |  |     if(isset($oid_parts['3'])) { $index .= ".".$oid_parts['3']; } | 
					
						
							|  |  |  |     if(isset($oid_parts['4'])) { $index .= ".".$oid_parts['4']; } | 
					
						
							|  |  |  |     if(isset($oid_parts['5'])) { $index .= ".".$oid_parts['5']; } | 
					
						
							|  |  |  |     if(isset($oid_parts['6'])) { $index .= ".".$oid_parts['6']; } | 
					
						
							|  |  |  |     if (!strstr($value, "at this OID") && isset($oid) && isset($index)) { | 
					
						
							|  |  |  |       $array[$device[device_id]][$index][$oid] = $value; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return $array; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-13 21:45:39 +00:00
										 |  |  | function snmpwalk_cache_double_oid($device, $oid, $array, $mib = NULL, $mibdir = NULL) { | 
					
						
							|  |  |  |   $data = snmp_walk($device, $oid, "-OQUs", $mib, $mibdir); | 
					
						
							|  |  |  |   foreach(explode("\n", $data) as $entry) { | 
					
						
							|  |  |  |     list($oid,$value) = explode("=", $entry); | 
					
						
							|  |  |  |     $oid = trim($oid); $value = trim($value); | 
					
						
							|  |  |  |     list($oid, $first, $second) = explode(".", $oid); | 
					
						
							|  |  |  |     if (!strstr($value, "at this OID") && isset($oid) && isset($first) && isset($second)) { | 
					
						
							|  |  |  |       $double = $first.".".$second; | 
					
						
							|  |  |  |       $array[$device[device_id]][$double][$oid] = $value; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return $array; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-15 21:02:07 +00:00
										 |  |  | function snmpwalk_cache_triple_oid($device, $oid, $array, $mib = NULL, $mibdir = NULL) { | 
					
						
							|  |  |  |   $data = snmp_walk($device, $oid, "-OQUs", $mib, $mibdir); | 
					
						
							|  |  |  |   foreach(explode("\n", $data) as $entry) { | 
					
						
							|  |  |  |     list($oid,$value) = explode("=", $entry); | 
					
						
							|  |  |  |     $oid = trim($oid); $value = trim($value); | 
					
						
							|  |  |  |     list($oid, $first, $second, $third) = explode(".", $oid); | 
					
						
							|  |  |  |     if (!strstr($value, "at this OID") && isset($oid) && isset($first) && isset($second)) { | 
					
						
							|  |  |  |       $index = $first.".".$second.".".$third; | 
					
						
							|  |  |  |       $array[$device[device_id]][$index][$oid] = $value; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return $array; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-10 15:43:13 +00:00
										 |  |  | function snmpwalk_cache_twopart_oid($oid, $device, $array, $mib = 0) { | 
					
						
							|  |  |  |   global $config; | 
					
						
							| 
									
										
										
										
											2010-06-25 17:30:18 +00:00
										 |  |  |   if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) | 
					
						
							| 
									
										
										
										
											2010-06-16 12:46:52 +00:00
										 |  |  |   {  | 
					
						
							|  |  |  |     $snmpcommand = $config['snmpwalk']; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     $snmpcommand = $config['snmpbulkwalk']; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-06-25 17:30:18 +00:00
										 |  |  |   $cmd  = $snmpcommand . " -O QUs -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port']; | 
					
						
							| 
									
										
										
										
											2010-07-02 19:58:13 +00:00
										 |  |  |   $cmd .= " -M ".$config['install_dir']."/mibs/"; | 
					
						
							| 
									
										
										
										
											2010-06-25 17:30:18 +00:00
										 |  |  |   if($mib) { $cmd .= " -m $mib"; } | 
					
						
							| 
									
										
										
										
											2010-07-05 12:29:37 +00:00
										 |  |  |   #$cmd .= " -t " . $config['snmp']['timeout'] . " -r " . $config['snmp']['retries'];
 | 
					
						
							| 
									
										
										
										
											2010-06-25 17:30:18 +00:00
										 |  |  |   $cmd .= " ".$oid; | 
					
						
							| 
									
										
										
										
											2009-11-10 15:43:13 +00:00
										 |  |  |   $data = trim(shell_exec($cmd)); | 
					
						
							|  |  |  |   $device_id = $device['device_id']; | 
					
						
							|  |  |  |   foreach(explode("\n", $data) as $entry) { | 
					
						
							|  |  |  |     list($oid,$value) = explode("=", $entry); | 
					
						
							| 
									
										
										
										
											2010-02-15 23:56:30 +00:00
										 |  |  |     $oid = trim($oid); $value = trim($value); $value = str_replace("\"", "", $value); | 
					
						
							| 
									
										
										
										
											2009-11-10 15:43:13 +00:00
										 |  |  |     list($oid, $first, $second) = explode(".", $oid); | 
					
						
							| 
									
										
										
										
											2010-01-16 23:58:27 +00:00
										 |  |  |     if (!strstr($value, "at this OID") && isset($oid) && isset($first) && isset($second)) { | 
					
						
							| 
									
										
										
										
											2009-11-10 15:43:13 +00:00
										 |  |  |       $array[$device_id][$first][$second][$oid] = $value; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return $array; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-05 18:40:05 +00:00
										 |  |  | function snmpwalk_cache_threepart_oid($oid, $device, $array, $mib = 0) { | 
					
						
							| 
									
										
										
										
											2010-01-07 16:58:08 +00:00
										 |  |  |   global $config, $debug; | 
					
						
							| 
									
										
										
										
											2010-06-25 17:30:18 +00:00
										 |  |  |   if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) | 
					
						
							| 
									
										
										
										
											2010-06-16 12:46:52 +00:00
										 |  |  |   {  | 
					
						
							|  |  |  |     $snmpcommand = $config['snmpwalk']; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     $snmpcommand = $config['snmpbulkwalk']; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-06-25 17:30:18 +00:00
										 |  |  |   $cmd  = $snmpcommand . " -O QUs -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port']; | 
					
						
							| 
									
										
										
										
											2010-07-02 19:58:13 +00:00
										 |  |  |   $cmd .= " -M ".$config['install_dir']."/mibs/"; | 
					
						
							| 
									
										
										
										
											2010-06-25 17:30:18 +00:00
										 |  |  |   if($mib) { $cmd .= " -m $mib"; } | 
					
						
							| 
									
										
										
										
											2010-07-05 12:29:37 +00:00
										 |  |  |   #$cmd .= " -t " . $config['snmp']['timeout'] . " -r " . $config['snmp']['retries'];
 | 
					
						
							| 
									
										
										
										
											2010-06-25 17:30:18 +00:00
										 |  |  |   $cmd .= " ".$oid; | 
					
						
							| 
									
										
										
										
											2010-01-05 18:40:05 +00:00
										 |  |  |   $data = trim(shell_exec($cmd)); | 
					
						
							|  |  |  |   $device_id = $device['device_id']; | 
					
						
							|  |  |  |   foreach(explode("\n", $data) as $entry) { | 
					
						
							|  |  |  |     list($oid,$value) = explode("=", $entry); | 
					
						
							| 
									
										
										
										
											2010-02-15 23:56:30 +00:00
										 |  |  |     $oid = trim($oid); $value = trim($value); $value = str_replace("\"", "", $value); | 
					
						
							| 
									
										
										
										
											2010-01-05 18:40:05 +00:00
										 |  |  |     list($oid, $first, $second, $third) = explode(".", $oid); | 
					
						
							| 
									
										
										
										
											2010-01-07 16:46:55 +00:00
										 |  |  |     if($debug) {echo("$entry || $oid || $first || $second || $third\n");} | 
					
						
							| 
									
										
										
										
											2010-01-16 23:58:27 +00:00
										 |  |  |     if (!strstr($value, "at this OID") && isset($oid) && isset($first) && isset($second) && isset($third)) { | 
					
						
							| 
									
										
										
										
											2010-01-05 18:40:05 +00:00
										 |  |  |       $array[$device_id][$first][$second][$third][$oid] = $value; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return $array; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-29 09:28:43 +00:00
										 |  |  | function snmp_cache_slotport_oid($oid, $device, $array, $mib = 0) { | 
					
						
							|  |  |  |   global $config; | 
					
						
							| 
									
										
										
										
											2010-06-25 17:30:18 +00:00
										 |  |  |   if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) | 
					
						
							| 
									
										
										
										
											2010-06-16 12:46:52 +00:00
										 |  |  |   {  | 
					
						
							|  |  |  |     $snmpcommand = $config['snmpwalk']; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     $snmpcommand = $config['snmpbulkwalk']; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-06-25 17:30:18 +00:00
										 |  |  |   $cmd  = $snmpcommand . " -O QUs -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port']; | 
					
						
							|  |  |  |   if($mib) { $cmd .= " -m $mib"; } | 
					
						
							| 
									
										
										
										
											2010-07-02 19:58:13 +00:00
										 |  |  |   $cmd .= " -M ".$config['install_dir']."/mibs/"; | 
					
						
							| 
									
										
										
										
											2010-07-05 12:29:37 +00:00
										 |  |  |   #$cmd .= " -t " . $config['snmp']['timeout'] . " -r " . $config['snmp']['retries'];
 | 
					
						
							| 
									
										
										
										
											2010-06-25 17:30:18 +00:00
										 |  |  |   $cmd .= " ".$oid; | 
					
						
							| 
									
										
										
										
											2009-10-29 09:28:43 +00:00
										 |  |  |   $data = trim(shell_exec($cmd)); | 
					
						
							|  |  |  |   $device_id = $device['device_id']; | 
					
						
							|  |  |  |   foreach(explode("\n", $data) as $entry) { | 
					
						
							|  |  |  |     $entry = str_replace($oid.".", "", $entry); | 
					
						
							|  |  |  |     list($slotport, $value) = explode("=", $entry); | 
					
						
							|  |  |  |     $slotport = trim($slotport); $value = trim($value); | 
					
						
							|  |  |  |     if ($array[$device_id][$slotport]['ifIndex']) { | 
					
						
							|  |  |  |       $ifIndex = $array[$device_id][$slotport]['ifIndex']; | 
					
						
							|  |  |  |       #$array[$device_id][$slotport][$oid] = $value;
 | 
					
						
							|  |  |  |       $array[$device_id][$ifIndex][$oid] = $value; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return $array; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-28 13:49:37 +00:00
										 |  |  | function snmp_cache_oid($oid, $device, $array, $mib = 0) { | 
					
						
							|  |  |  |   global $config; | 
					
						
							| 
									
										
										
										
											2010-06-25 17:30:18 +00:00
										 |  |  |   if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) | 
					
						
							| 
									
										
										
										
											2010-06-16 12:46:52 +00:00
										 |  |  |   {  | 
					
						
							|  |  |  |     $snmpcommand = $config['snmpwalk']; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     $snmpcommand = $config['snmpbulkwalk']; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-06-25 17:30:18 +00:00
										 |  |  |   $cmd  = $snmpcommand . " -O UQs -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port']; | 
					
						
							|  |  |  |   if($mib) { $cmd .= " -m $mib"; } | 
					
						
							| 
									
										
										
										
											2010-07-02 19:58:13 +00:00
										 |  |  |   $cmd .= " -M ".$config['install_dir']."/mibs/"; | 
					
						
							| 
									
										
										
										
											2010-07-05 12:29:37 +00:00
										 |  |  |   #$cmd .= " -t " . $config['snmp']['timeout'] . " -r " . $config['snmp']['retries'];
 | 
					
						
							| 
									
										
										
										
											2010-06-25 17:30:18 +00:00
										 |  |  |   $cmd .= " ".$oid; | 
					
						
							| 
									
										
										
										
											2009-10-28 13:49:37 +00:00
										 |  |  |   $data = trim(shell_exec($cmd)); | 
					
						
							|  |  |  |   $device_id = $device['device_id']; | 
					
						
							|  |  |  |   #echo("Caching: $oid\n");
 | 
					
						
							|  |  |  |   foreach(explode("\n", $data) as $entry) { | 
					
						
							| 
									
										
										
										
											2010-06-12 15:17:38 +00:00
										 |  |  |     list ($this_oid, $this_value) = preg_split("/=/", $entry); | 
					
						
							| 
									
										
										
										
											2009-10-28 13:49:37 +00:00
										 |  |  |     list ($this_oid, $this_index) = explode(".", $this_oid); | 
					
						
							|  |  |  |     $this_index = trim($this_index); | 
					
						
							|  |  |  |     $this_oid = trim($this_oid); | 
					
						
							|  |  |  |     $this_value = trim($this_value); | 
					
						
							| 
									
										
										
										
											2009-11-12 14:53:09 +00:00
										 |  |  |     if(!strstr($this_value, "at this OID") && $this_index) { | 
					
						
							| 
									
										
										
										
											2009-10-28 13:49:37 +00:00
										 |  |  |       $array[$device_id][$this_index][$this_oid] = $this_value; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     $array[$device_id][$oid] = '1'; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return $array; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function snmp_cache_port_oids($oids, $port, $device, $array, $mib=0) { | 
					
						
							|  |  |  |   global $config; | 
					
						
							|  |  |  |   foreach($oids as $oid){ | 
					
						
							|  |  |  |     $string .= " $oid.$port"; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-06-25 17:30:18 +00:00
										 |  |  |   $cmd = $config['snmpget'] . " -O vq -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port']; | 
					
						
							| 
									
										
										
										
											2010-07-02 19:58:13 +00:00
										 |  |  |   $cmd .= " -M ".$config['install_dir']."/mibs/"; | 
					
						
							| 
									
										
										
										
											2010-06-25 17:30:18 +00:00
										 |  |  |   if($mib) { $cmd .= " -m $mib"; } | 
					
						
							| 
									
										
										
										
											2010-07-05 12:29:37 +00:00
										 |  |  |   #$cmd .= " -t " . $config['snmp']['timeout'] . " -r " . $config['snmp']['retries'];
 | 
					
						
							| 
									
										
										
										
											2010-06-25 17:30:18 +00:00
										 |  |  |   $cmd .= " ".$string; | 
					
						
							| 
									
										
										
										
											2009-10-28 13:49:37 +00:00
										 |  |  |   $data = trim(shell_exec($cmd)); | 
					
						
							|  |  |  |   $x=0; | 
					
						
							|  |  |  |   $values = explode("\n", $data); | 
					
						
							|  |  |  |   #echo("Caching: ifIndex $port\n");
 | 
					
						
							|  |  |  |   foreach($oids as $oid){ | 
					
						
							| 
									
										
										
										
											2009-11-12 14:53:09 +00:00
										 |  |  |     if(!strstr($values[$x], "at this OID")) { | 
					
						
							| 
									
										
										
										
											2009-10-28 13:49:37 +00:00
										 |  |  |       $array[$device[device_id]][$port][$oid] = $values[$x]; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     $x++; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return $array; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function snmp_cache_portIfIndex ($device, $array) { | 
					
						
							|  |  |  |   global $config; | 
					
						
							| 
									
										
										
										
											2010-06-25 17:30:18 +00:00
										 |  |  |   $cmd = $config['snmpwalk'] . " -CI -m CISCO-STACK-MIB -O q -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port']; | 
					
						
							| 
									
										
										
										
											2010-07-02 19:58:13 +00:00
										 |  |  |   $cmd .= " -M ".$config['install_dir']."/mibs/"; | 
					
						
							| 
									
										
										
										
											2010-07-05 12:29:37 +00:00
										 |  |  |   #$cmd .= " -t " . $config['snmp']['timeout'] . " -r " . $config['snmp']['retries'];
 | 
					
						
							| 
									
										
										
										
											2010-06-25 17:30:18 +00:00
										 |  |  |   $cmd .= " portIfIndex"; | 
					
						
							| 
									
										
										
										
											2009-10-28 13:49:37 +00:00
										 |  |  |   $output = trim(shell_exec($cmd)); | 
					
						
							| 
									
										
										
										
											2009-10-29 09:28:43 +00:00
										 |  |  |   $device_id = $device['device_id']; | 
					
						
							| 
									
										
										
										
											2009-10-28 13:49:37 +00:00
										 |  |  |   foreach(explode("\n", $output) as $entry){ | 
					
						
							|  |  |  |     $entry = str_replace("CISCO-STACK-MIB::portIfIndex.", "", $entry); | 
					
						
							|  |  |  |     list($slotport, $ifIndex) = explode(" ", $entry); | 
					
						
							| 
									
										
										
										
											2009-11-12 11:35:58 +00:00
										 |  |  |     if($slotport && $ifIndex){ | 
					
						
							|  |  |  |       $array[$device_id][$ifIndex]['portIfIndex'] = $slotport; | 
					
						
							|  |  |  |       $array[$device_id][$slotport]['ifIndex'] = $ifIndex; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-10-28 13:49:37 +00:00
										 |  |  |   } | 
					
						
							|  |  |  |   return $array; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function snmp_cache_portName ($device, $array) { | 
					
						
							|  |  |  |   global $config; | 
					
						
							| 
									
										
										
										
											2010-06-25 17:30:18 +00:00
										 |  |  |   $cmd = $config['snmpwalk'] . " -CI -m CISCO-STACK-MIB -O Qs -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port']; | 
					
						
							| 
									
										
										
										
											2010-07-02 19:58:13 +00:00
										 |  |  |   $cmd .= " -M ".$config['install_dir']."/mibs/"; | 
					
						
							| 
									
										
										
										
											2010-07-05 12:29:37 +00:00
										 |  |  |   #$cmd .= " -t " . $config['snmp']['timeout'] . " -r " . $config['snmp']['retries'];
 | 
					
						
							| 
									
										
										
										
											2010-06-25 17:30:18 +00:00
										 |  |  |   $cmd .= " portName"; | 
					
						
							| 
									
										
										
										
											2009-10-28 13:49:37 +00:00
										 |  |  |   $output = trim(shell_exec($cmd)); | 
					
						
							| 
									
										
										
										
											2009-10-29 09:28:43 +00:00
										 |  |  |   $device_id = $device['device_id']; | 
					
						
							| 
									
										
										
										
											2009-10-28 13:49:37 +00:00
										 |  |  |   #echo("Caching: portName\n");
 | 
					
						
							|  |  |  |   foreach(explode("\n", $output) as $entry){ | 
					
						
							|  |  |  |     $entry = str_replace("portName.", "", $entry); | 
					
						
							|  |  |  |     list($slotport, $portName) = explode("=", $entry); | 
					
						
							|  |  |  |     $slotport = trim($slotport); $portName = trim($portName); | 
					
						
							|  |  |  |     if ($array[$device_id][$slotport]['ifIndex']) { | 
					
						
							|  |  |  |       $ifIndex = $array[$device_id][$slotport]['ifIndex']; | 
					
						
							|  |  |  |       $array[$device_id][$slotport]['portName'] = $portName; | 
					
						
							|  |  |  |       $array[$device_id][$ifIndex]['portName'] = $portName; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return $array; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ?>
 |