python script and data queries template is not working, support required

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

Post Reply
yedascientist
Posts: 10
Joined: Fri Oct 27, 2023 12:23 pm

python script and data queries template is not working, support required

Post by yedascientist »

Hi All,

below is my python script, polling interface traffic, I have used snmp_bulkwalk as getting OID incrementing error, first attempt to script for cacti, this python script, script is having execute permission to www-data and in /var/www/html/cacti/scripts/ folder, not having much knowledge on index and query parameters, using python3.7, cacti version is 1.2.25

Code: Select all

#!/home/hostaddition/bin/python
import sys
from easysnmp import Session

# Define the base OID for the MIB
base_oid = '.1.3.6.1.4.1.8255.1.2.1.2.37.1.1'

# Define the ifType dictionary
iftype = {
    "0": "ifOther",
    "1": "e1",
    "2": "e3",
    "3": "sONET",
    "4": "iBC",
    "5": "vOICE",
    "6": "eTHERNET",
    "7": "aTM"
}

def fetch_data(host, oid):
    session = Session(hostname=host, community='private', version=2)
    try:
        result = session.bulkwalk(oid)
        return result
    except Exception as e:
        print(f"Error fetching data for OID {oid}: {e}")
        return []

def main():
    if len(sys.argv) != 3:
        print("Usage: script.py <hostname>")
        sys.exit(1)

    host = sys.argv[1]
    cmd = sys.argv[2]

    # Define the MIB object identifiers
    ifOperStatus_oid = base_oid + '.3'
    ifType_oid = base_oid + '.4'
    objectName_oid = base_oid + '.1001'
    tejasStoctetsRx_oid = base_oid + '.480'
    tejasStoctetsTx_oid = base_oid + '.482'

    # Fetch data for the defined OIDs
    ifOperStatus_data = fetch_data(host, ifOperStatus_oid)
    ifType_data = fetch_data(host, ifType_oid)
    objectName_data = fetch_data(host, objectName_oid)
    tejasStoctetsRx_data = fetch_data(host, tejasStoctetsRx_oid)
    tejasStoctetsTx_data = fetch_data(host, tejasStoctetsTx_oid)

    # Process the retrieved data and print as a comma-separated string
    for index, item in enumerate(objectName_data):
        objectName = objectName_data[index].value
        ifOperStatus = ifOperStatus_data[index].value
        ifType = ifType_data[index].value
        tejasStoctetsRx = tejasStoctetsRx_data[index].value
        tejasStoctetsTx = tejasStoctetsTx_data[index].value

        # Use the ifType dictionary to get the corresponding value
        ifType_str = iftype.get(ifType, "Unknown")

        output_string = f"objectName:{objectName},ifOperStatus:{ifOperStatus},ifType:{ifType_str},tejasStoctetsRx:{tejasStoctetsRx},tejasStoctetsTx:{tejasStoctetsTx}"
        print(output_string)

if __name__ == '__main__':
    main()

here is output of python script, here index and query are just parameter
xxxx:/var/www/html/cacti/scripts# ./olt_interface_traffic.py xxx_N_TJ8P_xxxT-1 index
objectName:Port_Eth-1000-1-1-1,ifOperStatus:2,ifType:eTHERNET,tejasStoctetsRx:0,tejasStoctetsTx:0
objectName:Port_Eth-10000-1-1-2,ifOperStatus:1,ifType:eTHERNET,tejasStoctetsRx:73856,tejasStoctetsTx:147712
objectName:Port_Eth-1000-1-1-3,ifOperStatus:2,ifType:eTHERNET,tejasStoctetsRx:0,tejasStoctetsTx:0
objectName:Port_Eth-10000-1-1-4,ifOperStatus:1,ifType:eTHERNET,tejasStoctetsRx:73856,tejasStoctetsTx:73856
objectName:Port_Eth-1000-1-1-5,ifOperStatus:1,ifType:eTHERNET,tejasStoctetsRx:23317,tejasStoctetsTx:31760
objectName:Port_Eth-1000-1-1-6,ifOperStatus:2,ifType:eTHERNET,tejasStoctetsRx:0,tejasStoctetsTx:0
objectName:Port_Eth-2500-1-1-201,ifOperStatus:1,ifType:eTHERNET,tejasStoctetsRx:0,tejasStoctetsTx:0
objectName:Port_Eth-2500-1-1-202,ifOperStatus:1,ifType:eTHERNET,tejasStoctetsRx:0,tejasStoctetsTx:0
objectName:Port_Eth-2500-1-1-203,ifOperStatus:1,ifType:eTHERNET,tejasStoctetsRx:0,tejasStoctetsTx:0
objectName:Port_Eth-2500-1-1-204,ifOperStatus:1,ifType:eTHERNET,tejasStoctetsRx:0,tejasStoctetsTx:0
objectName:Port_Eth-2500-1-1-205,ifOperStatus:1,ifType:eTHERNET,tejasStoctetsRx:0,tejasStoctetsTx:0
objectName:Port_Eth-2500-1-1-206,ifOperStatus:1,ifType:eTHERNET,tejasStoctetsRx:0,tejasStoctetsTx:0
objectName:Port_Eth-2500-1-1-207,ifOperStatus:1,ifType:eTHERNET,tejasStoctetsRx:0,tejasStoctetsTx:0
objectName:Port_Eth-2500-1-1-208,ifOperStatus:1,ifType:eTHERNET,tejasStoctetsRx:0,tejasStoctetsTx:0
objectName:Port_Eth-100-1-1-3595,ifOperStatus:1,ifType:eTHERNET,tejasStoctetsRx:176121,tejasStoctetsTx:176595
here is my xml file in /var/www/html/cacti/resource/snmp_queries/folder

Code: Select all

<interface>
   <name>Get OLT Interface Traffic</name>
   <script_path>/home/hostaddition/bin/python /var/www/html/cacti/scripts/olt_interface_traffic.py</script_path>
   <arg_prepend>|host_hostname| |</arg_prepend>
   <arg_index>index</arg_index>
   <arg_query>query</arg_query>
   <arg_get>walk</arg_get>
   <arg_num_indexes>num_indexes</arg_num_indexes>
   <output_delimeter>:</output_delimeter>
   <index_order>objectName</index_order>
   <index_order_type>numeric</index_order_type>
   <index_title_format>|chosen_order_field|</index_title_format>

   <fields>
      <objectName>
         <name>CPU Interface Name</name>
         <direction>input</direction>
         <query_name>index</query_name>
      </objectName>
      <ifOperStatus>
         <name>Operationaal Status</name>
         <direction>input</direction>
         <query_name>query</query_name>
      </ifOperStatus>
      <ifType>
         <name>Interface Type</name>
         <direction>input</direction>
         <query_name>query</query_name>
      </ifType>
      <tejasStoctetsRx>
         <name>Received Packets</name>
         <direction>output</direction>
         <query_name>tejasStoctetsRx</query_name>
      </tejasStoctetsRx>
      <tejasStoctetsTx>
         <name>Transmitted Packets</name>
         <direction>output</direction>
         <query_name>tejasStoctetsTx</query_name>
      </tejasStoctetsTx>

   </fields>
</interface>
getting below output
Data Query Debug Information
Total: 0.000000, Delta: 0.000000, Found data query XML file at '/var/www/html/cacti/resource/snmp_queries/olt_interface_traffic.xml'
Total: 0.000000, Delta: 0.000000, Running Data Query [25].
Total: 0.000000, Delta: 0.000000, Found Type = '4' [Script Query].
Total: 0.000000, Delta: 0.000000, XML file parsed ok.
Total: 0.220000, Delta: 0.220000, Executing script for num of indexes '/home/hostaddition/bin/python /var/www/html/cacti/scripts/olt_interface_traffic.py 'MUM_N_TJ16P_APOLT-1' '|' 'num_indexes''
Total: 0.220000, Delta: 0.000000, Found number of indexes: Usage: script.py <hostname>
Total: 0.450000, Delta: 0.220000, Executing script for list of indexes '/home/hostaddition/bin/python /var/www/html/cacti/scripts/olt_interface_traffic.py 'MUM_N_TJ16P_APOLT-1' '|' 'index'', Index Count: 1
Click to show Data Query output for 'index'
Found index: Usage: script.py <hostname>
Click to show Data Query output for field 'objectName'
Executing script query '/home/hostaddition/bin/python /var/www/html/cacti/scripts/olt_interface_traffic.py 'MUM_N_TJ16P_APOLT-1' '|' 'query' 'index''
Found item [objectName=' script.py <hostname>'] index: Usage
Click to show Data Query output for field 'ifOperStatus'
Executing script query '/home/hostaddition/bin/python /var/www/html/cacti/scripts/olt_interface_traffic.py 'MUM_N_TJ16P_APOLT-1' '|' 'query' 'query''
Found item [ifOperStatus=' script.py <hostname>'] index: Usage
Click to show Data Query output for field 'ifType'
Executing script query '/home/hostaddition/bin/python /var/www/html/cacti/scripts/olt_interface_traffic.py 'MUM_N_TJ16P_APOLT-1' '|' 'query' 'query''
Found item [ifType=' script.py <hostname>'] index: Usage
Total: 1.100000, Delta: 0.660000, Checking for Sort Field change. No changes detected.
Total: 1.100000, Delta: 0.000000, Update Data Query Sort Cache complete
Total: 1.100000, Delta: 0.000000, Index Association with Local Data complete
Total: 1.150000, Delta: 0.040000, No Index Changes Detected, Skipping Re-Index and Poller Cache Re-population
Total: 1.150000, Delta: 0.000000, Automation Executing for Data Query complete
Total: 1.150000, Delta: 0.000000, Plugin hooks complete
macan
Cacti Pro User
Posts: 898
Joined: Tue Mar 18, 2008 2:30 am
Location: Czech

Re: python script and data queries template is not working, support required

Post by macan »

Let the Cacti grow!
yedascientist
Posts: 10
Joined: Fri Oct 27, 2023 12:23 pm

Re: python script and data queries template is not working, support required

Post by yedascientist »

Thanks Macan,

I am not able to get index here, need to use snmp_bulkwalk in script to get result and not able to use get

here is output through snmpwalk disabling oid increment
scripts# snmpwalk -Cc -v2c -c private x.x.x.x .1.3.6.1.4.1.8255.1.2.1.2.37.1.1.3
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.3.10000.1.1.1 = INTEGER: 1
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.3.10000.1.1.2 = INTEGER: 1
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.3.10000.1.1.3 = INTEGER: 2
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.3.10000.1.1.4 = INTEGER: 1
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.3.1000.1.1.5 = INTEGER: 2
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.3.1000.1.1.6 = INTEGER: 2
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.3.1000.1.1.7 = INTEGER: 2
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.3.1000.1.1.8 = INTEGER: 2
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.3.2500.1.1.201 = INTEGER: 1
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.3.2500.1.1.202 = INTEGER: 1
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.3.2500.1.1.203 = INTEGER: 1
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.3.2500.1.1.204 = INTEGER: 1
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.3.2500.1.1.205 = INTEGER: 1
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.3.2500.1.1.206 = INTEGER: 1
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.3.2500.1.1.207 = INTEGER: 1
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.3.2500.1.1.208 = INTEGER: 1
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.3.2500.1.1.209 = INTEGER: 1
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.3.2500.1.1.210 = INTEGER: 1
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.3.2500.1.1.211 = INTEGER: 1
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.3.2500.1.1.212 = INTEGER: 1
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.3.2500.1.1.213 = INTEGER: 1
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.3.2500.1.1.214 = INTEGER: 1
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.3.2500.1.1.215 = INTEGER: 1
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.3.2500.1.1.216 = INTEGER: 1
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.3.100.1.1.3595 = INTEGER: 1
scripts# snmpwalk -Cc -v2c -c private x.x.x.x .1.3.6.1.4.1.8255.1.2.1.2.37.1.1.4
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.4.10000.1.1.1 = INTEGER: 6
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.4.10000.1.1.2 = INTEGER: 6
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.4.10000.1.1.3 = INTEGER: 6
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.4.10000.1.1.4 = INTEGER: 6
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.4.1000.1.1.5 = INTEGER: 6
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.4.1000.1.1.6 = INTEGER: 6
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.4.1000.1.1.7 = INTEGER: 6
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.4.1000.1.1.8 = INTEGER: 6
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.4.2500.1.1.201 = INTEGER: 6
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.4.2500.1.1.202 = INTEGER: 6
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.4.2500.1.1.203 = INTEGER: 6
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.4.2500.1.1.204 = INTEGER: 6
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.4.2500.1.1.205 = INTEGER: 6
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.4.2500.1.1.206 = INTEGER: 6
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.4.2500.1.1.207 = INTEGER: 6
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.4.2500.1.1.208 = INTEGER: 6
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.4.2500.1.1.209 = INTEGER: 6
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.4.2500.1.1.210 = INTEGER: 6
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.4.2500.1.1.211 = INTEGER: 6
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.4.2500.1.1.212 = INTEGER: 6
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.4.2500.1.1.213 = INTEGER: 6
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.4.2500.1.1.214 = INTEGER: 6
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.4.2500.1.1.215 = INTEGER: 6
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.4.2500.1.1.216 = INTEGER: 6
SNMPv2-SMI::enterprises.8255.1.2.1.2.37.1.1.4.100.1.1.3595 = INTEGER: 6
yedascientist
Posts: 10
Joined: Fri Oct 27, 2023 12:23 pm

Re: python script and data queries template is not working, support required

Post by yedascientist »

here is my updated python script

Code: Select all

#!/home/hostaddition/bin/python
import sys
from easysnmp import Session, snmp_get, snmp_walk

# Function to retrieve all indices from the target
def reindex(snmp_result):
    index_values = []
    for result in snmp_result:
        index_values.append(result.value)
    return index_values

