It can also create a Template, with a Command DataSource, with Multiple DataPoints. This means you can now automate the creation of Templates and DataSources and DataPoints. So if you are using a tool like Puppet, Cfengine, Bcfg2, or Chef, this process can be automated. I will be adding more features in the next few weeks.
Any question or help about this script, please post them here http://www.linuxdynasty.org/forums/Scripting/scripting/ZenossTemplateManager
UPDATES!!!!!!
- Update 1.0.6, Fixed an issue where if youdo not pass the -G option for graph it will fail.
- Update 1.0.5, Now have the ability to add multiple graphs with multiple datapoints
- Update 1.0.4, Now have the ability to create thresholds, bind templates to class or device, set severities on thresholds and
datasources, attach datapoints to thresholds. - Update 1.0.3, I broke down the templateManager function into 3 smaller functions. You also can now list templates and datasources for either device or organizer, and list datapoints for a device. I also added more verbosity with the -V option.
- Update 1.0.2, You now do not have to pass a command with the script. So i f you already have a command in the DataSource, it wll not get overwritten.. Thank you Eangel, for telling me about this issue..
Upcoming Features such as….
- Deleteing Templates, DataSources, and DataPoints
- Copying Templates
- Adding Graphs
The tool is called Zenoss_Template_Manager.py. You can download it here..
Download
Here are some examples….
Examples: python Zenoss_Template_Manager.py -d "zenoss.linuxdynasty" -c'/opt/zenoss/libexec/snmp_branch.py -c public -d localhost -p 161 -o 1.3.6.1.2.1.2.2.1 --ival="1" --label="ifIndex,ifDescr,ifType,ifMtu,ifSpeed,ifPhysAddress,ifAdminStatus,ifOperStatus,ifLastChange,ifInOctets,ifInUcastPkts,ifInNUcastPkts,InDiscards,ifInErrors,ifInUnknownProtos,ifOutOctets,ifOutUcastPkts,ifOutNUcastPkts,ifOutDiscards,ifOutErrors,ifOutQLen,ifSpecific"'--template=TESTER4LIFE2 -p "ifSpeed,G" -p "ifInOctets,C" -p "ifInUcastPkts,C" -p "ifInNUcastPkts,C" -p "ifInDiscards,C" -p "ifInErrors,C" -p "ifOutOctets,C" -p "ifOutUcastPkts,C" -p "ifOutNUcastPkts,C" -p "ifOutDiscards,C" -p "ifOutErrors,C" --dsource="WoW2
If you already have the command in place for that DataSource, then run the script with out the -c option…
Examples:
python Zenoss_Template_Manager.py -d "zenoss.linuxdynasty" --template=TESTER4LIFE2 \ -p "ifSpeed,G" -p "ifInOctets,C" -p "ifInUcastPkts,C" -p "ifInNUcastPkts,C" -p "ifInDiscards,C" \ -p "ifInErrors,C" -p "ifOutOctets,C" -p "ifOutUcastPkts,C" -p "ifOutNUcastPkts,C" -p "ifOutDiscards,C" \ -p "ifOutErrors,C" --dsource="WoW2"
Another Example With The Verbose Option..
[zenoss@zenoss2 ~]$ python Zenoss_Template_Manager.py -o "/Devices/Server/Linux" \ -c '/opt/zenoss/libexec/snmp_branch.py -c public -d localhost -p 161 -o 1.3.6.1.2.1.2.2.1 --ival="1" --label="ifIndex,ifDescr,ifType,ifMtu,ifSpeed,ifPhysAddress,ifAdminStatus,ifOperStatus,ifLastChange,ifInOctets,ifInUcastPkts, ifInNUcastPkts,InDiscards,ifInErrors,ifInUnknownProtos,ifOutOctets,ifOutUcastPkts,ifOutNUcastPkts,ifOutDiscards,ifOutErrors,ifOutQLen,ifSpecific"' \ -t FooYoo -p "ifSpeed,G" -p "ifInOctets,C" -p "ifInUcastPkts,C" -p "ifInNUcastPkts,C" -p "ifInDiscards,C" -p "ifInErrors,C" -p "ifOutOctets,C" -p "ifOutUcastPkts,C" \ -p "ifOutNUcastPkts,C" -p "ifOutDiscards,C" -p "ifOutErrors,C" -s "eth0" -S "Critical" -P "Nagios" -b -V Template FooYoo already exists at /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYooBinded Templates : ['Shaolin', 'Device', 'NtpMonitor', 'TESTER4L1F3', 'TESTER', 'FooYoo', 'FooYoo']DataSource eth0 already exists at /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYoo/datasources/eth0Command /opt/zenoss/libexec/snmp_branch.py -c public -d localhost -p 161 -o 1.3.6.1.2.1.2.2.1 --ival="1" --label="ifIndex,ifDescr,ifType,ifMtu,ifSpeed,ifPhysAddress,ifAdminStatus,ifOperStatus,ifLastChange,ifInOctets,ifInUcastPkts,ifInNUcastPkts,InDiscards,ifInErrors,ifInUnknownProtos,ifOutOctets,ifOutUcastPkts,ifOutNUcastPkts,ifOutDiscards,ifOutErrors,ifOutQLen,ifSpecific" has been added to DataSource /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYoo/datasources/eth0Parser = NagiosSeverity = 5eth0 DataSource is EnabledDataPoint ifSpeed of type GAUGE has been added to DataSource /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYoo/datasources/eth0DataPoint ifInOctets of type COUNTER has been added to DataSource /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYoo/datasources/eth0DataPoint ifInUcastPkts of type COUNTER has been added to DataSource /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYoo/datasources/eth0DataPoint ifInNUcastPkts of type COUNTER has been added to DataSource /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYoo/datasources/eth0DataPoint ifInDiscards of type COUNTER has been added to DataSource /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYoo/datasources/eth0DataPoint ifInErrors of type COUNTER has been added to DataSource /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYoo/datasources/eth0DataPoint ifOutOctets of type COUNTER has been added to DataSource /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYoo/datasources/eth0DataPoint ifOutUcastPkts of type COUNTER has been added to DataSource /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYoo/datasources/eth0DataPoint ifOutNUcastPkts of type COUNTER has been added to DataSource /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYoo/datasources/eth0DataPoint ifOutDiscards of type COUNTER has been added to DataSource /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYoo/datasources/eth0DataPoint ifOutErrors of type COUNTER has been added to DataSource /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYoo/datasources/eth0
I also added the ability to list templates, datasources, and datapoints…
Examples Below…
python Zenoss_Template_Manager.py -d "qazenoss" --list="datapoints" -t "TESTER4LIFE2" ifInDiscards /zport/dmd/Devices/Server/Tomcat/devices/qazenoss/TESTER4LIFE2/datasources/WoW2/datapoints/ifInDiscardsifInErrors /zport/dmd/Devices/Server/Tomcat/devices/qazenoss/TESTER4LIFE2/datasources/WoW2/datapoints/ifInErrorsifInNUcastPkts /zport/dmd/Devices/Server/Tomcat/devices/qazenoss/TESTER4LIFE2/datasources/WoW2/datapoints/ifInNUcastPktsifInOctets /zport/dmd/Devices/Server/Tomcat/qdevices/qazenoss/TESTER4LIFE2/datasources/WoW2/datapoints/ifInOctetsifInUcastPkts /zport/dmd/Devices/Server/Tomcat/devices/qazenoss/TESTER4LIFE2/datasources/WoW2/datapoints/ifInUcastPktsifOutDiscards /zport/dmd/Devices/Server/Tomcat/devices/qazenoss/TESTER4LIFE2/datasources/WoW2/datapoints/ifOutDiscardsifOutErrors /zport/dmd/Devices/Server/Tomcat/devices/qazenoss/TESTER4LIFE2/datasources/WoW2/datapoints/ifOutErrorsifOutNUcastPkts /zport/dmd/Devices/Server/Tomcat/devices/qazenoss/TESTER4LIFE2/datasources/WoW2/datapoints/ifOutNUcastPktsifOutOctets /zport/dmd/Devices/Server/Tomcat/devices/qazenoss/TESTER4LIFE2/datasources/WoW2/datapoints/ifOutOctetsifOutUcastPkts /zport/dmd/Devices/Server/Tomcat/devices/qazenoss/TESTER4LIFE2/datasources/WoW2/datapoints/ifOutUcastPktsifSpeed /zport/dmd/Devices/Server/Tomcat/devices/qazenoss/TESTER4LIFE2/datasources/WoW2/datapoints/ifSpeed
python Zenoss_Template_Manager.py -o "/Devices/Server/Tomcat" -l "datasources" -t "Tomcat Thread Pool" Tomcat Current Thread Count /zport/dmd/Devices/Server/Tomcat/rrdTemplates/Tomcat%20Thread%20Pool/datasources/Tomcat%20Current%20Thread%20CountTomcat Current Threads Busy /zport/dmd/Devices/Server/Tomcat/rrdTemplates/Tomcat%20Thread%20Pool/datasources/Tomcat%20Current%20Threads%20Busy python Zenoss_Template_Manager.py -o "/Devices/Server/Tomcat" -l "templates" DigMonitor /zport/dmd/Devices/Server/rrdTemplates/DigMonitorFtpMonitor /zport/dmd/Devices/rrdTemplates/FtpMonitorJava /zport/dmd/Devices/rrdTemplates/Java
Example of creating a Threshold..
[zenoss@zenoss ~]$ python Zenoss_Template_Manager.py -o "/Devices/Server/Linux" -t FooYoo -T FooYee -p "eth0_ifInOctets" -s "eth0" -S "Warning" -m 0 -M 20 -V Template FooYoo already exists at /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYooDataSource eth0 already exists at /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYoo/datasources/eth0FooYee threshold created at /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYoo/thresholds/FooYeeminval = 0maxval = 20Severity = 3 eth0_ifInOctets datapoint added to threshold /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYoo/thresholds/FooYeeFooYee Threshold is Enabled
Now here is an example of Adding Graphs..
Remember, when adding DataPoints to your graphs, you are adding the name of the DataSource_Datapoint. You can see what the names of the DataPoints you have available by using the –list=”datapoints” option with the –template=TEMPLATE_NAME option
python Zenoss_Template_Manager.py -d "zenoss.linuxdynasty" -t "TESTER" -G "eth0 Discards, eth0_ifInDiscards, eth0_ifOutDiscards, units=discards"
here is an example of adding graphs with a template and a datasource and multiple datapoints..
python Zenoss_Template_Manager.py -o "/Devices/Server/Linux" -c '/opt/zenoss/libexec/snmp_branch.py -c public -d localhost -p 161 -o 1.3.6.1.2.1.2.2.1 --ival="1" \ --label="ifIndex,ifDescr,ifType,ifMtu,ifSpeed,ifPhysAddress,ifAdminStatus,ifOperStatus,ifLastChange,ifInOctets,ifInUcastPkts,ifInNUcastPkts,InDiscards,ifInErrors,ifInUnknownProtos,ifOutOctets,ifOutUcastPkts,ifOutNUcastPkts,ifOutDiscards,ifOutErrors,ifOutQLen,ifSpecific"' \ -t FooYoo -p "ifSpeed,G" -p "ifInOctets,C" -p "ifInUcastPkts,C" -p "ifInNUcastPkts,C" -p "ifInDiscards,C" -p "ifInErrors,C" -p "ifOutOctets,C" -p "ifOutUcastPkts,C" -p "ifOutNUcastPkts,C" -p "ifOutDiscards,C" -p "ifOutErrors,C"\ -s "eth0" -S "Critical" -P "Nagios" -b -G "eth0 Discards, eth0_ifInDiscards, eth0_ifOutDiscards, units=discards" -G "eth1 Discards, eth0_ifInDiscards, eth0_ifOutDiscards, units=discards" -V Template FooYoo created at /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYooBinded Templates : ['Shaolin', 'Device', 'NtpMonitor', 'TESTER4L1F3', 'TESTER', 'FooYoo', 'FooYoo'] DataSource eth0 created at /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYoo/datasources/eth0Parser = NagiosCommand /opt/zenoss/libexec/snmp_branch.py -c public -d localhost -p 161 -o 1.3.6.1.2.1.2.2.1 --ival="1" --label="ifIndex,ifDescr,ifType,ifMtu,ifSpeed,ifPhysAddress,ifAdminStatus,ifOperStatus,ifLastChange,ifInOctets,ifInUcastPkts,ifInNUcastPkts,InDiscards,ifInErrors,ifInUnknownProtos,ifOutOctets,ifOutUcastPkts,ifOutNUcastPkts,ifOutDiscards,ifOutErrors,ifOutQLen,ifSpecific" has been added to DataSource /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYoo/datasources/eth0Severity = 5 eth0 DataSource is EnabledDataPoint ifSpeed of type GAUGE has been added to DataSource /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYoo/datasources/eth0DataPoint ifInOctets of type COUNTER has been added to DataSource /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYoo/datasources/eth0DataPoint ifInUcastPkts of type COUNTER has been added to DataSource /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYoo/datasources/eth0DataPoint ifInNUcastPkts of type COUNTER has been added to DataSource /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYoo/datasources/eth0DataPoint ifInDiscards of type COUNTER has been added to DataSource /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYoo/datasources/eth0DataPoint ifInErrors of type COUNTER has been added to DataSource /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYoo/datasources/eth0DataPoint ifOutOctets of type COUNTER has been added to DataSource /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYoo/datasources/eth0DataPoint ifOutUcastPkts of type COUNTER has been added to DataSource /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYoo/datasources/eth0DataPoint ifOutNUcastPkts of type COUNTER has been added to DataSource /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYoo/datasources/eth0DataPoint ifOutDiscards of type COUNTER has been added to DataSource /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYoo/datasources/eth0DataPoint ifOutErrors of type COUNTER has been added to DataSource /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYoo/datasources/eth0 eth0 Discards graph was created with ['eth0_ifInDiscards', 'eth0_ifOutDiscards'] DataPoints attached at /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYoo/graphDefs/eth0%20Discards eth1 Discards graph was created with ['eth0_ifInDiscards', 'eth0_ifOutDiscards'] DataPoints attached at /zport/dmd/Devices/Server/Linux/rrdTemplates/FooYoo/graphDefs/eth1%20Discards
To see the Help output, just run it like this python Zenoss_Template_Manager.py -h
Hey Dynasty,
This tool is awesome. Thanks for creating it. Can you help me with this problem?
What is wrong with this syntax. I can’t seem to add graphs
python Zenoss_Template_Manager.py -d “” –template=App-Application-Stats -G “Application Runtimes – Breakdown Instance 1, ApplicationStats-Instance1_datafilter-sqlcache, ApplicationStats-Instance1_datafilter_eventlog, ApplicationStats-Instance1_bpmedia_runtime, ApplicationStats-Instance1_content-runtime, ApplicationStats-Instance1_xdata-runtime, ApplicationStats-Instance1_campaign-revenue-runtime, ApplicationStats-Instance1_winningbids-runtime, ApplicationStats-Instance1_geo-runtime, ApplicationStats-Instance1_bpdetail-runtime, ApplicationStats-Instance1_freq-runtime, ApplicationStats-Instance1-leadback-runtime, ApplicationStats-Instance1-segmentation-runtime, ApplicationStats-Instance1_megment-rtd-runtime” -V
Template already exists at
Traceback (most recent call last):
File “Zenoss_Template_Manager.py”, line 348, in
graphs = graphCreator(template)
File “Zenoss_Template_Manager.py”, line 72, in graphCreator
graph.manage_deleteGraphPoints(graph.getGraphPointsNames())
AttributeError: ‘NoneType’ object has no attribute ‘manage_deleteGraphPoints’
I do not see the –dsource option or short form -s.. Which is needed.
Hi Dynasty,
I’m trying to bind template to a device in Zenoss, using command line. I tried using your script (Zenoss_Template_Manager.py).
I entered following command to run the script :
python Zenoss_Template_Manager.py -d “3.204.40.112″ –list=”datapoints”
Where 3.204.40.112 is the device which I want to bind a template to.
However, I keep getting following error:
‘import site’ failed; use -v for traceback
Traceback (most recent call last):
File “Zenoss_Template_Manager.py”, line 32, in ?
import Globals
ImportError: No module named Globals
I tried setting PYTHONPATH, sudoers as –
Defaults env_reset, env_keep=*
Still no luck. Request you to help.
Are you running this as the zenoss user?