|
|
| Author |
Message |
oxo-oxo Cacti User
Joined: 30 Aug 2007 Posts: 89 Location: Denmark
|
Posted: Tue Sep 04, 2007 5:27 am Post subject: addg - add graphs via add_graphs in bash |
|
|
Playing with the code to see if I can make batch import
If you have a linux machine, the code works but doesn't add a graph but gives an idea what is happening
It should also be sourced: then call the subroutine from cmd line
| Code: |
#!/bin/bash
lists(){
type=$1
shift
extra=$*
php5 cli/add_graphs.php $type $extra
}
plingit(){
sed "s/\(.*\)/'\1' /"
}
hosts(){
{
lists --list-hosts
} | grep [0-9]
}
hostids(){
eval harray=( $(hosts|plingit) )
for h in $(seq 0 $(( ${#harray[@]}-1)) );do
eval hline=( ${harray[$h]} )
eval hostid=${hline[0]}
echo $hostid
done
}
cleanup(){
grep -v "Known" | grep [a-z,A-Z]
}
snmpvalues(){
hostid=$1
snmpfield=$2
{
lists --list-snmp-values --host-id=$hostid --snmp-field=$snmpfield
} | cleanup
}
snmpfields(){
hostid=$1
{
lists --list-snmp-fields --host-id=$hostid
} | cleanup
}
doit(){
for hostid in $(hostids);do
for snmpfield in $(snmpfields $hostid);do
for snmpvalue in $(snmpvalues $hostid $snmpfield);do
echo "'$hostid';$snmpfield;$snmpvalue"
done
done
done
}
{
cat <<EOF
Please source the script ...
For referance:
php5 cli/add_graphs.php \
--host-id=$hostid --graph-template-id=2 \
--graph-title="$hostid $snmpvalue" \
--graph-type=ds \
--snmp-query-id=1 --snmp-query-type-id=13 \
--snmp-field=$snmpfield --snmp-value=$snmpvalue
EOF
}
|
Please note that there are cleanup routines to get rid of blank lines and verbose comments in the output of add_graphs
- it would be nice if the add_graphs just put out the result and left verbose for a parameter
Makes bash parsing a lot easier if they did ...
Last edited by oxo-oxo on Wed Sep 05, 2007 12:44 am; edited 9 times in total |
|
| Back to top |
|
 |
oxo-oxo Cacti User
Joined: 30 Aug 2007 Posts: 89 Location: Denmark
|
Posted: Tue Sep 04, 2007 5:35 am Post subject: |
|
|
Necessary changes if you are to have the same setup:
None pt. |
|
| Back to top |
|
 |
oxo-oxo Cacti User
Joined: 30 Aug 2007 Posts: 89 Location: Denmark
|
Posted: Wed Sep 05, 2007 12:36 am Post subject: |
|
|
This will be edited every now and again.
It seems that cacti has a lib/api_automation_tools.php that is included by the cli tools:
| Code: | function api_tree_item_save($id, $tree_id, $type, $parent_tree_item_id, $title, $local_graph_id, $rra_id,
function get_host_templates() {
function get_hosts_by_description() {
function getHosts() {
function get_addresses() {
function getSNMPFields($hostId) {
function getSNMPValues($hostId, $field) {
function getSNMPQueries() {
function getSNMPQueryTypes($snmpQueryId) {
function displayQueryTypes($types) {
function getGraphTemplates() {
function display_host_templates($host_templates) {
function display_communities() {
function displaySNMPFields($fields, $hostId) {
function displaySNMPValues($values, $hostId, $field) {
function displaySNMPQueries($queries) {
function displayGraphTemplates($templates) {
function displayHosts($hosts) { |
And some of the cli tools
| Code: | add_device.php copy_user.php poller_reindex_hosts.php
add_graphs.php rebuild_poller_cache.php
add_perms.php poller_graphs_reapply_names.php
add_tree.php poller_output_empty.php |
So is this enough?
Well, for my own cisco case, I need something like:
if (description_on($device, $interface) add_graph($device,$interface,$graph_template,$graph_txt)
Can we get there?
add_graphs can list-hosts via library so the key host $id is available by searching for the $device so that is left to the reader
$interface is also possible to get ifDesc
--host-id=$id --snmp-field=ifDesc --list-snmp-values
$graph_template is also availale
--list-graph-templates
$graph_txt is really a function of host name graph template ifDescr and ifAlias: needs work...
But the problem now is to find out via cacti's library, which interfaces for a host have a description.
It is possible to scan one's backups but...
So at some stage I will try and define what the api library could give access to: but I have to thonk sorry think first or else one wasts one's time.
Input welcome
(solution being worked on is http://forums.cacti.net/viewtopic.php?t=23193)
Please note that
--host-id=$id --snmp-field=ifAlias --list-snmp-values
doesn't show duplicated descriptions, just unique list. |
|
| Back to top |
|
 |
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|