# Define all OIDs needed for further processing
oids = {
    "index": ".1.3.6.1.4.1.8255.1.2.1.2.37.1.1.7",
    "ifOperStatus": ".1.3.6.1.4.1.8255.1.2.1.2.37.1.1.3",
    "ifType": ".1.3.6.1.4.1.8255.1.2.1.2.37.1.1.4",
    "objectName": ".1.3.6.1.4.1.8255.1.2.1.2.37.1.1.1001",
    "lCTName": ".1.3.6.1.4.1.8255.1.2.1.2.37.1.1.1002",
    "tejasStoctetsRx": ".1.3.6.1.4.1.8255.1.2.1.2.37.1.1.480",
    "tejasStoctetsTx": ".1.3.6.1.4.1.8255.1.2.1.2.37.1.1.482",
}

# Read input parameters
if len(sys.argv) < 7:
    print("Invalid use of script query, required parameters:")
    print("<hostname> <community> <version> <snmp_port> <timeout> <max_oids> [<auth_user> <auth_passphrase> <auth_proto> <priv_passphrase> <priv_proto> <context>] <cmd> [<query_field> <query_index>]")
    sys.exit(1)

hostname = sys.argv[1]
community = sys.argv[2]
version = sys.argv[3]
snmp_port = int(sys.argv[4])
snmp_timeout = int(sys.argv[5])
max_oids = int(sys.argv[6])
auth_user = sys.argv[7] if len(sys.argv) >= 8 else None
auth_passphrase = sys.argv[8] if len(sys.argv) >= 9 else None
auth_proto = sys.argv[9] if len(sys.argv) >= 10 else None
priv_passphrase = sys.argv[10] if len(sys.argv) >= 11 else None
priv_proto = sys.argv[11] if len(sys.argv) >= 12 else None
context = sys.argv[12] if len(sys.argv) >= 13 else None
cmd = sys.argv[13]
query_field = sys.argv[14] if len(sys.argv) >= 15 else None
query_index = sys.argv[15] if len(sys.argv) >= 16 else None

xml_delimiter = "!"

# Create an SNMP session
if version == "3" and auth_user and auth_passphrase and auth_proto:
    session = Session(hostname=hostname, community=community, version=int(version), remote_port=snmp_port, timeout=snmp_timeout, security_level="auth", auth_protocol=auth_proto, auth_password=auth_passphrase)
else:
    session = Session(hostname=hostname, community=community, version=int(version), remote_port=snmp_port, timeout=snmp_timeout)

# Perform different actions based on the command
if cmd == "index":
    # Retrieve all indices from the target
    index_values = reindex(session.bulkwalk(oids["index"], max_repetitions=max_oids))

    # Print each index as a separate line
    for index in index_values:
        print(index)
elif cmd == "query" and query_field:
    # Retrieve the specified field
    index_values = reindex(session.bulkwalk(oids["index"], max_repetitions=max_oids))
    field_values = reindex(session.bulkwalk(oids[query_field], max_repetitions=max_oids))

    for index, field in zip(index_values, field_values):
        print(f"{index}{xml_delimiter}{field}")
elif cmd == "get" and query_field and query_index:
    # Get the specified field for a specific index
    value = session.get(f"{oids[query_field]}.{query_index}").value
    print(value)
else:
    print("Invalid use of script query, required parameters:")
    print("<hostname> <community> <version> <snmp_port> <timeout> <max_oids> [<auth_user> <auth_passphrase> <auth_proto> <priv_passphrase> <priv_proto> <context>] <cmd> [<query_field> <query_index>]")
