Back to Geneos FAQ

How to use Python with the API plug-in

Geneos - How to use Python with the API plug-in Your Python version needs to be at least 2.7

Below is an example python script for sending data to the netprobe via the API plugin. For this example, a Managed Entity named “InfraSvr06” and an API sampler named “myAPI” needs to be set up before the following script is initiated. Please read the comments carefully.

Python API Plugin Example:

(Do not copy the code below. Use the attached YourScipt.py)

import xmlrpclib
import time

#Your Python version needs to be 2.7 or higher...
#For I am the XMLRPC client, I need to contact my XMLRPC server (in our case the NetProbe)
#Ideally, with no ssl in mind, it should be as follows http://<Netprobe hostname>:<Netprobe Port>/xmlrpc
#However SSL is possible with this script, it is outside the scope of this example.
server = xmlrpclib.ServerProxy("http://netprobeHost:7036/xmlrpc")

#Empty Python Array
params = []

#Let's Create a view; "Dataview Name", "Dataview grouping"
params = ["py-queues", "Python"]
try: #Lets create a dataview, will get an error if one is already created with the same name
result = getattr(server, "InfraSvr06.myAPI.createview")(params[0], params[1])
except xmlrpclib.Fault, err:
print "Error"
print "Fault code: %d" % err.faultCode
print "Fault string: %s" % err.faultString
del params[:] #if you want to clean up the old array

#Let's do a headline
params = ["totalQueues"]
try:
result = getattr(server, "InfraSvr06.myAPI.Python-py-queues.addHeadline")(params[0])
except xmlrpclib.Fault, err:
print "Error"
print "Fault code: %d" % err.faultCode
print "Fault string: %s" % err.faultString

#Let's do another headline!
params = ["queuesOffline"]
try:
result = getattr(server, "InfraSvr06.myAPI.Python-py-queues.addHeadline")(params[0])
except xmlrpclib.Fault, err:
print "Error"
print "Fault code: %d" % err.faultCode
print "Fault string: %s" % err.faultString

#Using a multi-dimensional array for our Dataview
DataviewMatrix = [
["queueName", "currentSize", "maxSize", "currentUtilisation", "status"], #Keep in mind, the First is actually your column headings
["queue1", "332", "30000", "0.11", "online"], #This is where you will be starting your first row.
["queue2", "0", "90000", "0", "offline"],
["queue3", "7331", "45000", "0.16", "online"]
]

#The matrix of our Dataview,
params[0] = DataviewMatrix
result = getattr(server, "InfraSvr06.myAPI.Python-py-queues.updateEntireTable")(params[0])

params = ["totalQueues", 3]
result = getattr(server, "InfraSvr06.myAPI.Python-py-queues.updateHeadline")(params[0], params[1])

params = ["queuesOffline", 1]
result = getattr(server, "InfraSvr06.myAPI.Python-py-queues.updateHeadline")(params[0], params[1])

bSendTestData = True

if bSendTestData:
params[0] = "queue2.currentSize" #Imagine this as "x,y" coordinates, we're updating "row name"."column name"
for x in xrange(1,1000):
params[1] = "%d" % x
try:
getattr(server, "InfraSvr06.myAPI.Python-py-queues.updateTableCell")(params[0], params[1])
getattr(server, "InfraSvr06.myAPI.Python-py-queues.updateHeadline")("queuesOffline", params[1])
time.sleep(1) #Sleep for one second
except xmlrpclib.Fault, err:
print "Error"
print "Fault code: %d" % err.faultCode
print "Fault string: %s" % err.faultString

Once you saved this script as “.py” file just run it with the following command:

python YourScript.py

Ideally, you should have a view similar to the following:

8343170572829 mceclip0

["Geneos"] ["Geneos > Netprobe"] ["FAQ"]

Was this topic helpful?