From a88d72381f11b89a7da26cd6630a1e4bbae53fd9 Mon Sep 17 00:00:00 2001 From: netniV Date: Fri, 5 Jan 2018 09:21:23 +0000 Subject: [PATCH] Version 0.7 as taken from http://www.eric-a-hall.com/software/cacti-netsnmp-memory/ --- scripts/ss_netsnmp_memory.php | 385 +++++++++ templates/netsnmp_memory_graph_template.xml | 841 ++++++++++++++++++++ 2 files changed, 1226 insertions(+) create mode 100644 scripts/ss_netsnmp_memory.php create mode 100644 templates/netsnmp_memory_graph_template.xml diff --git a/scripts/ss_netsnmp_memory.php b/scripts/ss_netsnmp_memory.php new file mode 100644 index 0000000..24652e1 --- /dev/null +++ b/scripts/ss_netsnmp_memory.php @@ -0,0 +1,385 @@ + 11) { + + echo ("FATAL: Too many elements in SNMP parameter bundle\n"); + ss_netsnmp_memory_syntax(); + return; + } + + # + # 1st bundle element is $snmp_hostname + # + $snmp_hostname = trim($protocol_array[0]); + + if ($snmp_hostname == "") { + + echo ("FATAL: Hostname not specified in SNMP parameter bundle\n"); + ss_netsnmp_memory_syntax(); + return; + } + + # + # 2nd bundle element is $snmp_version + # + $snmp_version = trim($protocol_array[1]); + + if ($snmp_version == "") { + + echo ("FATAL: SNMP version not specified in SNMP parameter bundle\n"); + ss_netsnmp_memory_syntax(); + return; + } + + if (($snmp_version != 1) and ($snmp_version != 2) and ($snmp_version != 3)) { + + echo ("FATAL: \"$snmp_version\" is not a valid SNMP version\n"); + ss_netsnmp_memory_syntax(); + return; + } + + # + # 3rd bundle element is $snmp_community + # + $snmp_community = trim($protocol_array[2]); + + if (($snmp_version != 3) and ($snmp_community == "")) { + + echo ("FATAL: SNMP v$snmp_version community not specified in SNMP parameter bundle\n"); + ss_netsnmp_memory_syntax(); + return; + } + + # + # 4th bundle element is $snmp_v3_username + # + $snmp_v3_username = trim($protocol_array[3]); + + # + # 5th bundle element is $snmp_v3_password + # + $snmp_v3_password = trim($protocol_array[4]); + + # + # 6th bundle element is $snmp_v3_authproto + # + $snmp_v3_authproto = trim($protocol_array[5]); + + # + # 7th bundle element is $snmp_v3_privpass + # + $snmp_v3_privpass = trim($protocol_array[6]); + + # + # 8th bundle element is $snmp_v3_privproto + # + $snmp_v3_privproto = trim($protocol_array[7]); + + # + # 9th bundle element is $snmp_v3_context + # + $snmp_v3_context = trim($protocol_array[8]); + + # + # 10th bundle element is $snmp_port + # + $snmp_port = trim($protocol_array[9]); + + if ($snmp_port == "") { + + # + # if the value was omitted use the default port number + # + $snmp_port = 161; + } + + if (is_numeric($snmp_port) == FALSE) { + + echo ("FATAL: Non-numeric SNMP port \"$snmp_port\" specified in SNMP parameter bundle\n"); + ss_netsnmp_memory_syntax(); + return; + } + + # + # 11th bundle element is $snmp_timeout + # + $snmp_timeout = trim($protocol_array[10]); + + if ($snmp_timeout == "") { + + # + # if the value was omitted use the Cacti SNMP timeout + # + if (isset($GLOBALS['config']['config_options_array']['snmp_timeout'])) { + + $snmp_timeout = trim($GLOBALS['config']['config_options_array']['snmp_timeout']); + } + + elseif (isset($GLOBALS['_SESSION']['sess_config_array']['snmp_timeout'])) { + + $snmp_timeout = trim($GLOBALS['_SESSION']['sess_config_array']['snmp_timeout']); + } + + else { + echo ("FATAL: Timeout not specified in SNMP parameter bundle and " . + "unable to determine Cacti default\n"); + ss_netsnmp_memory_syntax(); + return; + } + } + + if (is_numeric($snmp_timeout) == FALSE) { + + echo ("FATAL: Non-numeric SNMP timeout \"$snmp_timeout\" specified in SNMP parameter bundle\n"); + ss_netsnmp_memory_syntax(); + return; + } + + # + # Cacti's SNMP timeout uses milliseconds, while PHP uses Net-SNMP foormat, which is + # typically microseconds. Normalize by multiplying the timeout value by 1000. + # + $snmp_timeout = ($snmp_timeout * 1000); + + # + # build a nested array of data elements for future use + # + $oid_array = array ("totalReal" => ".1.3.6.1.2.1.25.2.2.0", + "availReal" => ".1.3.6.1.4.1.2021.4.6.0", + "totalSwap" => ".1.3.6.1.4.1.2021.4.3.0", + "availSwap" => ".1.3.6.1.4.1.2021.4.4.0", + "memBuffer" => ".1.3.6.1.4.1.2021.4.14.0", + "memCached" => ".1.3.6.1.4.1.2021.4.15.0"); + + # + # build the snmp_arguments array for future use + # + # note that the array structure varies according to the version of Cacti in use + # + if (isset($GLOBALS['config']['cacti_version']) == FALSE) { + + echo ("FATAL: Unable to determine Cacti version\n"); + return; + } + + elseif (substr($GLOBALS['config']['cacti_version'],0,5) == "0.8.6") { + $snmp_arguments = array( + $snmp_hostname, + $snmp_community, + "", + $snmp_version, + $snmp_v3_username, + $snmp_v3_password, + $snmp_port, + $snmp_timeout, + "", + ""); + } + + elseif (substr($GLOBALS['config']['cacti_version'],0,5) >= "0.8.7") { + $snmp_arguments = array( + $snmp_hostname, + $snmp_community, + "", + $snmp_version, + $snmp_v3_username, + $snmp_v3_password, + $snmp_v3_authproto, + $snmp_v3_privpass, + $snmp_v3_privproto, + $snmp_v3_context, + $snmp_port, + $snmp_timeout, + "", + ""); + } + + else { + echo ("FATAL: \"" . $GLOBALS['config']['cacti_version'] . + "\" is not a supported Cacti version\n"); + return; + } + + # + # query for each OID in $oid_array + # + foreach ($oid_array as $label => $oid) { + + # + # use next OID for $snmp_arguments array and query + # + $snmp_arguments[2] = $oid; + + # + # create the memory array element from the snmp query results + # + $mem_array[$label] = trim(call_user_func_array("cacti_snmp_get", $snmp_arguments)); + + # + # verify snmp response data + # + if ((isset($mem_array[$label] ) == FALSE) || + (substr($mem_array[$label] , 0, 16) == "No Such Instance")) { + + echo ("FATAL: Unable to read memory data from SNMP\n"); + return; + } + + # + # replace NULL with zero + # + if ($mem_array[$label] == "") { + + $mem_array[$label] = 0; + } + + # + # make sure the data only contains numbers + # + if (is_numeric($mem_array[$label] ) == FALSE) { + + # + # ignore "kB" or "KBytes" if it exists + # + if ((substr($mem_array[$label], -2) == "kB") || + (substr($mem_array[$label], -6) == "KBytes")) { + + $mem_array[$label] = intval($mem_array[$label] ); + } + + # + # zero out any remaining non-numeric responses + # + else { + $mem_array[$label] = 0; + } + } + } + + # + # determine extra memory values, so somebody else doesn't have to + # + $mem_array['usedReal'] = ($mem_array['totalReal'] - ($mem_array['availReal'] + + $mem_array['memBuffer'] + $mem_array['memCached'])); + + $mem_array['usedSwap'] = ($mem_array['totalSwap'] - $mem_array['availSwap']); + + # + # generate output + # + $output = ""; + + # + # concatenate the elements of $mem_array into a single string + # + foreach ($mem_array as $key => $value) { + + $output = $output . $key . ":" . $value . " "; + } + + $output = trim($output); + + # + # return the string + # + if (isset($GLOBALS['called_by_script_server']) == TRUE) { + + return($output); + } + + else { + echo ($output . "\n"); + } +} + +# +# display the syntax +# +function ss_netsnmp_memory_syntax() { + + echo ("Syntax: ss_netsnmp_memory.php ::[]:\ \n" . + " []:[]:[]:[]:\ \n" . + " []:[]:[}:[] \n"); +} + +?> diff --git a/templates/netsnmp_memory_graph_template.xml b/templates/netsnmp_memory_graph_template.xml new file mode 100644 index 0000000..9706a04 --- /dev/null +++ b/templates/netsnmp_memory_graph_template.xml @@ -0,0 +1,841 @@ + + + Host Memory - ucd/net - Memory Usage + + + |host_description| - Memory Usage + + 1 + + 120 + + 500 + 0 + on + + on + + 2 + + + 0 + + + + + on + + on + + 0 + + 0 + + 1024 + + + + + + bytes + + + + hash_080003a05184f5255edf0d433cb818b788afce + 862F2F + FF + 7 + 1 + hash_050003634a23af5e78af0964e8d33b1a4ed26b + + hash_060003e9c43831e54eca8069317a2ce8c6f751 + Used Real + + 1 + + + hash_080003a05184f5255edf0d433cb818b788afce + 0 + FF + 9 + 4 + hash_050003634a23af5e78af0964e8d33b1a4ed26b + + hash_060003e9c43831e54eca8069317a2ce8c6f751 + Current: + + 2 + + + hash_080003a05184f5255edf0d433cb818b788afce + 0 + FF + 9 + 1 + hash_050003634a23af5e78af0964e8d33b1a4ed26b + + hash_060003e9c43831e54eca8069317a2ce8c6f751 + Average: + + 3 + + + hash_080003a05184f5255edf0d433cb818b788afce + 0 + FF + 9 + 2 + hash_050003634a23af5e78af0964e8d33b1a4ed26b + + hash_060003e9c43831e54eca8069317a2ce8c6f751 + Minimum: + + 4 + + + hash_080003a05184f5255edf0d433cb818b788afce + 0 + FF + 9 + 3 + hash_050003634a23af5e78af0964e8d33b1a4ed26b + + hash_060003e9c43831e54eca8069317a2ce8c6f751 + Maximum: + on + 5 + + + hash_080003f16053962f2fd6b4ba15a6e20f9042f8 + EA8F00 + FF + 8 + 1 + hash_050003634a23af5e78af0964e8d33b1a4ed26b + + hash_060003e9c43831e54eca8069317a2ce8c6f751 + Buffers + + 6 + + + hash_080003f16053962f2fd6b4ba15a6e20f9042f8 + 0 + FF + 9 + 4 + hash_050003634a23af5e78af0964e8d33b1a4ed26b + + hash_060003e9c43831e54eca8069317a2ce8c6f751 + Current: + + 7 + + + hash_080003f16053962f2fd6b4ba15a6e20f9042f8 + 0 + FF + 9 + 1 + hash_050003634a23af5e78af0964e8d33b1a4ed26b + + hash_060003e9c43831e54eca8069317a2ce8c6f751 + Average: + + 8 + + + hash_080003f16053962f2fd6b4ba15a6e20f9042f8 + 0 + FF + 9 + 2 + hash_050003634a23af5e78af0964e8d33b1a4ed26b + + hash_060003e9c43831e54eca8069317a2ce8c6f751 + Minimum: + + 9 + + + hash_080003f16053962f2fd6b4ba15a6e20f9042f8 + 0 + FF + 9 + 3 + hash_050003634a23af5e78af0964e8d33b1a4ed26b + + hash_060003e9c43831e54eca8069317a2ce8c6f751 + Maximum: + on + 10 + + + hash_0800036584c1db510c08785e6ec50dc7f8f34e + FFC73B + FF + 8 + 1 + hash_050003634a23af5e78af0964e8d33b1a4ed26b + + hash_060003e9c43831e54eca8069317a2ce8c6f751 + Cache + + 11 + + + hash_0800036584c1db510c08785e6ec50dc7f8f34e + 0 + FF + 9 + 4 + hash_050003634a23af5e78af0964e8d33b1a4ed26b + + hash_060003e9c43831e54eca8069317a2ce8c6f751 + Current: + + 12 + + + hash_0800036584c1db510c08785e6ec50dc7f8f34e + 0 + FF + 9 + 1 + hash_050003634a23af5e78af0964e8d33b1a4ed26b + + hash_060003e9c43831e54eca8069317a2ce8c6f751 + Average: + + 13 + + + hash_0800036584c1db510c08785e6ec50dc7f8f34e + 0 + FF + 9 + 2 + hash_050003634a23af5e78af0964e8d33b1a4ed26b + + hash_060003e9c43831e54eca8069317a2ce8c6f751 + Minimum: + + 14 + + + hash_0800036584c1db510c08785e6ec50dc7f8f34e + 0 + FF + 9 + 3 + hash_050003634a23af5e78af0964e8d33b1a4ed26b + + hash_060003e9c43831e54eca8069317a2ce8c6f751 + Maximum: + on + 15 + + + hash_0800033733b38d9d8f13e3fb56d1d8a2fc926c + 74C366 + FF + 8 + 1 + hash_050003634a23af5e78af0964e8d33b1a4ed26b + + hash_060003e9c43831e54eca8069317a2ce8c6f751 + Unused Real + + 16 + + + hash_0800033733b38d9d8f13e3fb56d1d8a2fc926c + 0 + FF + 9 + 4 + hash_050003634a23af5e78af0964e8d33b1a4ed26b + + hash_060003e9c43831e54eca8069317a2ce8c6f751 + Current: + + 17 + + + hash_0800033733b38d9d8f13e3fb56d1d8a2fc926c + 0 + FF + 9 + 1 + hash_050003634a23af5e78af0964e8d33b1a4ed26b + + hash_060003e9c43831e54eca8069317a2ce8c6f751 + Average: + + 18 + + + hash_0800033733b38d9d8f13e3fb56d1d8a2fc926c + 0 + FF + 9 + 2 + hash_050003634a23af5e78af0964e8d33b1a4ed26b + + hash_060003e9c43831e54eca8069317a2ce8c6f751 + Minimum: + + 19 + + + hash_0800033733b38d9d8f13e3fb56d1d8a2fc926c + 0 + FF + 9 + 3 + hash_050003634a23af5e78af0964e8d33b1a4ed26b + + hash_060003e9c43831e54eca8069317a2ce8c6f751 + Maximum: + on + 20 + + + hash_0800038c61f584d287664da6f4a1a3ac299930 + FFC3C0 + FF + 8 + 1 + hash_050003634a23af5e78af0964e8d33b1a4ed26b + + hash_060003e9c43831e54eca8069317a2ce8c6f751 + Used Swap + + 21 + + + hash_0800038c61f584d287664da6f4a1a3ac299930 + 0 + FF + 9 + 4 + hash_050003634a23af5e78af0964e8d33b1a4ed26b + + hash_060003e9c43831e54eca8069317a2ce8c6f751 + Current: + + 22 + + + hash_0800038c61f584d287664da6f4a1a3ac299930 + 0 + FF + 9 + 1 + hash_050003634a23af5e78af0964e8d33b1a4ed26b + + hash_060003e9c43831e54eca8069317a2ce8c6f751 + Average: + + 23 + + + hash_0800038c61f584d287664da6f4a1a3ac299930 + 0 + FF + 9 + 2 + hash_050003634a23af5e78af0964e8d33b1a4ed26b + + hash_060003e9c43831e54eca8069317a2ce8c6f751 + Minimum: + + 24 + + + hash_0800038c61f584d287664da6f4a1a3ac299930 + 0 + FF + 9 + 3 + hash_050003634a23af5e78af0964e8d33b1a4ed26b + + hash_060003e9c43831e54eca8069317a2ce8c6f751 + Maximum: + on + 25 + + + hash_080003ca3b962da8cf74165184937db6d368dc + 000000 + FF + 4 + 1 + hash_050003634a23af5e78af0964e8d33b1a4ed26b + + hash_060003e9c43831e54eca8069317a2ce8c6f751 + Total Real + + 26 + + + hash_080003ca3b962da8cf74165184937db6d368dc + 0 + FF + 9 + 4 + hash_050003634a23af5e78af0964e8d33b1a4ed26b + + hash_060003e9c43831e54eca8069317a2ce8c6f751 + Current: + on + 27 + + + + + Data Source [totalReal] + + task_item_id + hash_00000301b0aef3652b53e7b63d81061aa92cc3|hash_00000327b9f7a2eaed7ec59a39ad3aeb3e3f61 + + + Data Source [usedMem] + + task_item_id + hash_000003e25035089e948e06c493cf4dd5aef242|hash_000003f84a571e578108bfdd1582f91b72a724|hash_000003c039eb603e3c9b64c0c2fc34dde6f4b5|hash_0000032eae8cc0e3ae4990d5206b69e91d745d|hash_0000037269261f810da3e62b544abe237d8771 + + + Data Source [memCached] + + task_item_id + hash_000003d303ce39cae0668028212d3be79589a1|hash_0000036a351d4ff32906fd85570f1376f4c8f1|hash_000003e30bfeb739369b30df3a7784b3cf7648|hash_0000036b36bcc15e7a748d0468a5fb6cac211d|hash_000003bccf517b6e033d2782c0977073f9d092 + + + Data Source [availReal] + + task_item_id + hash_0000039a44cb92ae745e4c6f021689bacb75e7|hash_000003616bd6c7ec24a2e8d135f7fc901ad0e6|hash_000003a31bab249f909ff5b53e6e51dcfbf64e|hash_0000034f34c80eea4feaf5ba3a1be51b0e9610|hash_0000033e10cea5121314627c66065fc31c7f26 + + + Data Source [usedSwap] + + task_item_id + hash_000003162a54ee8030fb1db9ceac3ea3ea6186|hash_0000037486d99b05836b1c8af880c870ed24c2|hash_00000323d8a919ff2cc35c591e2b74b9b70398|hash_00000336b0b9f6acdcba944f370eedea9e070f|hash_000003d7a3bf67f6e3b7b1a7f724ad6c4e64ee + + + Data Source [memBuffer] + + task_item_id + hash_0000034e2e4ffd3e1d8db0d8b522a12c599c6c|hash_000003f55a1bde7742f2f7b83cbff22eda0f0a|hash_000003e2a26becd72b542ae590e610d2b41357|hash_000003b248fa87ef7068ce4a59c27901d84c5c|hash_000003bf251c6162c7e6194e424c0a3f15cf63 + + + + + ucd/net - Memory Usage + + + |host_description| - Memory Usage + hash_0300038e556220d403fc98b23e690088f96474 + + + 300 + + on + hash_150003c21df5178e5c955013591239eb0afd46|hash_1500030d9c0af8b8acdc7807943937b3208e29|hash_1500036fc2d038fb42950138b0ce3e9874cc60|hash_150003e36f3adb9f152adfa5dc50fd2b23337e|hash_150003283ea2bf1634d92ce081ec82a634f513 + + + + + usedReal + + 0 + + 0 + + 1 + + 600 + + hash_070003787d10e5e6346e77d8ecfd95551f60b7 + + + + totalReal + + 0 + + 0 + + 1 + + 600 + + hash_07000345d116204cdaa69672da40681d73175d + + + + memCached + + 0 + + 0 + + 1 + + 600 + + hash_0700035618afca552b03cc8c893bf347b81b82 + + + + memBuffer + + 0 + + 0 + + 1 + + 600 + + hash_070003bb667f71df75ca81072155693a7456a8 + + + + availSwap + + 0 + + 0 + + 1 + + 600 + + hash_07000370d411e4f07f74fa5cf1ef4d4c29bf9c + + + + totalSwap + + 0 + + 0 + + 1 + + 600 + + hash_070003df81713f892f4e969b77dd6d948a79c4 + + + + availReal + + 0 + + 0 + + 1 + + 600 + + hash_0700035aca8602e80d9061f0bc3253ccea760d + + + + usedSwap + + 0 + + 0 + + 1 + + 600 + + hash_070003c5fed724e9aba2b0467c36d053b748fa + + + + + hash_07000347d9bb7e51bfde0d28835501dbd35381 + + + + + hash_0700036239cfa08a3fbaf0085780fc90efb1eb + + + + + hash_07000367d9e6b66844aa5d966a5fa798817456 + + + + + hash_070003e3265a4de7e403ecb80cc36e0875aa67 + + + + + hash_0700036d4cbe6e6cd5e5ce6c534356559a9536 + + + + + hash_0700034c04a173fca89d42f85ef40a68d3af37 + + + + + hash_0700034d495e10d1c702485c4753bdc41910d6 + + + + + + + ucd/net - Memory Usage + 5 + <path_cacti>/scripts/ss_netsnmp_memory.php ss_netsnmp_memory <hostname>:<snmp_ver>:<snmp_community>:<snmp3_username>:<snmp3_password>:<snmp3_authprot>:<snmp3_privpass>:<snmp3_privprot>:<snmp3_context>:<snmp_port>:<snmp_timeout> + + + SNMP port number + + + + snmp_port + in + snmp_port + + + Timeout for SNMP queries + + + + snmp_timeout + in + snmp_timeout + + + SNMPv3 user password + + + on + snmp_password + in + snmp3_password + + + Memory allocated to processes + on + + + + out + usedReal + + + SNMPv3 username + + + on + snmp_username + in + snmp3_username + + + Swap memory allocated + on + + + + out + usedSwap + + + SNMP community + + + on + snmp_community + in + snmp_community + + + Target hostname/IP address + + + + hostname + in + hostname + + + Total physical memory installed + on + + + + out + totalReal + + + SNMP version + + + + snmp_version + in + snmp_ver + + + Unallocated physical memory + on + + + + out + availReal + + + Memory allocated to buffers + on + + + + out + memBuffer + + + Memory allocated to cache + on + + + + out + memCached + + + Total swap memory installed + on + + + + out + totalSwap + + + Unallocated swap memory + on + + + + out + availSwap + + + SNMPv3 authentication protocol + + + + snmp_auth_protocol + in + snmp3_authprot + + + SNMPv3 privilege passphrase + + + + snmp_priv_passphrase + in + snmp3_privpass + + + SNMPv3 privilege protocol + + + + snmp_priv_protocol + in + snmp3_privprot + + + SNMPv3 authentiation context + + + + snmp_context + in + snmp3_context + + + + + Daily (5 Minute Average) + 0.5 + 1 + 600 + 86400 + 1|2|3|4 + + + Weekly (30 Minute Average) + 0.5 + 6 + 700 + 604800 + 1|2|3|4 + + + Monthly (2 Hour Average) + 0.5 + 24 + 775 + 2678400 + 1|2|3|4 + + + Yearly (1 Day Average) + 0.5 + 288 + 797 + 33053184 + 1|2|3|4 + + + Hourly (1 Minute Average) + 0.5 + 1 + 500 + 14400 + 1|3 + + + Multiply by 1024 + + + 1 + 4 + CURRENT_DATA_SOURCE + + + 2 + 6 + 1024 + + + 3 + 2 + 3 + + + + + Normal + %8.2lf%s + +