and output
abc# /home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py 'x.x.x.x' abcd 2 161 2 50 "" "" "" "" "" "" 'query' 'lCTName'
4096!ETH-1-1-1
8192!ETH-1-1-2
12288!ETH-1-1-3
16384!ETH-1-1-4
20480!ETH-1-1-5
24576!ETH-1-1-6
28672!ETH-1-1-7
32768!ETH-1-1-8
40960!BPETH-1-1-201
45056!BPETH-1-1-202
49152!BPETH-1-1-203
53248!BPETH-1-1-204
57344!BPETH-1-1-205
61440!BPETH-1-1-206
65536!BPETH-1-1-207
69632!BPETH-1-1-208
73728!BPETH-1-1-209
77824!BPETH-1-1-210
81920!BPETH-1-1-211
86016!BPETH-1-1-212
90112!BPETH-1-1-213
94208!BPETH-1-1-214
98304!BPETH-1-1-215
102400!BPETH-1-1-216
106496!CPU_PORT
abc# /home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py 'x.x.x.x' abcd 2 161 2 50 "" "" "" "" "" "" 'query' 'index'
4096!4096
8192!8192
12288!12288
16384!16384
20480!20480
24576!24576
28672!28672
32768!32768
40960!40960
45056!45056
49152!49152
53248!53248
57344!57344
61440!61440
65536!65536
69632!69632
73728!73728
77824!77824
81920!81920
86016!86016
90112!90112
94208!94208
98304!98304
102400!102400
106496!106496
abc# /home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py 'x.x.x.x' abcd 2 161 2 50 "" "" "" "" "" "" 'query' 'ifOperStatus'
4096!2
8192!1
12288!1
16384!1
20480!2
24576!2
28672!2
32768!2
40960!1
45056!1
49152!1
53248!1
57344!1
61440!1
65536!1
69632!1
73728!1
77824!1
81920!1
86016!1
90112!1
94208!1
98304!1
102400!1
106496!1
abc# /home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py 'x.x.x.x' abcd 2 161 2 50 "" "" "" "" "" "" 'query' 'tejasStoctetsRx'
4096!0
8192!1768802672
12288!9069684
16384!194880
20480!0
24576!0
28672!0
32768!0
40960!53555541
45056!89495076
49152!69409534
53248!112120453
57344!109363735
61440!263806403
65536!155976369
69632!0
73728!20063863
77824!47655144
81920!30146161
86016!65665626
90112!65744411
94208!213558337
98304!88853834
102400!0
106496!359227
abc# /home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py 'x.x.x.x' abcd 2 161 2 50 "" "" "" "" "" "" 'query' 'tejasStoctetsTx'
4096!0
8192!955574432
12288!209131518
16384!196096
20480!0
24576!0
28672!0
32768!0
40960!41267827
45056!502722295
49152!71300085
53248!515873360
57344!132626613
61440!254396660
65536!231856578
69632!0
73728!41277197
77824!502737143
81920!71306752
86016!516221531
90112!132649761
94208!254429534
98304!231885557
102400!0
106496!361362
here is my xml file

Code: Select all

<interface>
    <name>Get Interface Traffic Information</name>
    <script_path>/home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py</script_path>
    <arg_prepend>|host_hostname| abcd 2 161 2 50 "" "" "" "" "" ""</arg_prepend>
    <arg_index>index</arg_index>
    <arg_query>query</arg_query>
    <arg_get>get</arg_get>
    <output_delimiter>!</output_delimiter>
    <index_order>ifOperStatus</index_order>
    <index_order_type>numeric</index_order_type>
    <index_title_format>|chosen_order_field|</index_title_format>
    <arg_num_indexes>1</arg_num_indexes>
    <fields>
        <ifOperStatus>
            <name>IfOperStatus</name>
            <direction>input</direction>
            <query_name>ifOperStatus</query_name>
        </ifOperStatus>
        <ifType>
            <name>IfType</name>
            <direction>input</direction>
            <query_name>ifType</query_name>
        </ifType>
        <objectName>
            <name>ObjectName</name>
            <direction>input</direction>
            <query_name>objectName</query_name>
        </objectName>
        <lCTName>
            <name>lCTName</name>
            <direction>input</direction>
            <query_name>lCTName</query_name>
        </lCTName>

        <tejasStoctetsRx>
            <name>TejasStoctetsRx</name>
            <direction>output</direction>
            <query_name>tejasStoctetsRx</query_name>
        </tejasStoctetsRx>
        <tejasStoctetsTx>
            <name>TejasStoctetsTx</name>
            <direction>output</direction>
            <query_name>tejasStoctetsTx</query_name>
        </tejasStoctetsTx>
    </fields>
