|
|
| Author |
Message |
gninja Cacti User
Joined: 24 Aug 2004 Posts: 326 Location: San Francisco, CA
|
Posted: Mon Nov 30, 2009 9:50 pm Post subject: Automatic template generation |
|
|
As I work in a very dynamic environment, with a lot of different products requiring a lot of new and unique graphing, anything that speeds up template generation benefits me greatly.
And what's worth doing for oneself is worth sharing.
So, here's my automatic template generation script. It's in python, as I work in a python heavy environment, and it's more important for my code to be understood by my coworkers than it is for it to be pure, but the code is pretty clean and should make sense to anyone who has done any scripting.
Feel free to take it apart and make it do whatever you want, but it should be have all the features you might like. If you find bugs, let me know and I'll see about fixing them.
The other day I made 49 new graph templates, with 1-4 data points per graph, as well as the associated data templates and the data input method, with this script, in about 90 minutes, and not a single one had a problem beyond tweaking titles or labels. I hope it's useful to others as well.
So, here you go.
You may need to edit line 29, to point to your cacti config.php, if you don't want to pass database hostname, username, and password on the command line.
| Code: | $ ./cacti_build-templates.py --help
usage: cacti_build-templates.py [options]
example: cacti_build-templates.py --script "<path_cacti>/scripts/snmp_extend.sh <hostname> <snmp_community> jstat_jboss-gcutil" --hostname app-server.domain.com
example: cacti_build-templates.py --script "<path_cacti>/scripts/snmp_extend.sh <hostname> <snmp_community> jstat_jboss-gcutil" --hostname app-server.domain.com --dstype=gauge --title="JVM GC Summary" --group 'S0,S1,E,O,P!YGC,FGC!YGCT,FGCT,GCT' --friendlies='S0:Survivor 0 % Capacity,S1:Survivor 1 % Capacity,E:Eden % Capacity,YGC:Young GC Events,YGCT:Young GC Time,FGC:Full GC Events,FGCT:Full GC Time,GCT:Total GC Time' --dstypeoverride='YGCT:derive,FGCT:derive,GCT:derive' --templates 'HostTemplate'
options:
-h, --help show this help message and exit
-s SCRIPT, --script=SCRIPT
Script to run for DIM inspection. Cacti style
bracketing for input sources. Anything other than
<path_cacti>, <hostname>, <snmp_community> will not be
handled properly at this time!
-H HOSTNAME, --hostname=HOSTNAME
Hostname to run input script against for validation
--group=GROUP CSV style input for DS grouping onto single graphs.
--group 'name1,name2,name3!name2,name6,name12' to
group onto multiple multi-item graphs. Duplicates ok!
--height=HEIGHT Height of graphs. Default=120
--width=WIDTH Width of graphs. Default=500
--area Create Area/Stack type graph instead of line type
graph.
--title=TITLE Shared DS and Graph Title. Defaults to base of script.
--templates=TEMPLATES
CSV Host Templates to add new graphs to.
--rrdmax=RRDMAX RRD Maximum for data templates, Default=1000000000
--rrdmin=RRDMIN RRD Minimum for data templates, Default=0
--rrdbeat=RRDBEAT RRD Heartbeat for data templates, Default=600
--dstype=DSTYPE RRD DS type for data templates, Default=gauge
--dstypeoverride=DSTYPEOVERRIDE
CSV of DS:Type list for overriding --dstype for
individual data sources
--friendly Prompt for Friendly Names for DS inputs.
--friendlies=FRIENDLIES
CSV of DS:Friendly Name, instead of prompting.
--dbhost=DBHOST Database hostname to connect to. Default=localhost
--database=DB Database to connect to. Default=cacti
--www=WWWHOST WWW Host to use in url generation.
-u USER, --user=USER User to connect to as. Default=cactiuser
-p PASSWORD, --password=PASSWORD
Password to connect with. Default=<redacted>
-v, --verbose print debug messages to stderr
--justrun Just run the script, don't build templates.
|
And the output from the first example.
| Code: | $ ./cacti_build-templates.py --script "<path_cacti>/scripts/snmp_extend.sh <hostname> <snmp_community> jstat_jboss-gcutil" --hostname app-server.domain.com --dstype=gauge --title Magic
About to run script for inspection:
/usr/local/share/cacti/scripts/snmp_extend.sh app-server.domain.com XXXXX jstat_jboss-gcutil
Script output is:
S0:0.00 S1:0.00 E:76.46 O:13.32 P:91.09 YGC:7047 YGCT:629281 FGC:1220 FGCT:1359952 GCT:1989234
Creating Data Input Method for 'Magic'
Adding field 'S0' to DIM.
Adding field 'S1' to DIM.
Adding field 'E' to DIM.
Adding field 'O' to DIM.
Adding field 'P' to DIM.
Adding field 'YGC' to DIM.
Adding field 'YGCT' to DIM.
Adding field 'FGC' to DIM.
Adding field 'FGCT' to DIM.
Adding field 'GCT' to DIM.
Data Input Method created:
https://cacti-www/cacti/data_input.php?action=edit&id=135
Running create_templates for S0
Creating Data Template 'Magic/S0'
Adding Data Source 'S0' to Data Template 'Magic/S0'
https://cacti-www/cacti/data_templates.php?action=template_edit&id=388
Creating Graph Template 'Magic/S0'
https://cacti-www/cacti/graph_templates.php?action=template_edit&id=334
Graph Added - graph-id: (42853) - data-source-ids: (60342)
Running create_templates for S1
Creating Data Template 'Magic/S1'
Adding Data Source 'S1' to Data Template 'Magic/S1'
https://cacti-www/cacti/data_templates.php?action=template_edit&id=389
Creating Graph Template 'Magic/S1'
https://cacti-www/cacti/graph_templates.php?action=template_edit&id=335
Graph Added - graph-id: (42854) - data-source-ids: (60343)
Running create_templates for E
Creating Data Template 'Magic/E'
Adding Data Source 'E' to Data Template 'Magic/E'
https://cacti-www/cacti/data_templates.php?action=template_edit&id=390
Creating Graph Template 'Magic/E'
https://cacti-www/cacti/graph_templates.php?action=template_edit&id=336
Graph Added - graph-id: (42855) - data-source-ids: (60344)
Running create_templates for O
Creating Data Template 'Magic/O'
Adding Data Source 'O' to Data Template 'Magic/O'
https://cacti-www/cacti/data_templates.php?action=template_edit&id=391
Creating Graph Template 'Magic/O'
https://cacti-www/cacti/graph_templates.php?action=template_edit&id=337
Graph Added - graph-id: (42856) - data-source-ids: (60345)
Running create_templates for P
Creating Data Template 'Magic/P'
Adding Data Source 'P' to Data Template 'Magic/P'
https://cacti-www/cacti/data_templates.php?action=template_edit&id=392
Creating Graph Template 'Magic/P'
https://cacti-www/cacti/graph_templates.php?action=template_edit&id=338
Graph Added - graph-id: (42857) - data-source-ids: (60346)
Running create_templates for YGC
Creating Data Template 'Magic/YGC'
Adding Data Source 'YGC' to Data Template 'Magic/YGC'
https://cacti-www/cacti/data_templates.php?action=template_edit&id=393
Creating Graph Template 'Magic/YGC'
https://cacti-www/cacti/graph_templates.php?action=template_edit&id=339
Graph Added - graph-id: (42858) - data-source-ids: (60347)
Running create_templates for YGCT
Creating Data Template 'Magic/YGCT'
Adding Data Source 'YGCT' to Data Template 'Magic/YGCT'
https://cacti-www/cacti/data_templates.php?action=template_edit&id=394
Creating Graph Template 'Magic/YGCT'
https://cacti-www/cacti/graph_templates.php?action=template_edit&id=340
Graph Added - graph-id: (42859) - data-source-ids: (60348)
Running create_templates for FGC
Creating Data Template 'Magic/FGC'
Adding Data Source 'FGC' to Data Template 'Magic/FGC'
https://cacti-www/cacti/data_templates.php?action=template_edit&id=395
Creating Graph Template 'Magic/FGC'
https://cacti-www/cacti/graph_templates.php?action=template_edit&id=341
Graph Added - graph-id: (42860) - data-source-ids: (60349)
Running create_templates for FGCT
Creating Data Template 'Magic/FGCT'
Adding Data Source 'FGCT' to Data Template 'Magic/FGCT'
https://cacti-www/cacti/data_templates.php?action=template_edit&id=396
Creating Graph Template 'Magic/FGCT'
https://cacti-www/cacti/graph_templates.php?action=template_edit&id=342
Graph Added - graph-id: (42861) - data-source-ids: (60350)
Running create_templates for GCT
Creating Data Template 'Magic/GCT'
Adding Data Source 'GCT' to Data Template 'Magic/GCT'
https://cacti-www/cacti/data_templates.php?action=template_edit&id=397
Creating Graph Template 'Magic/GCT'
https://cacti-www/cacti/graph_templates.php?action=template_edit&id=343
Graph Added - graph-id: (42862) - data-source-ids: (60351)
|
Enjoy!
| Description: |
|
 Download |
| Filename: |
cacti_build-templates.py.gz |
| Filesize: |
5.05 KB |
| Downloaded: |
35 Time(s) |
|
|
| Back to top |
|
 |
Linegod Developer
Joined: 20 Feb 2003 Posts: 950 Location: Canada
|
|
| Back to top |
|
 |
mcutting Cacti Guru User
Joined: 16 Oct 2006 Posts: 1622 Location: United Kingdom
|
Posted: Tue Dec 01, 2009 6:36 am Post subject: |
|
|
| Have you had a look at Gandalf's "autom8" ?
|
|
| Back to top |
|
 |
gninja Cacti User
Joined: 24 Aug 2004 Posts: 326 Location: San Francisco, CA
|
Posted: Tue Dec 01, 2009 2:07 pm Post subject: |
|
|
| mcutting wrote: | | Have you had a look at Gandalf's "autom8" ? |
Not until a few minutes ago. Looks neat, but I already have something I've written that ties into our host allocation system and does pretty much everything autom8 does (and dumps back problem reports, into our ticketing system)..
autom8 looks great, but it looks like it just uses existing templates to create graphs based on data queries.
This script creates entirely new templates, based solely on the data collected by a collection script. Only limitation that it has, is that it doesn't apply CDEFs, but so far I've not had a need for that.
|
|
| Back to top |
|
 |
gandalf Developer
Joined: 02 Dec 2004 Posts: 15639 Location: Muenster, Germany
|
Posted: Tue Dec 01, 2009 4:11 pm Post subject: |
|
|
My goal is NOT to move you away from your solution.
But I'd like to learn how autom8 can be put one step beyond. So I'd like to understand what still is missing from your point of view.
R.
|
|
| Back to top |
|
 |
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|