Cacti (home)ForumsDocumentation

Differences

This shows you the differences between two versions of the page.

manual:088:3a_advanced_topics.3d_script_data_query_walkthrough [2009/03/23 10:57]
127.0.0.1 external edit
manual:088:3a_advanced_topics.3d_script_data_query_walkthrough [2012/05/20 16:13] (current)
Line 10: Line 10:
  
 Before starting the work, I feel encouraged to point out a drawback of this approach. Cacti will start a php instance, each time it has to fetch a value from the target device. This is not that fast, obviously. And it will not prosper from the performance boost when switching over from cmd.php to cactid. Of course, even cactid will need to start php! And that's exactly, where the thingy called **Script Server Data Query** drops in. But let's leave this for the next main chapter. Before starting the work, I feel encouraged to point out a drawback of this approach. Cacti will start a php instance, each time it has to fetch a value from the target device. This is not that fast, obviously. And it will not prosper from the performance boost when switching over from cmd.php to cactid. Of course, even cactid will need to start php! And that's exactly, where the thingy called **Script Server Data Query** drops in. But let's leave this for the next main chapter.
 +
 +The code runs on Cacti 0.8.7 versions.
  
 ==== Basic Script ==== ==== Basic Script ====
Line 17: Line 19:
 Output is a list of indices, each one on a seperate line. Output is a list of indices, each one on a seperate line.
 <PHP><?php <PHP><?php
 +
 +/* do NOT run this script through a web browser */
 +if (!isset($_SERVER["argv"][0]) || isset($_SERVER['REQUEST_METHOD'])  || isset($_SERVER['REMOTE_ADDR'])) {
 +   die("<br><strong>This script is only meant to run at the command line.</strong>");
 +}
  
 # deactivate http headers # deactivate http headers
 $no_http_headers = true; $no_http_headers = true;
 # include some cacti files for ease of use # include some cacti files for ease of use
-include(dirname(__FILE__) . "/../include/config.php");+include(dirname(__FILE__) . "/../include/global.php");
 include(dirname(__FILE__) . "/../lib/snmp.php"); include(dirname(__FILE__) . "/../lib/snmp.php");
  
Line 31: Line 38:
  
 # all required input parms # all required input parms
-$hostname       = $_SERVER["argv"][1];     # hostname/[email protected]+$hostname       = $_SERVER["argv"][1]; # hostname/[email protected] 
 +$cmd            = $_SERVER["argv"][2]; # one of: index/query/get 
 # put your own community string here # put your own community string here
-$snmp_community = "public";                # community string +$snmp_community = "public"; # community string 
-$snmp_version   = 1;                       # snmp version +$snmp_version   = 1; # snmp version 
-$snmp_port      = 161;                     # snmp port +$snmp_port      = 161; # snmp port 
-$snmp_timeout   = 500;                     # snmp timeout +$snmp_timeout   = 500; # snmp timeout 
-$snmp_user      = "";                      # SNMP V3: user +$snmp_retries   = 3; # snmp retries 
-$snmp_pw        = "";                      # SNMP V3: password +$max_oids = 1; # max oids for V2/V3 hosts 
-$cmd            = $_SERVER["argv"][2]    # one of: index/query/get +# required for SNMP V3 
-$snmp_retries   3                      # snmp retries+$snmp_auth_username    = ""; 
 +$snmp_auth_password    = ""; 
 +$snmp_auth_protocol  ""; 
 +$snmp_priv_passphrase = ""; 
 +$snmp_priv_protocol    ""; 
 +$snmp_context          = "";
  
 # ------------------------------------------------------------------------- # -------------------------------------------------------------------------
 # main code starts here # main code starts here
-# 
-# snmp walk will not be provided with snmp_user and snmp_password 
-# so this will not work for SNMP V3 hosts 
 # ------------------------------------------------------------------------- # -------------------------------------------------------------------------
  
Line 63: Line 74:
 if ($cmd == "index") { if ($cmd == "index") {
         # retrieve all indices from target         # retrieve all indices from target
-        $return_arr = reindex(cacti_snmp_walk($hostname, $snmp_community, $oids["index"], +        $return_arr = reindex(cacti_snmp_walk($hostname, $snmp_community, 
-                                              $snmp_version, $snmp_user, $snmp_pw, $snmp_port+        $oids["index"], $snmp_version, $snmp_auth_username, 
-                                              $snmp_timeout, $snmp_retries));+        $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol
 +        $snmp_context, $snmp_port, $snmp_timeout, $snmp_retries, $max_oids, SNMP_POLLER));
  
         # and print each index as a separate line         # and print each index as a separate line
Line 88: Line 100:
         return $return_arr;         return $return_arr;
 } }
- +</PHP>
-?></PHP>+
 It will be called like this It will be called like this
 <code>php -q query_interface_traffic.php <your target host> index <code>php -q query_interface_traffic.php <your target host> index
Line 126: Line 137:
  
 )</code>The values of interest are stored in **$return_arr[$i] = $arr[$i]["value"];**. The **function_reindex** gets them all. )</code>The values of interest are stored in **$return_arr[$i] = $arr[$i]["value"];**. The **function_reindex** gets them all.
 +
 ==== XML File ==== ==== XML File ====
  
Line 158: Line 170:
 Now save this file and lets turn to cacti to implement this one. First, goto **Data Queries** to see Now save this file and lets turn to cacti to implement this one. First, goto **Data Queries** to see
  