</interface>
cacti log showing invalid response and output: U
2023-10-30 01:25:13 - SPINE: Poller[Main Poller] PID[17514] PT[140217345238784] Device[x.x.x.x] HT[1] DS[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] Graphs[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] TT[200.41] SCRIPT: /home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py 'x.x.x.x' 'abcd' '2' '161' '2' '50' '""' '""' '""' '""' '""' '""' 'get' 'tejasStoctetsTx' '102400', output: U
2023-10-30 01:25:13 - SPINE: Poller[Main Poller] PID[17514] PT[140217345238784] WARNING: Invalid Response, Device[x.x.x.x] HT[1] DS[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] Graphs[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] SCRIPT: /home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py 'x.x.x.x' 'abcd' '2' '161' '2' '50' '""' '""' '""' '""' '""' '""' 'get' 'tejasStoctetsTx' '102400', output:
2023-10-30 01:25:12 - SPINE: Poller[Main Poller] PID[17514] PT[140217345238784] Device[x.x.x.x] HT[1] DS[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] Graphs[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] TT[199.81] SCRIPT: /home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py 'x.x.x.x' 'abcd' '2' '161' '2' '50' '""' '""' '""' '""' '""' '""' 'get' 'tejasStoctetsTx' '102400', output: U
2023-10-30 01:25:12 - SPINE: Poller[Main Poller] PID[17514] PT[140217345238784] WARNING: Invalid Response, Device[x.x.x.x] HT[1] DS[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] Graphs[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] SCRIPT: /home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py 'x.x.x.x' 'abcd' '2' '161' '2' '50' '""' '""' '""' '""' '""' '""' 'get' 'tejasStoctetsTx' '102400', output:
2023-10-30 01:25:12 - SPINE: Poller[Main Poller] PID[17514] PT[140217345238784] Device[x.x.x.x] HT[1] DS[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] Graphs[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] TT[201.16] SCRIPT: /home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py 'x.x.x.x' 'abcd' '2' '161' '2' '50' '""' '""' '""' '""' '""' '""' 'get' 'tejasStoctetsTx' '102400', output: U
2023-10-30 01:25:12 - SPINE: Poller[Main Poller] PID[17514] PT[140217345238784] WARNING: Invalid Response, Device[x.x.x.x] HT[1] DS[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] Graphs[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] SCRIPT: /home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py 'x.x.x.x' 'abcd' '2' '161' '2' '50' '""' '""' '""' '""' '""' '""' 'get' 'tejasStoctetsTx' '102400', output:
2023-10-30 01:25:12 - SPINE: Poller[Main Poller] PID[17514] PT[140217345238784] Device[x.x.x.x] HT[1] DS[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] Graphs[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] TT[202.48] SCRIPT: /home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py 'x.x.x.x' 'abcd' '2' '161' '2' '50' '""' '""' '""' '""' '""' '""' 'get' 'tejasStoctetsTx' '102400', output: U
2023-10-30 01:25:12 - SPINE: Poller[Main Poller] PID[17514] PT[140217345238784] WARNING: Invalid Response, Device[x.x.x.x] HT[1] DS[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] Graphs[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] SCRIPT: /home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py 'x.x.x.x' 'abcd' '2' '161' '2' '50' '""' '""' '""' '""' '""' '""' 'get' 'tejasStoctetsTx' '102400', output:
2023-10-30 01:25:11 - SPINE: Poller[Main Poller] PID[17514] PT[140217345238784] Device[x.x.x.x] HT[1] DS[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] Graphs[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] TT[207.26] SCRIPT: /home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py 'x.x.x.x' 'abcd' '2' '161' '2' '50' '""' '""' '""' '""' '""' '""' 'get' 'tejasStoctetsTx' '102400', output: U
2023-10-30 01:25:11 - SPINE: Poller[Main Poller] PID[17514] PT[140217345238784] WARNING: Invalid Response, Device[x.x.x.x] HT[1] DS[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] Graphs[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] SCRIPT: /home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py 'x.x.x.x' 'abcd' '2' '161' '2' '50' '""' '""' '""' '""' '""' '""' 'get' 'tejasStoctetsTx' '102400', output:
2023-10-30 01:25:11 - SPINE: Poller[Main Poller] PID[17514] PT[140217345238784] Device[x.x.x.x] HT[1] DS[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] Graphs[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] TT[206.24] SCRIPT: /home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py 'x.x.x.x' 'abcd' '2' '161' '2' '50' '""' '""' '""' '""' '""' '""' 'get' 'tejasStoctetsTx' '102400', output: U
2023-10-30 01:25:11 - SPINE: Poller[Main Poller] PID[17514] PT[140217345238784] WARNING: Invalid Response, Device[x.x.x.x] HT[1] DS[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] Graphs[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] SCRIPT: /home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py 'x.x.x.x' 'abcd' '2' '161' '2' '50' '""' '""' '""' '""' '""' '""' 'get' 'tejasStoctetsTx' '102400', output:
2023-10-30 01:25:10 - SPINE: Poller[Main Poller] PID[17514] PT[140217345238784] Device[x.x.x.x] HT[1] DS[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] Graphs[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] TT[202.53] SCRIPT: /home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py 'x.x.x.x' 'abcd' '2' '161' '2' '50' '""' '""' '""' '""' '""' '""' 'get' 'tejasStoctetsTx' '102400', output: U
2023-10-30 01:25:10 - SPINE: Poller[Main Poller] PID[17514] PT[140217345238784] WARNING: Invalid Response, Device[x.x.x.x] HT[1] DS[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] Graphs[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] SCRIPT: /home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py 'x.x.x.x' 'abcd' '2' '161' '2' '50' '""' '""' '""' '""' '""' '""' 'get' 'tejasStoctetsTx' '102400', output:
2023-10-30 01:25:10 - SPINE: Poller[Main Poller] PID[17514] PT[140217345238784] Device[x.x.x.x] HT[1] DS[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] Graphs[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] TT[204.91] SCRIPT: /home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py 'x.x.x.x' 'abcd' '2' '161' '2' '50' '""' '""' '""' '""' '""' '""' 'get' 'tejasStoctetsTx' '102400', output: U
2023-10-30 01:25:10 - SPINE: Poller[Main Poller] PID[17514] PT[140217345238784] WARNING: Invalid Response, Device[x.x.x.x] HT[1] DS[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] Graphs[x.x.x.x - Port_Eth-2500-1-1-216-BPETH-1-1-216 - Traffic] SCRIPT: /home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py 'x.x.x.x' 'abcd' '2' '161' '2' '50' '""' '""' '""' '""' '""' '""' 'get' 'tejasStoctetsTx' '102400', output:
macan
Cacti Pro User
Posts: 898
Joined: Tue Mar 18, 2008 2:30 am
Location: Czech

