Page 1 of 1

root cmd line utility to delete service

Posted: Sat May 23, 2020 12:54 am
by zaji_nms
Dear Expert

is there any command line utility (shell / perl / php script) to delete any service?

an example looks like

root#del_nagios_service "host" "service"

regards

Re: root cmd line utility to delete service

Posted: Tue May 26, 2020 11:04 am
by lmiltchev
I assume that you don't want to use the REST API to delete services, correct? If this is the case, you could use the "ccm_delete_object.php" script, located in the "/usr/local/nagiosxi/scripts" directory.

Usage:
# php ccm_delete_object.php --help

Deletes an object (or list of objects) from the CCM database.

Usage: ./ccm_delete_host.php [option] ..

Example: Remove all services from service with config name localhost
./ccm_delete_host.php -t service -c localhost

Usage Options:
-t|--type <type> Object type (host, service, contact, timeperiod)
-i|--id <object id> (OPTIONAL) Object ID
\Host Type Options:
-n|--name <host name> (OPTIONAL) Host name (host type only)

Service Type Options:
-c|--config <config name> (OPTIONAL) Config name to remove all services from (service type only)

Help and Logging:
-h|--help Print out help output
Example:

Code: Select all

php /usr/local/nagiosxi/scripts/ccm_delete_object.php -t service -i <id>
where you substitute <id> with the actual ID of the object.

Hope this helps.

Re: root cmd line utility to delete service

Posted: Wed May 27, 2020 1:40 am
by zaji_nms
yes lmiltchev, u r correct, we don't want to use REST API , but you (NAGIOSxi) not displaying OBJECTid, plz plz mention object id in the another column every where , its very very important too (same as DISPLAY_NAME, plz show ObjectID every where) in

Home Operations Center
Home Host Detail
Home Service Detail

till you implement above, is there any way, just we provide below detail and our job can done?

root#del_nagios_service "host" "service" <<<< v r interested deleting SERVICE not Host

Re: root cmd line utility to delete service

Posted: Wed May 27, 2020 11:10 am
by lmiltchev
...but you (NAGIOSxi) not displaying OBJECTid...
Object ID is shown in the CCM.
example-02.jpg
If your user has root access but doesn't have access to the CCM, you could try obtaining the ID via a mysql query. This is an example bash script that you could probably use:

find_ip

Code: Select all

#!/bin/bash
echo "select id from tbl_service where service_description='$1' and config_name='$2';"|mysql -u root -pnagiosxi nagiosql|tail -1
When you run it, you pass two arguments. The first one is the service_description, and the second one is the config_name.

Examples:

Code: Select all

./find_ip '<service_description>' '<config_name>'

Code: Select all

[root@main-nagios-xi tmp]# ./find_ip 'PING' 'localhost'
1
[root@main-nagios-xi tmp]# ./find_ip 'HTTP' 'localhost'
8
[root@main-nagios-xi tmp]# ./find_ip 'Ping' 'MacOSX'
204
[root@main-nagios-xi tmp]# ./find_ip 'Cron Scheduling Daemon' 'CentOS-NRPE'
84
Once you have the ID of the service that you need to delete, you could simply run:

Code: Select all

php /usr/local/nagiosxi/scripts/ccm_delete_object.php -t service -i <id>