-{{http://docs.cacti.net/files/images/dq-add-01.preview.png|script_query-data_query-add_01}}+{{:manual:088:dq-add-01.preview.png|script_query-data_query-add_01}}
  
 and **Add** a new one: and **Add** a new one:
  
-{{http://docs.cacti.net/files/images/dq-add-02.preview.png|script_query-data_query-add_02}}+{{:manual:088:dq-add-02.preview.png|script_query-data_query-add_02}}
  
 Fill in Short and Long Names at your wish. Enter the file name of the XML file and don't forget to choose **Get Script Data (indexed)**. **Create** to see Fill in Short and Long Names at your wish. Enter the file name of the XML file and don't forget to choose **Get Script Data (indexed)**. **Create** to see
  
-{{http://docs.cacti.net/files/images/dq-add-03.preview.png|script_query-data_query-add_03}}+{{:manual:088:dq-add-03.preview.png|script_query-data_query-add_03}}
  
 It has now **Successfully located XML file**. But this does not mean that there are no errors. So lets go on with that. Turn to the **Device** you want to query and add the new **Data Query** as shown: It has now **Successfully located XML file**. But this does not mean that there are no errors. So lets go on with that. Turn to the **Device** you want to query and add the new **Data Query** as shown:
  
-{{http://docs.cacti.net/files/images/dev-dq-01.preview.png|script_query-data_query-dev-add_01}}+{{:manual:088:dev-dq-01.preview.png|script_query-data_query-dev-add_01}}
  
 **Index Count Changed** was chosen on purpose to tell cacti to re-index not only on reboot but each time the Index Count (e.g. number of interfaces) changed. When done, see the results as **Index Count Changed** was chosen on purpose to tell cacti to re-index not only on reboot but each time the Index Count (e.g. number of interfaces) changed. When done, see the results as
  
-{{http://docs.cacti.net/files/images/dev-dq-02.preview.png|script_query-data_query-dev-add_02}}+{{:manual:088:dev-dq-02.preview.png|script_query-data_query-dev-add_02}}
  
 To see your script at work, select **Verbose Query** to see: To see your script at work, select **Verbose Query** to see:
  
-{{http://docs.cacti.net/files/images/dev-dq-03.preview.png|script_query-data_query-dev-add_03}}+{{:manual:088:dev-dq-03.preview.png|script_query-data_query-dev-add_03}}
  
 ==== Completing the Script ==== ==== Completing the Script ====
Line 186: Line 198:
  
 <PHP><?php <PHP><?php
 +
 +/* do NOT run this script through a web browser */
 +if (!isset($_SERVER["argv"][0]) || isset($_SERVER['REQUEST_METHOD'])  || isset($_SERVER['REMOTE_ADDR'])) {
 +   die("<br><strong>This script is only meant to run at the command line.</strong>");
 +}
  
 # deactivate http headers # deactivate http headers
 $no_http_headers = true; $no_http_headers = true;
 # include some cacti files for ease of use # include some cacti files for ease of use
-include(dirname(__FILE__) . "/../include/config.php");+include(dirname(__FILE__) . "/../include/global.php");
 include(dirname(__FILE__) . "/../lib/snmp.php"); include(dirname(__FILE__) . "/../lib/snmp.php");
  
Line 208: Line 225:
 $xml_delimiter          =  "!";</PHP> $xml_delimiter          =  "!";</PHP>
  
-The next step removes all the builtin "magic strings" and replaces them by parameters. We'll have to change the XML template for that (see: <arg_prepend> later on). cacti supports "snmp_retries" since version 0.8.6i. This is a global config option, access to those is available using "read_config_option".+The next step removes all the builtin "magic strings" and replaces them by parameters. We'll have to change the XML template for that (see: <arg_prepend> later on). Cacti supports more SNMP parameters since version 0.8.7:
  
 <PHP># all required input parms <PHP># all required input parms
-$hostname       = $_SERVER["argv"][1]; +$hostname       = $_SERVER["argv"][1]; 
-$snmp_community = $_SERVER["argv"][2]; +$snmp_community  = $_SERVER["argv"][2]; 
-$snmp_version   = $_SERVER["argv"][3]; +$snmp_version   = $_SERVER["argv"][3]; 
-$snmp_port      = $_SERVER["argv"][4]; +$snmp_port       = $_SERVER["argv"][4]; 
-$snmp_timeout   = $_SERVER["argv"][5]; +$snmp_timeout   = $_SERVER["argv"][5]; 
-$snmp_user      = $_SERVER["argv"][6]; +$max_oids = $_SERVER["argv"][6]; 
-$snmp_pw        = $_SERVER["argv"][7]; +# required for SNMP V3 
-$cmd            = $_SERVER["argv"][8]; +$snmp_auth_username    = $_SERVER["argv"][7]; 
-if (isset($_SERVER["argv"][9]))  { $query_field = $_SERVER["argv"][9]; }; +$snmp_auth_password    = $_SERVER["argv"][8]; 
-if (isset($_SERVER["argv"][10])) { $query_index = $_SERVER["argv"][10]; };+$snmp_auth_protocol  = $_SERVER["argv"][9]; 
 +$snmp_priv_passphrase = $_SERVER["argv"][10]; 
 +$snmp_priv_protocol    = $_SERVER["argv"][11]; 
 +$snmp_context          = $_SERVER["argv"][12]; 
 +$cmd            = $_SERVER["argv"][13]; 
 +if (isset($_SERVER["argv"][14])) { $query_field = $_SERVER["argv"][14]; }; 
 +if (isset($_SERVER["argv"][15])) { $query_index = $_SERVER["argv"][15]; };
  
 # get number of snmp retries from global settings # get number of snmp retries from global settings
Line 239: Line 262:
 if ($cmd == "index") { if ($cmd == "index") {
         # retrieve all indices from target         # retrieve all indices from target
-        $return_arr = reindex(cacti_snmp_walk($hostname, $snmp_community, $oids["index"], +        $return_arr = reindex(cacti_snmp_walk($hostname, $snmp_community, 
-                                              $snmp_version, $snmp_user, $snmp_pw, $snmp_port+        $oids["index"], $snmp_version, $snmp_auth_username, 
-                                              $snmp_timeout, $snmp_retries));+        $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol
 +        $snmp_context, $snmp_port, $snmp_timeout, $snmp_retries, $max_oids, SNMP_POLLER));
  
         # and print each index as a separate line         # and print each index as a separate line
Line 264: Line 288:
 #      interface indices along with the description of the interface #      interface indices along with the description of the interface
 # ------------------------------------------------------------------------- # -------------------------------------------------------------------------
-}elseif ($cmd == "query") { +}elseif ($cmd == "query" && isset($query_field)) { 
-        $arr_index = reindex(cacti_snmp_walk($hostname, $snmp_community, $oids["index"], +        $arr_index = reindex(cacti_snmp_walk($hostname, $snmp_community, 
-                                             $snmp_version, $snmp_user, $snmp_pw, $snmp_port+        $oids["index"], $snmp_version, $snmp_auth_username, 
-                                             $snmp_timeout, $snmp_retries)); +        $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol
-        $arr = reindex(cacti_snmp_walk($hostname, $snmp_community, $oids[$query_field], +        $snmp_context, $snmp_port, $snmp_timeout, $snmp_retries, $max_oids, SNMP_POLLER)); 
-                                        $snmp_version, $snmp_user, $snmp_pw, $snmp_port+        $arr = reindex(cacti_snmp_walk($hostname, $snmp_community, 
-                                        $snmp_timeout, $snmp_retries));+        $oids[$query_field], $snmp_version, $snmp_auth_username, 
 +        $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol
 +        $snmp_context, $snmp_port, $snmp_timeout, $snmp_retries, $max_oids, SNMP_POLLER));
  
         for ($i=0;($i<sizeof($arr_index));$i++) {         for ($i=0;($i<sizeof($arr_index));$i++) {
Line 294: Line 320:
 #      the description of the interface for interface #1 #      the description of the interface for interface #1
 # ------------------------------------------------------------------------- # -------------------------------------------------------------------------
-}elseif ($cmd == "get") { +}elseif ($cmd == "get" $$ isset($query_field) && isset($query_index)) { 
-        print (cacti_snmp_get($hostname, $snmp_community, $oids[$query_field] . +        print (cacti_snmp_get($hostname, $snmp_community, 
-                              ".$query_index", $snmp_version, $snmp_user, $snmp_pw+        $oids[$query_field] . ".$query_index", $snmp_version, $snmp_auth_username, 
-                              $snmp_port, $snmp_timeout, $snmp_retries));</PHP>+        $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol
 +        $snmp_context, $snmp_port, $snmp_timeout, $snmp_retries, $max_oids, SNMP_POLLER));</PHP>
  
 The rest of it is left unchanged. For sake of completeness, I repeat it here The rest of it is left unchanged. For sake of completeness, I repeat it here
Line 305: Line 332:
 } else { } else {
         print "Invalid use of script query, required parameters:\n\n";         print "Invalid use of script query, required parameters:\n\n";
-        print "    <hostname> <community> <version> <snmp_port> <timeout> <user> <pw> <cmd>\n";+        print "    <hostname> <community> <version> <snmp_port> <timeout>  
 +                   <max_oids> <auth_user> <auth_passphrase> <auth_proto> 
 +                   <priv_passphrase> <priv_proto> <context> <cmd>\n";
 } }
  
Line 322: Line 351:
 You may want to copy all those fragments together and replace the basic script. Now, lets have a try using the command line. The "index" option was already shown, but is repeated here You may want to copy all those fragments together and replace the basic script. Now, lets have a try using the command line. The "index" option was already shown, but is repeated here
  
-<code>[[email protected] scripts]$ php -q query_interface_traffic.php <target> <community> 1 161 500 "" "" index+<code>[[email protected] scripts]$ php -q query_interface_traffic.php <target> <community> 1 161 500 "" "" "" "" "" "" "" index
 1 1
 2 2
 3 3
 4</code> 4</code>
- 
-Now, lets test the "query" option. The keyword "query" must be given along with the variable, that should be queried. The script now will scan all indices and report the contents of the given variable as follows: 
- 
-<code>[[email protected] scripts]$ php -q query_interface_traffic.php <target> <community> 1 161 500 "" "" query iftype 
-1!ethernetCsmacd(6) 
-2!0 
-3!0 
-4!ethernetCsmacd(6)</code> 
-The output reports the index, followed by the chosen delimiter. Then, the content of the requested variable is printed 
- 
-Last, the "get" option is shown. The keyword "get" is required, followed again by the variable (see above). Last needed option is the index, for which the "get" should be performed. Contrary to the "query" option, only one index is scanned. So the index number is not required and will nort be printed. 
- 
-<code>[[email protected] scripts]$ php -q query_interface_traffic.php <target> <community> 1 161 500 "" "" get iftype 1 
-ethernetCsmacd(6)</code> 
- 
-The output is not followed by a "newline"! 
  
 ==== The Complete XML File ==== ==== The Complete XML File ====
Line 350: Line 363:
         <name>Get Interface Traffic Information</name>         <name>Get Interface Traffic Information</name>
         <script_path>|path_php_binary| -q |path_cacti|/scripts/query_interface_traffic.php</script_path>         <script_path>|path_php_binary| -q |path_cacti|/scripts/query_interface_traffic.php</script_path>
-        <arg_prepend>|host_hostname| |host_snmp_community| |host_snmp_version| |host_snmp_port| |host_snmp_timeout| "|host_snmp_username|" "|host_snmp_password|"</arg_prepend>+        <arg_prepend>|host_hostname| |host_snmp_community| |host_snmp_version| |host_snmp_port| |host_snmp_timeout| |host_max_oids| "|host_snmp_username|" "|host_snmp_password|" "|host_snmp_auth_protocol|" "|host_snmp_priv_passphrase|" "|host_snmp_priv_protocol|" "|host_snmp_context|"</arg_prepend>
         <arg_index>index</arg_index>         <arg_index>index</arg_index>
         <arg_query>query</arg_query>         <arg_query>query</arg_query>
Line 357: Line 370:
         <index_order>ifIndex</index_order>         <index_order>ifIndex</index_order>
         <index_order_type>numeric</index_order_type>         <index_order_type>numeric</index_order_type>
-        <index_title_format>|chosen_order_field|</index_title_format>**</code>+        <index_title_format>|chosen_order_field|</index_title_format></code>
  
 Let's discuss the changes Let's discuss the changes
  
-|**arg_prepend**|some more parameters were added to provide all necessary values for the script. They are position-dependant. You may notice the strange tics I've added for <em>host_snmp_username</em> and <em>host_snmp_password</em>. If you're not using those SNMP V3 parameters, they must be quoted, else the script would fail because two parameters would be missing. Unfortunately, I  don't have any SNMP V3 capable system. So I was not able to test this version.|+|**arg_prepend**|some more parameters were added to provide all necessary values for the script. They are position-dependant. You may notice the strange tics I've added to e.g. //host_snmp_username/and //host_snmp_password//. If you're not using those SNMP V3 parameters, they must be quoted, else the script would fail because two parameters would be missing.|
 |**arg_query**|The string passed to the query to perform **query** requests is given here. So you may modify it to your liking (in this case, the script has to be modified accordingly).| |**arg_query**|The string passed to the query to perform **query** requests is given here. So you may modify it to your liking (in this case, the script has to be modified accordingly).|
 |**arg_get**|Some as above for **get** requests| |**arg_get**|Some as above for **get** requests|
 |**output_delimiter**|The delimiter used for **query** requests to separate index and value| |**output_delimiter**|The delimiter used for **query** requests to separate index and value|
 |**index_order** (optional)|Cacti will attempt to find the best field to index off of based on whether each row in the query is unique and non-null. If specified, Cacti will perform this check on the fields listed here in the order specified. Only input fields can be specified and multiple fields should be delimited with a comma.| |**index_order** (optional)|Cacti will attempt to find the best field to index off of based on whether each row in the query is unique and non-null. If specified, Cacti will perform this check on the fields listed here in the order specified. Only input fields can be specified and multiple fields should be delimited with a comma.|
-|**index_order_type** (optional)|For sorting purposes, specify whether the index is numeric or alphanumeric.<html><ul><li>numeric: The indexes in this script query are to be sorted numerically (ie. 1,2,3,10,20,31)</li> +|**index_order_type** (optional)|For sorting purposes, specify whether the index is numeric or alphanumeric.\\ <html><ul><li>numeric: The indexes in this script query are to be sorted numerically (ie. 1,2,3,10,20,31)</li><li>alphabetic: The indexes in this script query are to be sorted alphabetically (1,10,2,20,3,31).</li></ul></html>|
-<li>alphabetic: The indexes in this script query are to be sorted alphabetically (1,10,2,20,3,31).</li></ul></html>|+
 |**index_title_format** (optional)|Specify the title format to use when representing an index to the user. Any **input field name** can be used as a variable if enclosed in pipes (%%|%%). The variable %%|chosen_order_field|%% will be substituted with the field chosen by Cacti to index off of (see index_order above). Text constants are allowed as well| |**index_title_format** (optional)|Specify the title format to use when representing an index to the user. Any **input field name** can be used as a variable if enclosed in pipes (%%|%%). The variable %%|chosen_order_field|%% will be substituted with the field chosen by Cacti to index off of (see index_order above). Text constants are allowed as well|
  
Line 435: Line 447:
 These fields are related to the **OID** array of the script.  These fields are related to the **OID** array of the script. 
 **Attention:** The **query_name** strings must match the OID names **exactly**! **Attention:** The **query_name** strings must match the OID names **exactly**!
-Please notice, that all but the last two fields use **direction input**. All variables representing numeric values to be graphed must be defined as **direction** <em>output</eminstead.+Please notice, that all but the last two fields use **direction input**. All variables representing numeric values to be graphed must be defined as **direction** //output// instead. 
 + 
 + 
 +Now, lets test the "query" option. The keyword "query" must be given along with the variable, that should be queried. The script now will scan all indices and report the contents of the given variable as follows: 
 + 
 +<code>[[email protected] scripts]$ php -q query_interface_traffic.php <target> <community> 1 161 500 "" "" "" "" "" "" "" query iftype 
 +1!ethernetCsmacd(6) 
 +2!0 
 +3!0 
 +4!ethernetCsmacd(6)</code> 
 +The output reports the index, followed by the chosen delimiterThen, the content of the requested variable is printed 
 + 
 +Last, the "get" option is shown. The keyword "get" is required, followed again by the variable (see above). Last needed option is the index, for which the "get" should be performed. Contrary to the "query" option, only one index is scanned. So the index number is not required and will nort be printed. 
 + 
 +<code>[[email protected] scripts]$ php -q query_interface_traffic.php <target> <community> 1 161 500 "" "" "" "" "" "" "" get iftype 1 
 +ethernetCsmacd(6)</code> 
 + 
 +The output is not followed by a "newline"!
  
 ==== See it at work! ==== ==== See it at work! ====
Line 444: Line 473:
 + Found data query XML file at '/var/www/html/cacti/resource/script_queries/ifTraffic.xml' + Found data query XML file at '/var/www/html/cacti/resource/script_queries/ifTraffic.xml'
 + XML file parsed ok. + XML file parsed ok.
-+ Executing script for list of indexes '/usr/bin/php -q /var/www/html/cacti/scripts/query_interface_traffic.php router snmp-get 1 161 600 "" "" index' ++ Executing script for list of indexes '/usr/bin/php -q /var/www/html/cacti/scripts/query_interface_traffic.php router snmp-get 1 161 600 10 "admin" "admin" "MD5" "" "DES" "" index' 
-+ Executing script query '/usr/bin/php -q /var/www/html/cacti/scripts/query_interface_traffic.php router snmp-get 1 161 600 "" "" query index'++ Executing script query '/usr/bin/php -q /var/www/html/cacti/scripts/query_interface_traffic.php router snmp-get 1 161 600 10 "admin" "admin" "MD5" "" "DES" "" query index'
 + Found item [ifIndex='1'] index: 1 + Found item [ifIndex='1'] index: 1
 + Found item [ifIndex='2'] index: 2 + Found item [ifIndex='2'] index: 2
 + Found item [ifIndex='3'] index: 3 + Found item [ifIndex='3'] index: 3
 + Found item [ifIndex='4'] index: 4 + Found item [ifIndex='4'] index: 4
-+ Executing script query '/usr/bin/php -q /var/www/html/cacti/scripts/query_interface_traffic.php router snmp-get 1 161 600 "" "" query ifstatus'++ Executing script query '/usr/bin/php -q /var/www/html/cacti/scripts/query_interface_traffic.php router snmp-get 1 161 600 10 "admin" "admin" "MD5" "" "DES" "" query ifstatus'
 + Found item [ifstatus='up(1)'] index: 1 + Found item [ifstatus='up(1)'] index: 1
 + Found item [ifstatus='up(1)'] index: 2 + Found item [ifstatus='up(1)'] index: 2
 + Found item [ifstatus='up(1)'] index: 3 + Found item [ifstatus='up(1)'] index: 3
 + Found item [ifstatus='up(1)'] index: 4 + Found item [ifstatus='up(1)'] index: 4
-+ Executing script query '/usr/bin/php -q /var/www/html/cacti/scripts/query_interface_traffic.php router snmp-get 1 161 600 "" "" query ifdescription'++ Executing script query '/usr/bin/php -q /var/www/html/cacti/scripts/query_interface_traffic.php router snmp-get 1 161 600 10 "admin" "admin" "MD5" "" "DES" "" query ifdescription'
 + Found item [ifdescription='Ethernet0'] index: 1 + Found item [ifdescription='Ethernet0'] index: 1
 + Found item [ifdescription=''] index: 2 + Found item [ifdescription=''] index: 2
 + Found item [ifdescription=''] index: 3 + Found item [ifdescription=''] index: 3
 + Found item [ifdescription='Ethernet1'] index: 4 + Found item [ifdescription='Ethernet1'] index: 4
-+ Executing script query '/usr/bin/php -q /var/www/html/cacti/scripts/query_interface_traffic.php router snmp-get 1 161 600 "" "" query ifname'++ Executing script query '/usr/bin/php -q /var/www/html/cacti/scripts/query_interface_traffic.php router snmp-get 1 161 600 10 "admin" "admin" "MD5" "" "DES" "" query ifname'
 + Found item [ifname=''] index: 1 + Found item [ifname=''] index: 1
 + Found item [ifname=''] index: 2 + Found item [ifname=''] index: 2
 + Found item [ifname=''] index: 3 + Found item [ifname=''] index: 3
 + Found item [ifname=''] index: 4 + Found item [ifname=''] index: 4
-+ Executing script query '/usr/bin/php -q /var/www/html/cacti/scripts/query_interface_traffic.php router snmp-get 1 161 600 "" "" query ifalias'++ Executing script query '/usr/bin/php -q /var/www/html/cacti/scripts/query_interface_traffic.php router snmp-get 1 161 600 10 "admin" "admin" "MD5" "" "DES" "" query ifalias'
 + Found item [ifalias=''] index: 1 + Found item [ifalias=''] index: 1
 + Found item [ifalias=''] index: 2 + Found item [ifalias=''] index: 2
 + Found item [ifalias=''] index: 3 + Found item [ifalias=''] index: 3
 + Found item [ifalias=''] index: 4 + Found item [ifalias=''] index: 4
-+ Executing script query '/usr/bin/php -q /var/www/html/cacti/scripts/query_interface_traffic.php router snmp-get 1 161 600 "" "" query iftype'++ Executing script query '/usr/bin/php -q /var/www/html/cacti/scripts/query_interface_traffic.php router snmp-get 1 161 600 10 "admin" "admin" "MD5" "" "DES" "" query iftype'
 + Found item [iftype='ethernetCsmacd(6)'] index: 1 + Found item [iftype='ethernetCsmacd(6)'] index: 1
 + Found item [iftype='0'] index: 2 + Found item [iftype='0'] index: 2
 + Found item [iftype='0'] index: 3 + Found item [iftype='0'] index: 3
 + Found item [iftype='ethernetCsmacd(6)'] index: 4 + Found item [iftype='ethernetCsmacd(6)'] index: 4
-+ Executing script query '/usr/bin/php -q /var/www/html/cacti/scripts/query_interface_traffic.php router snmp-get 1 161 600 "" "" query ifspeed'++ Executing script query '/usr/bin/php -q /var/www/html/cacti/scripts/query_interface_traffic.php router snmp-get 1 161 600 10 "admin" "admin" "MD5" "" "DES" "" query ifspeed'
 + Found item [ifspeed='100000000'] index: 1 + Found item [ifspeed='100000000'] index: 1
 + Found item [ifspeed='0'] index: 2 + Found item [ifspeed='0'] index: 2
 + Found item [ifspeed='0'] index: 3 + Found item [ifspeed='0'] index: 3
 + Found item [ifspeed='10000000'] index: 4 + Found item [ifspeed='10000000'] index: 4
-+ Executing script query '/usr/bin/php -q /var/www/html/cacti/scripts/query_interface_traffic.php router snmp-get 1 161 600 "" "" query ifHWaddress'++ Executing script query '/usr/bin/php -q /var/www/html/cacti/scripts/query_interface_traffic.php router snmp-get 1 161 600 10 "admin" "admin" "MD5" "" "DES" "" query ifHWaddress'
 + Found item [ifHWaddress='00:30:30:2E:35:30:2E:37:46:2E:30:43:2E:30:30:2E:44:16:00:00:00:01:00'] index: 1 + Found item [ifHWaddress='00:30:30:2E:35:30:2E:37:46:2E:30:43:2E:30:30:2E:44:16:00:00:00:01:00'] index: 1
 + Found item [ifHWaddress=''] index: 2 + Found item [ifHWaddress=''] index: 2
Line 488: Line 517:
 + Found data query XML file at '/var/www/html/cacti/resource/script_queries/ifTraffic.xml' + Found data query XML file at '/var/www/html/cacti/resource/script_queries/ifTraffic.xml'
 + Found data query XML file at '/var/www/html/cacti/resource/script_queries/ifTraffic.xml'</code> + Found data query XML file at '/var/www/html/cacti/resource/script_queries/ifTraffic.xml'</code>
 +Of course, snmp_username and snmp_user_password and more may differ from your installation defaults.
 Read it carefully, and you'll notice, that all XML **fields** were scanned and the output shown. All? No, not all. The **direction output** fields are missing! But this is on purpose as those won't make sense as header fields but will be written to rrd files. Read it carefully, and you'll notice, that all XML **fields** were scanned and the output shown. All? No, not all. The **direction output** fields are missing! But this is on purpose as those won't make sense as header fields but will be written to rrd files.
 +
 ==== Create the Data Template ==== ==== Create the Data Template ====
  
 As usual, next step is to create the **Data Template**. Select that menu item and **Add**: As usual, next step is to create the **Data Template**. Select that menu item and **Add**:
  
-{{http://docs.cacti.net/files/images/dev-dt-01.preview.png|script_query-data_template-add-01}}+{{:manual:088:dev-dt-01.preview.png|script_query-data_template-add-01}}
  
 and find: and find:
  
-{{http://docs.cacti.net/files/images/dev-dt-02.preview.png|script_query-data_template-add-02}}+{{:manual:088:dev-dt-02.preview.png|script_query-data_template-add-02}}
  
 fill in **Data Template Name**, **Data Source Name**, and, most important, select **Data Input Method** to read **Get Script Data (Indexed)**. Leave **Associated RRAs** as is. fill in **Data Template Name**, **Data Source Name**, and, most important, select **Data Input Method** to read **Get Script Data (Indexed)**. Leave **Associated RRAs** as is.
Line 505: Line 536:
 Now, please proceed to the lower half Now, please proceed to the lower half
  
-{{http://docs.cacti.net/files/images/dev-dt-03.png|script_query-data_template-add-03}}+{{:manual:088:dev-dt-03.png|script_query-data_template-add-03}}
  
 enter the **Internal Data Source Name**. You may select this name freely. There's no need to match it to any of the XML field names. As the OID is a **COUNTER**, the **Data Source Type** must be selected appropriately. **Save**. enter the **Internal Data Source Name**. You may select this name freely. There's no need to match it to any of the XML field names. As the OID is a **COUNTER**, the **Data Source Type** must be selected appropriately. **Save**.
  
-{{http://docs.cacti.net/files/images/dev-dt-04.preview.png|script_query-data_template-add-04}}+{{:manual:088:dev-dt-04.preview.png|script_query-data_template-add-04}}
  
 For the second data source item, please select **New**. For the second data source item, please select **New**.
  
-{{http://docs.cacti.net/files/images/dev-dt-05.png|script_query-data_template-add-05}}+{{:manual:088:dev-dt-05.png|script_query-data_template-add-05}}
  
 Again, fill in the Data Source Name. Pay attention to set the maximum value to 0 to avoid clipping it off during updating of the rrd file. COUNTER has to be set as done above. Again, fill in the Data Source Name. Pay attention to set the maximum value to 0 to avoid clipping it off during updating of the rrd file. COUNTER has to be set as done above.
Line 521: Line 552:
 Now, its time for the **Graph Template**. Select this menu item and **Add**. Now, its time for the **Graph Template**. Select this menu item and **Add**.
  
-{{http://docs.cacti.net/files/images/dev-gt-01.preview.png|script_query-graph_template-add_01}}+{{:manual:088:dev-gt-01.preview.png|script_query-graph_template-add_01}}
  
 and fill in the values as usual: and fill in the values as usual:
  
-{{http://docs.cacti.net/files/images/dev-gt-02.png|script_query-graph_template-add_02}}+{{:manual:088:dev-gt-02.png|script_query-graph_template-add_02}}
  
 Enter the y-axis description on the lower part of the screen Enter the y-axis description on the lower part of the screen
  
-{{http://docs.cacti.net/files/images/dev-gt-03.png|script_query-graph_template-add_03}}+{{:manual:088:dev-gt-03.png|script_query-graph_template-add_03}}
  
 Now **Save**. Next, fill in the **Graph Items** Now **Save**. Next, fill in the **Graph Items**
  
-{{http://docs.cacti.net/files/images/dev-gt-04_0.preview.png|script_query-graph_template-add_04}}+{{:manual:088:dev-gt-04_0.preview.png|script_query-graph_template-add_04}}
  
 Select the Data Source from our Data Template, take the color and select AREA, enter some text Select the Data Source from our Data Template, take the color and select AREA, enter some text
  
-{{http://docs.cacti.net/files/images/dev-gt-05.preview.png|script_query-graph_template-add_05}}+{{:manual:088:dev-gt-05.preview.png|script_query-graph_template-add_05}}
  
 Save and add the next graph item. Now, we're going to use the "LEGEND" timesaver again: Save and add the next graph item. Now, we're going to use the "LEGEND" timesaver again:
  
-{{http://docs.cacti.net/files/images/dev-gt-06.preview.png|script_query-graph_template-add_06}}+{{:manual:088:dev-gt-06.preview.png|script_query-graph_template-add_06}}
  
 For the next step, it's necessary to remove the newline added with the last action. Please select the 4th item as follows For the next step, it's necessary to remove the newline added with the last action. Please select the 4th item as follows
  
-{{http://docs.cacti.net/files/images/dev-gt-07.png|script_query-graph_template-add_07}}+{{:manual:088:dev-gt-07.png|script_query-graph_template-add_07}}
  
 and remove the newline by deselecting the checkbox and remove the newline by deselecting the checkbox
  
-{{http://docs.cacti.net/files/images/dev-gt-08.png|script_query-graph_template-add_08}}+{{:manual:088:dev-gt-08.png|script_query-graph_template-add_08}}
  
 Now lets add the same data source again, but as a LINE1, MAXimum with a slightly changed color. Newline is checked this time Now lets add the same data source again, but as a LINE1, MAXimum with a slightly changed color. Newline is checked this time
  
-{{http://docs.cacti.net/files/images/dev-gt-09.preview.png|script_query-graph_template-add_09}}+{{:manual:088:dev-gt-09.preview.png|script_query-graph_template-add_09}}
  
 Pooh. Now lets apply the same procedure for the **Outgoing Traffic**. Personally, I love those outgoing stuff tp be presented on the negative y-axis. So we'll have to apply some CDEF magic to some items. Lets see Pooh. Now lets apply the same procedure for the **Outgoing Traffic**. Personally, I love those outgoing stuff tp be presented on the negative y-axis. So we'll have to apply some CDEF magic to some items. Lets see
  
-{{http://docs.cacti.net/files/images/dev-gt-10.preview.png|script_query-graph_template-add_10}}+{{:manual:088:dev-gt-10.preview.png|script_query-graph_template-add_10}}
  
 Please pay attention when adding the "LEGEND" stuff. No CDEF to be applied in this case (else, legends will show negative values) Please pay attention when adding the "LEGEND" stuff. No CDEF to be applied in this case (else, legends will show negative values)
  
-{{http://docs.cacti.net/files/images/dev-gt-11.preview.png|script_query-graph_template-add_11}}+{{:manual:088:dev-gt-11.preview.png|script_query-graph_template-add_11}}
  
 Again, select last legend item Again, select last legend item
  
-{{http://docs.cacti.net/files/images/dev-gt-12.png|script_query-graph_template-add_12}}+{{:manual:088:dev-gt-12.png|script_query-graph_template-add_12}}
  
 to remove the newline to remove the newline
  
-{{http://docs.cacti.net/files/images/dev-gt-13.png|script_query-graph_template-add_13}}+{{:manual:088:dev-gt-13.png|script_query-graph_template-add_13}}
  
 and add a new LINE1, MAXimum, "Make Stack Negative" CDEF with some text and a newline and add a new LINE1, MAXimum, "Make Stack Negative" CDEF with some text and a newline
  
-{{http://docs.cacti.net/files/images/dev-gt-14.preview.png|script_query-graph_template-add_14}}+{{:manual:088:dev-gt-14.preview.png|script_query-graph_template-add_14}}
  
 Hoping, you've got all those steps correctly, finally **Save** your work. Take a cup of coffee to get your brains free again, kiss your wife, hug your children and/or pet your dog; sequence is arbitrary. Hoping, you've got all those steps correctly, finally **Save** your work. Take a cup of coffee to get your brains free again, kiss your wife, hug your children and/or pet your dog; sequence is arbitrary.
Line 581: Line 612:
 So, let's revisit the **Data Query**. Remember the lower part on **Associated Graph Templates**. Click **Add** So, let's revisit the **Data Query**. Remember the lower part on **Associated Graph Templates**. Click **Add**
  
-{{http://docs.cacti.net/files/images/dev-dq-20.preview.png|script_query-data_query-add-gt_20}}+{{:manual:088:dev-dq-20.preview.png|script_query-data_query-add-gt_20}}
  
 fill in a name for your choice and select the **Graph Template** that we have created in the last step. fill in a name for your choice and select the **Graph Template** that we have created in the last step.
  
-{{http://docs.cacti.net/files/images/dev-dq-21.preview.png|script_query-data_query-add-gt_21}}+{{:manual:088:dev-dq-21.preview.png|script_query-data_query-add-gt_21}}
  
 **Create** to see  **Create** to see 
  
-{{http://docs.cacti.net/files/images/dev-dq-22.preview.png|script_query-data_query-add-gt_22}}+{{:manual:088:dev-dq-22.preview.png|script_query-data_query-add-gt_22}}
  
 First, let's have a look at the upper half of the screen. The red box to the left show the **Internal Data Source Names** names taken from the **Data Template** that is associated with the **Graph template** we've just added.  First, let's have a look at the upper half of the screen. The red box to the left show the **Internal Data Source Names** names taken from the **Data Template** that is associated with the **Graph template** we've just added. 
Line 595: Line 626:
 The red box to the right must be checked on each line, to make the association valid. Now, lets turn to the lower half of the screen, denoted **Suggested Values** The red box to the right must be checked on each line, to make the association valid. Now, lets turn to the lower half of the screen, denoted **Suggested Values**
  
-{{http://docs.cacti.net/files/images/dev-dq-23.png|script_query-data_query-add-gt_23}}+{{:manual:088:dev-dq-23.png|script_query-data_query-add-gt_23}}
  
 The example shows **|host_description| - Traffic - |query_ifdescription|** entered both for **name** of the Data Template and **title** of the Graph Template. Click **Add**, one by one The example shows **|host_description| - Traffic - |query_ifdescription|** entered both for **name** of the Data Template and **title** of the Graph Template. Click **Add**, one by one
  
-{{http://docs.cacti.net/files/images/dev-dq-24.preview.png|script_query-data_query-add-gt_24}}+{{:manual:088:dev-dq-24.preview.png|script_query-data_query-add-gt_24}}
  
 Notice the second **title** I've added here. If more than one entry is present, they are applied from top to bottom, until a match is found. Match means, that all variables present are filled. Of course, you may add more than one variable taken from the XML file. But pay attention, that not all devices will fill all those variables. So my router does, sigh. Notice the second **title** I've added here. If more than one entry is present, they are applied from top to bottom, until a match is found. Match means, that all variables present are filled. Of course, you may add more than one variable taken from the XML file. But pay attention, that not all devices will fill all those variables. So my router does, sigh.
Line 606: Line 637:
 Click **Save**, and find the new Graph Template added to the list of **Associated Graph Templates**.  Click **Save**, and find the new Graph Template added to the list of **Associated Graph Templates**. 
  
-{{http://docs.cacti.net/files/images/dev-dq-25.preview.png|script_query-data_query-add-gt_25}}+{{:manual:088:dev-dq-25.preview.png|script_query-data_query-add-gt_25}}
  
 You may continue to add more **Graph Templates**, each of them may be related to other output field of the XML file. Find, as an example, lots of graph templates associated to the standard <em>Interface Statistics</em> Data Query to get an idea what I'm talking about You may continue to add more **Graph Templates**, each of them may be related to other output field of the XML file. Find, as an example, lots of graph templates associated to the standard <em>Interface Statistics</em> Data Query to get an idea what I'm talking about
  
-{{http://docs.cacti.net/files/images/dev-dq-26.preview.png|script_query-data_query-add-gt_26}}+{{:manual:088:dev-dq-26.preview.png|script_query-data_query-add-gt_26}}
  
 Don't worry about the first two entries; they are home-made. Don't worry about the first two entries; they are home-made.
Line 617: Line 648:
 Now, let's return to the **Device**, that we've already have used for this Data Query. **Create Graphs for this Host** Now, let's return to the **Device**, that we've already have used for this Data Query. **Create Graphs for this Host**
  
-{{http://docs.cacti.net/files/images/dev-dev-10.preview.png|script_query-data_query-dev-10}}+{{:manual:088:dev-dev-10.preview.png|script_query-data_query-dev-10}}
  
 to see to see
  
-{{http://docs.cacti.net/files/images/dev-dev-11_0.preview.png|script_query-data_query-dev-11}}+{{:manual:088:dev-dev-11_0.preview.png|script_query-data_query-dev-11}}
  
 I've left the standard //Interface Statistics// in the screenshot. So you may compare both Queries. Our //PHP Interface Traffic// stuff has two more header items, //Name// and //Alias//. But all data seen equals the standard SNMP Data Query; not that bad, eh? I've left the standard //Interface Statistics// in the screenshot. So you may compare both Queries. Our //PHP Interface Traffic// stuff has two more header items, //Name// and //Alias//. But all data seen equals the standard SNMP Data Query; not that bad, eh?
Line 627: Line 658:
 Now, select one item Now, select one item
  
-{{http://docs.cacti.net/files/images/dev-dev-12.preview.png|script_query-data_query-dev-12}}+{{:manual:088:dev-dev-12.preview.png|script_query-data_query-dev-12}}
  
 and **Create** and **Create**
  
-{{http://docs.cacti.net/files/images/dev-dev-13.png|script_query-data_query-dev-13}}+{{:manual:088:dev-dev-13.png|script_query-data_query-dev-13}}
  
 You'll have to wait a bit, at least two polling cycles. Then, you may notice some data in your new graph. The next image shows both our new graph (the first one) and a standard interface traffic graph. The latter one holds more data in this example, don't worry about that. You'll have to wait a bit, at least two polling cycles. Then, you may notice some data in your new graph. The next image shows both our new graph (the first one) and a standard interface traffic graph. The latter one holds more data in this example, don't worry about that.
  
-{{http://docs.cacti.net/files/images/dev-dev-14.png|script_query-data_query-dev-14}}+{{:manual:088:dev-dev-14.png|script_query-data_query-dev-14}}
  
 Having a closer view, you may notice a difference in magnitude (y-axis). But please compare the units used. The first graph uses **Bytes**, the latter one uses **Bits**. For comparison, it would be necessary to multiply the first one with 8. This may be done using a CDEF //Turn Bytes into Bits//, applied to all items of the **Graph Template**. This task is left to you. Having a closer view, you may notice a difference in magnitude (y-axis). But please compare the units used. The first graph uses **Bytes**, the latter one uses **Bits**. For comparison, it would be necessary to multiply the first one with 8. This may be done using a CDEF //Turn Bytes into Bits//, applied to all items of the **Graph Template**. This task is left to you.





Personal Tools