skip to main content
op5 API Documentation : Nacoma CLI API Documentation
  
Nacoma CLI API Documentation
Syntax help to use with the Nacoma CLI API.
 
The API is located here: /opt/monitor/op5/nacoma/api/monitor.php
 
This is the commandline API towards the Nacoma database.
 
Usage:
monitor.php -t|--obj_type <object type>
-n <string> (Old) name of object
-R <string> rename object (parameter=new_name)
-i <ID> Object ID in database
-o <array> Additional options for object
-a <string> [delete, save_config, undo_config]
-H Show this help
-E Show this help + examples
 
Examples:
CREATE NEW HOST:
php monitor.php -t host -o host_name=API_TESTHOST -o alias=API_TESTHOST -o address=192.168.1.26 -o template=default-host-template -o contacts=monitor -u monitor
ADD SERVICE:
php monitor.php -t service -o template=default-service -o host_name=API_TESTHOST -o service_description=API_TEST_SERVICE -o check_command=check_ping -o check_command_args=100,20%\!500,60% -u monitor
ADD CONTACT:
php monitor.php -t contact -o contact_name=API_CONTACT -o alias=API_CONTACT -o email=someone@op5.com -o service_notification_period=none -o host_notification_period=none -u monitor
ADD TIMEPERIOD
php monitor.php -t timeperiod -o timeperiod_name=API_TIMEPERIOD -o alias=API_TIMEPERIOD -u monitor
ADD COMMAND
php monitor.php -t command -o command_name=CHECK_TEST -o command_line=\$USER1\$/check_plugin.pl\ \-H\ \$HOSTADDRESS\$\ \-t\ 10 -u monitor
 
DELETE SERVICE:
php monitor.php -t service -n "API_TESTHOST;API_TESTSERVICE" -a delete -u monitor
DELETE HOST:
php monitor.php -t host -n API_TESTHOST -a delete -u monitor
DELETE CONTACT:
php monitor.php -t contact -n API_CONTACT -a delete -u monitor
DELETE HOST:
php monitor.php -t host -n API_TESTHOST -a delete -u monitor
DELETE TIMEPERIOD
php monitor.php -t timeperiod -a delete -n API_TIMEPERIOD -u monitor
DELETE COMMAND
php monitor.php -t command -a delete -n CHECK_TEST -u monitor
SHOW HOST
php monitor.php -t host -a show_object -n API_TESTHOST -u monitor
SHOW SERVICE
php monitor.php -t service -a show_object -n "API_TESTHOST;API_TESTSERVICE" -u monitor
LIST AVAILABLE OBJECTS OF TYPE
php monitor.php -t service_template -a list_objects -u monitor
SAVE CONFIGURATION TO FILE:
php monitor.php -a save_config -u monitor
UNDO CONFIGURATION CHANGES (READ CONFIG FROM FILE);
php monitor.php -a undo_config -u monitor
 
Note 1: that the '!' and '$' char need to be escaped with a backslash '\' as in the service and command examples above.
Also spaces needs to be escaped.
Note 2: also that the service object differ from all other object since it is not only identified by
the service description, hostname is also needed. A service is identified by the
hostname;service_description tuple, separated by a semicolon.
Note 3: All commands need to be acompanied with -u <user> as in the examples above. If the default
user 'monitor' has been removed or his privileges reduced a different user need to be used.
 
Workflow:
When working with the Nacoma API it is important to know a few things about op5 Monitor operations.
First of all, op5 Monitor uses configuration files, the Nacoma database is only used to create the
configuration files. When saving the configuration using the save button in the webinterface or the
'-a save_config' commandline option the database is written to file and the op5 Monitor process is
re-loaded. The reverse function is the 'Undo applied changes' button in the webinterface and the
'-a undo_config' commandline option. The fetches the configuration from file and populates the
database.
 
When using the commandline API you normally start by issuing '-a undo_config'. This is good
practice since we otherwise might write changes made in the webinterface to file that was never
meant to be saved to file. When all changes are applied to database we issue '-a save_config' to
write the configuration to file. IE to add 2 hosts with one service and delete a contact we do:
1, php monitor.php -a undo_config -u monitor
2, php monitor.php -t host -o host_name=API_TESTHOST_1 -o alias=API_TESTHOST_1 -o address=192.168.1.26 -o template=default-host-template -o contacts=monitor -u monitor
3, php monitor.php -t service -o template=default-service -o host_name=API_TESTHOST_1 -o service_description=API_TEST_SERVICE -o check_command=check_ping -o check_command_args=100,20%\!500,60% -u monitor
4, php monitor.php -t host -o host_name=API_TESTHOST_2 -o alias=API_TESTHOST_2 -o address=192.168.1.27 -o template=default-host-template -o contacts=monitor -u monitor
5, php monitor.php -t service -o template=default-service -o host_name=API_TESTHOST_2 -o service_description=API_TEST_SERVICE -o check_command=check_ping -o check_command_args=100,20%\!500,60% -u monitor
6, php monitor.php -t contact -n API_CONTACT -a delete -u monitor
7, php monitor.php -a save_config -u monitor