Re: python script and data queries template is not working, support required

Post by macan »

You are asking incorrectly. There should be query (with some parameter) or index. No both
abc# /home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py 'x.x.x.x' abcd 2 161 2 50 "" "" "" "" "" "" 'query' 'index'
Let the Cacti grow!
yedascientist
Posts: 10
Joined: Fri Oct 27, 2023 12:23 pm

Re: python script and data queries template is not working, support required

Post by yedascientist »

Hi Macan,
post changes in my script, its working get with parameter, query with parameter, however whenever i select graph creation, only one graph is created i.e. for 100.1.1.3595!CPU_PORT even selecting all graphs with ifOperStatus as 1

abcd# /home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py 'x.x.x.x' xxxxxx 2 161 2 50 "" "" "" "" "" "" get tejasStoctetsRx 100.1.1.3595
397096
abcd# /home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py 'x.x.x.x' xxxxxx 2 161 2 50 "" "" "" "" "" "" get tejasStoctetsTx 100.1.1.3595
401854
abcd# /home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py 'x.x.x.x' xxxxxx 2 161 2 50 "" "" "" "" "" "" query tejasStoctetsTx 100.1.1.3595
100.1.1.3595!413966
abcd# /home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py 'x.x.x.x' xxxxxx 2 161 2 50 "" "" "" "" "" "" query tejasStoctetsTx
10000.1.1.1!0
10000.1.1.2!3733432549
10000.1.1.3!613204799
10000.1.1.4!226944
1000.1.1.5!0
1000.1.1.6!0
1000.1.1.7!0
1000.1.1.8!0
2500.1.1.201!856999733
2500.1.1.202!2103588127
2500.1.1.203!691712704
2500.1.1.204!303619501
2500.1.1.205!13539908868
2500.1.1.206!1893124554
2500.1.1.207!6722295813
2500.1.1.208!0
2500.1.1.209!857090489
2500.1.1.210!2103760525
2500.1.1.211!691731974
2500.1.1.212!303646755
2500.1.1.213!13541164394
2500.1.1.214!1893240344
2500.1.1.215!6722461201
2500.1.1.216!0
100.1.1.3595!423864
abcd# /home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py 'x.x.x.x' xxxxxx 2 161 2 50 "" "" "" "" "" "" query index
10000.1.1.1!2
10000.1.1.2!1
10000.1.1.3!1
10000.1.1.4!1
1000.1.1.5!2
1000.1.1.6!2
1000.1.1.7!2
1000.1.1.8!2
2500.1.1.201!1
2500.1.1.202!1
2500.1.1.203!1
2500.1.1.204!1
2500.1.1.205!1
2500.1.1.206!1
2500.1.1.207!1
2500.1.1.208!1
2500.1.1.209!1
2500.1.1.210!1
2500.1.1.211!1
2500.1.1.212!1
2500.1.1.213!1
2500.1.1.214!1
2500.1.1.215!1
2500.1.1.216!1
100.1.1.3595!1
abcd# /home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py 'x.x.x.x' xxxxxx 2 161 2 50 "" "" "" "" "" "" index
10000.1.1.1
10000.1.1.2
10000.1.1.3
10000.1.1.4
1000.1.1.5
1000.1.1.6
1000.1.1.7
1000.1.1.8
2500.1.1.201
2500.1.1.202
2500.1.1.203
2500.1.1.204
2500.1.1.205
2500.1.1.206
2500.1.1.207
2500.1.1.208
2500.1.1.209
2500.1.1.210
2500.1.1.211
2500.1.1.212
2500.1.1.213
2500.1.1.214
2500.1.1.215
2500.1.1.216
100.1.1.3595


