1<?php 2 3error_reporting(0); 4 5if (!isset($called_by_script_server)) { 6 include_once(dirname(__FILE__) . '/../include/cli_check.php'); 7 include_once(dirname(__FILE__) . '/../lib/snmp.php'); 8 9 array_shift($_SERVER['argv']); 10 11 print call_user_func_array('ss_host_disk', $_SERVER['argv']); 12} else { 13 include_once(dirname(__FILE__) . '/../lib/snmp.php'); 14} 15 16function ss_host_disk($hostname, $host_id, $snmp_auth, $cmd, $arg1 = '', $arg2 = '') { 17 $snmp = explode(':', $snmp_auth); 18 $snmp_version = $snmp[0]; 19 $snmp_port = $snmp[1]; 20 $snmp_timeout = $snmp[2]; 21 $ping_retries = $snmp[3]; 22 $max_oids = $snmp[4]; 23 24 $snmp_auth_username = ''; 25 $snmp_auth_password = ''; 26 $snmp_auth_protocol = ''; 27 $snmp_priv_passphrase = ''; 28 $snmp_priv_protocol = ''; 29 $snmp_context = ''; 30 $snmp_community = ''; 31 32 if ($snmp_version == 3) { 33 $snmp_auth_username = $snmp[6]; 34 $snmp_auth_password = $snmp[7]; 35 $snmp_auth_protocol = $snmp[8]; 36 $snmp_priv_passphrase = $snmp[9]; 37 $snmp_priv_protocol = $snmp[10]; 38 $snmp_context = $snmp[11]; 39 } else { 40 $snmp_community = $snmp[5]; 41 } 42 43 $oids = array( 44 'total' => '.1.3.6.1.2.1.25.2.3.1.5', 45 'totalin' => '.1.3.6.1.2.1.25.2.3.1.5', 46 'used' => '.1.3.6.1.2.1.25.2.3.1.6', 47 'failures' => '.1.3.6.1.2.1.25.2.3.1.7', 48 'index' => '.1.3.6.1.2.1.25.2.3.1.1', 49 'description' => '.1.3.6.1.2.1.25.2.3.1.3', 50 'sau' => '.1.3.6.1.2.1.25.2.3.1.4' 51 ); 52 53 if ($cmd == 'index') { 54 $return_arr = ss_host_disk_reindex( 55 cacti_snmp_walk($hostname, $snmp_community, $oids['index'], $snmp_version, $snmp_auth_username, 56 $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, 57 $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER) 58 ); 59 60 if (cacti_sizeof($return_arr)) { 61 foreach ($return_arr as $item) { 62 print $item . "\n"; 63 } 64 } 65 } elseif ($cmd == 'num_indexes') { 66 $return_arr = ss_host_disk_reindex( 67 cacti_snmp_walk($hostname, $snmp_community, $oids['index'], $snmp_version, $snmp_auth_username, 68 $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, 69 $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER) 70 ); 71 72 return cacti_sizeof($return_arr); 73 } elseif ($cmd == 'query') { 74 $arg = $arg1; 75 76 $arr_index = ss_host_disk_reindex( 77 cacti_snmp_walk($hostname, $snmp_community, $oids['index'], $snmp_version, $snmp_auth_username, 78 $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, 79 $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER) 80 ); 81 82 if (cacti_sizeof($arr_index)) { 83 $arr = ss_host_disk_reindex( 84 cacti_snmp_walk($hostname, $snmp_community, $oids[$arg], $snmp_version, $snmp_auth_username, 85 $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, 86 $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER) 87 ); 88 89 if (cacti_sizeof($arr)) { 90 for ($i=0;($i<cacti_sizeof($arr_index));$i++) { 91 if (isset($arr[$i])) { 92 print $arr_index[$i] . '!' . $arr[$i] . "\n"; 93 } else { 94 print $arr_index[$i] . '!' . "Unknown\n"; 95 } 96 } 97 } else { 98 return ''; 99 } 100 } else { 101 return ''; 102 } 103 } elseif ($cmd == 'get') { 104 $arg = $arg1; 105 $index = $arg2; 106 107 $value = api_plugin_hook_function('hmib_get_disk', array('host_id' => $host_id, 'arg' => $arg, 'index' => $index)); 108 109 if (is_array($value)) { 110 if (($arg == 'total') || ($arg == 'used')) { 111 $sau = preg_replace('/[^0-9]/i', '', db_fetch_cell_prepared("SELECT field_value 112 FROM host_snmp_cache 113 WHERE host_id = ? 114 AND field_name = 'hrStorageAllocationUnits' 115 AND snmp_index = ?", 116 array($host_id, $index))); 117 118 $snmp_data = cacti_snmp_get($hostname, $snmp_community, $oids[$arg] . ".$index", $snmp_version, 119 $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, 120 $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, SNMP_POLLER); 121 122 if ($snmp_data < 0) { 123 return (abs($snmp_data) + 2147483647) * $sau; 124 } elseif (is_numeric($snmp_data) && is_numeric($sau)) { 125 return $snmp_data * $sau; 126 } else { 127 return 'U'; 128 } 129 } else { 130 return cacti_snmp_get($hostname, $snmp_community, $oids[$arg] . ".$index", $snmp_version, 131 $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, 132 $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, SNMP_POLLER); 133 } 134 } else { 135 return $value; 136 } 137 } 138} 139 140function ss_host_disk_reindex($arr) { 141 $return_arr = array(); 142 143 if (cacti_sizeof($arr)) { 144 for ($i=0;($i<cacti_sizeof($arr));$i++) { 145 if (!isset($arr[$i]['value'])) { 146 return array(); 147 } 148 149 $return_arr[$i] = $arr[$i]['value']; 150 } 151 } 152 153 return $return_arr; 154} 155 156