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 [2010/02/22 19:35]
gandalf
manual:088:3a_advanced_topics.3d_script_data_query_walkthrough [2019/10/29 15:16] (current)
Line 170: 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 288: 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,         $arr_index = reindex(cacti_snmp_walk($hostname, $snmp_community,
         $oids["index"], $snmp_version, $snmp_auth_username,         $oids["index"], $snmp_version, $snmp_auth_username,
Line 320: 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,         print (cacti_snmp_get($hostname, $snmp_community,
         $oids[$query_field] . ".$query_index", $snmp_version, $snmp_auth_username,         $oids[$query_field] . ".$query_index", $snmp_version, $snmp_auth_username,
Line 524: Line 524:
 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 536: 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 552: 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 612: 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 626: 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 637: 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 648: 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 658: 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