Page 1 of 1

Service add via CLI

Posted: Fri Nov 30, 2018 2:51 am
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

Re: Service add via CLI

Posted: Fri Nov 30, 2018 9:22 am
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.

Re: Service add via CLI

Posted: Fri Nov 30, 2018 9:29 am
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"