Cacti (home)ForumsDocumentation
Cacti: offical forums and support
It is currently Tue Apr 23, 2019 3:25 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: add node header without duplicates
PostPosted: Sun Dec 09, 2018 11:32 am 
Offline

Joined: Sun Dec 09, 2018 6:58 am
Posts: 2
hi,

i'm new to cacti, it's an amazing system.

i'm having an issue when i'm trying to automate the adding process, in the " add_tree.php --type=node --node-type=header --tree-id=1 --name=test " script it adds node headers regardless of it exists or not.

is there any solution to this? i've combed google for this with no luck

what i'm trying to do is to output just the id if the header exists, and if not to create one.

thanks for the help


Top
 Profile  
 
 Post subject: Re: add node header without duplicates
PostPosted: Mon Dec 10, 2018 6:57 am 
Offline
Cacti Guru User

Joined: Sun Aug 27, 2017 12:05 am
Posts: 2397
It's likely that it is allowed as you can have the same name used repeatedly throughout a tree. However, I think it would be prudent to only allow the same name once at each tree level. What version of Cacti are you using?

_________________
Official Cacti Developer

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation

My resources:
How to submit Pull Requests
Development Wiki and How To's
Updated NetSNMP Memory template for Cacti 1.x
Cisco SFP template for Cacti 0.8.8


Top
 Profile  
 
 Post subject: Re: add node header without duplicates
PostPosted: Tue Dec 11, 2018 3:26 am 
Offline

Joined: Sun Dec 09, 2018 6:58 am
Posts: 2
thanks for the reply,

i'm using 1.1.38,

i tried this code

parent_node_list=$(php -q /var/lib/cacti/cli/add_tree.php --list-nodes --tree-id=1)

if grep $name <<< "$parent_node_list"; then
1>$parent_node_id //this is the part that i can't figure, i can't get the matching found header id to an stdout so the device can use the
header id

else

parent_node_id=$(php -q /var/lib/cacti/cli/add_tree.php --type=node --node-type=header --tree-id=1 --name="$name")
fi

the code adds only once the $name but i get an echo output instead of it storing the id in a variable for the device to use


Top
 Profile  
 
 Post subject: Re: add node header without duplicates
PostPosted: Wed Dec 12, 2018 3:37 am 
Offline
Cacti Guru User

Joined: Sun Aug 27, 2017 12:05 am
Posts: 2397
Code:
sudo -u www-data php -q cli/add_tree.php --list-nodes --tree-id=1 | grep "^Header" | cut -d'   ' -f 4 | grep -qw "Machine"


Notes:
  • the -d value on the cut command is a tab not spaces.
  • the last grep returns its result (-q) which will be the process exit result ($? under most shells) and searches for the full name (-w)
  • to make grep return a count, change the -q to a -c and then capture the output (the $? result will then be sudo's execution status)

_________________
Official Cacti Developer

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation

My resources:
How to submit Pull Requests
Development Wiki and How To's
Updated NetSNMP Memory template for Cacti 1.x
Cisco SFP template for Cacti 0.8.8


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Protected by Anti-Spam ACP Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group