abcd# /home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py 'x.x.x.x' xxxxxx 2 161 2 50 "" "" "" "" "" "" query objectName
10000.1.1.1!Port_Eth-10000-1-1-1
10000.1.1.2!Port_Eth-10000-1-1-2
10000.1.1.3!Port_Eth-10000-1-1-3
10000.1.1.4!Port_Eth-10000-1-1-4
1000.1.1.5!Port_Eth-1000-1-1-5
1000.1.1.6!Port_Eth-1000-1-1-6
1000.1.1.7!Port_Eth-1000-1-1-7
1000.1.1.8!Port_Eth-1000-1-1-8
2500.1.1.201!Port_Eth-2500-1-1-201
2500.1.1.202!Port_Eth-2500-1-1-202
2500.1.1.203!Port_Eth-2500-1-1-203
2500.1.1.204!Port_Eth-2500-1-1-204
2500.1.1.205!Port_Eth-2500-1-1-205
2500.1.1.206!Port_Eth-2500-1-1-206
2500.1.1.207!Port_Eth-2500-1-1-207
2500.1.1.208!Port_Eth-2500-1-1-208
2500.1.1.209!Port_Eth-2500-1-1-209
2500.1.1.210!Port_Eth-2500-1-1-210
2500.1.1.211!Port_Eth-2500-1-1-211
2500.1.1.212!Port_Eth-2500-1-1-212
2500.1.1.213!Port_Eth-2500-1-1-213
2500.1.1.214!Port_Eth-2500-1-1-214
2500.1.1.215!Port_Eth-2500-1-1-215
2500.1.1.216!Port_Eth-2500-1-1-216
100.1.1.3595!Port_Eth-100-1-1-3595
abcd# /home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py 'x.x.x.x' xxxxxx 2 161 2 50 "" "" "" "" "" "" query lCTName
10000.1.1.1!ETH-1-1-1
10000.1.1.2!ETH-1-1-2
10000.1.1.3!ETH-1-1-3
10000.1.1.4!ETH-1-1-4
1000.1.1.5!ETH-1-1-5
1000.1.1.6!ETH-1-1-6
1000.1.1.7!ETH-1-1-7
1000.1.1.8!ETH-1-1-8
2500.1.1.201!BPETH-1-1-201
2500.1.1.202!BPETH-1-1-202
2500.1.1.203!BPETH-1-1-203
2500.1.1.204!BPETH-1-1-204
2500.1.1.205!BPETH-1-1-205
2500.1.1.206!BPETH-1-1-206
2500.1.1.207!BPETH-1-1-207
2500.1.1.208!BPETH-1-1-208
2500.1.1.209!BPETH-1-1-209
2500.1.1.210!BPETH-1-1-210
2500.1.1.211!BPETH-1-1-211
2500.1.1.212!BPETH-1-1-212
2500.1.1.213!BPETH-1-1-213
2500.1.1.214!BPETH-1-1-214
2500.1.1.215!BPETH-1-1-215
2500.1.1.216!BPETH-1-1-216
100.1.1.3595!CPU_PORT

here is my xml file

Code: Select all

<interface>
    <name>Get Interface Traffic Information</name>
    <script_path>/home/hostaddition/bin/python /var/www/html/cacti/scripts/query_interface_traffic.py</script_path>
    <arg_prepend>|host_hostname| xxxxxx 2 161 2 50 "" "" "" "" "" ""</arg_prepend>
    <arg_index>index</arg_index>
    <arg_query>query</arg_query>
    <arg_get>get</arg_get>
    <output_delimiter>!</output_delimiter>
    <index_order>ifOperStatus</index_order>
    <index_order_type>numeric</index_order_type>
    <index_title_format>|chosen_order_field|</index_title_format>
    <arg_num_indexes>1</arg_num_indexes>
    <fields>
        <ifOperStatus>
            <name>ifOperStatus</name>
            <direction>input</direction>
            <query_name>ifOperStatus</query_name>
        </ifOperStatus>
        <ifType>
            <name>IfType</name>
            <direction>input</direction>
            <query_name>ifType</query_name>
        </ifType>
        <!--<objectName>
            <name>ObjectName</name>
            <direction>input</direction>
            <query_name>objectName</query_name>
        </objectName>
        <lCTName>
            <name>lCTName</name>
            <direction>input</direction>
            <query_name>lCTName</query_name>
        </lCTName> -->

        <tejasStoctetsRx>
            <name>TejasStoctetsRx</name>
            <direction>output</direction>
            <query_name>tejasStoctetsRx</query_name>
        </tejasStoctetsRx>
        <tejasStoctetsTx>
            <name>TejasStoctetsTx</name>
            <direction>output</direction>
            <query_name>tejasStoctetsTx</query_name>
        </tejasStoctetsTx>
        <objectName>
            <name>ObjectName</name>
            <direction>input</direction>
            <query_name>objectName</query_name>
        </objectName>
        <lCTName>
            <name>lCTName</name>
            <direction>input</direction>
            <query_name>lCTName</query_name>
        </lCTName>



    </fields>
</interface>
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests