Service add via CLI

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
progressive.nagiosXI
Posts: 277
Joined: Mon Jul 31, 2017 5:54 am

Service add via CLI

Post by progressive.nagiosXI »

Hi Team,
We have a project going on using mod-gearman and need to configure network devices in monitoring,

many devices have over 500 ports in there and we need to add it via using CCM and its getting very difficult to add. please help or give any soluion for this,


we have tried using API option but its giving kind a error is there any other way to this can we do auto discovery or add services in services.cfg file sort of it will help.


[root@Nagios ~]# curl -XPOST "http://IP/nagiosxi/api/v1/config/servic ... D&pretty=1" -d "host_name=test&service_description=bandwidth&check_command=check_bandwidth!htread 4" > 600 " " > 800 "!!!!!!!&check_interval=5&retry_interval=5&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7&applyconfig=1"
-bash: !htread: event not found
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Service add via CLI

Post by mcapra »

Make sure your Bash commands contain proper escaping:
http://wiki.bash-hackers.org/syntax/quoting

! is a reserved Bash character and appears in your command. Also, several un-escaped double-quotes (") appear in your command.

I would also batch-up your several hundred transactions without &applyconfig=1 set. You really don't want to be applying the configuration for every single transaction if there's a bunch of them -- it'll take forever. Set them all up first, then apply the configuration in the very final request.
Former Nagios employee
https://www.mcapra.com/
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Service add via CLI

Post by scottwilkerson »

Your API command needs to escape ! and if you are adding additional " in the arguments like so:

Code: Select all

curl -XPOST "http://IP/nagiosxi/api/v1/config/service?apikey=APIdD&pretty=1" -d "host_name=test&service_description=bandwidth&check_command=check_bandwidth\!htread 4\" > 600 \" \" > 800 \"\!\!\!\!\!\!\!&check_interval=5&retry_interval=5&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7&applyconfig=1"
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked