Skip to content

Commit

Permalink
rest: add support for new log commands
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Sep 18, 2024
1 parent 6f6179a commit 8389a13
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ This file documents the revision history for the Monitoring Webinterface Thruk.
next:
- show host attributes on grid/overview pages
- make status badges toggle buttons
- Rest:
- add support for host/service note commands
ex.: /hosts/<name>/cmd/note
and /services/<host>/<service>/cmd/note
- add new endpoint /system/cmd/log

3.18 Tue Sep 10 22:30:40 CEST 2024
- add optional oauth 2.1 pkce workflow
Expand Down
3 changes: 3 additions & 0 deletions docs/documentation/rest.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,7 @@ list of supported commands:
- link:rest_commands.html#post-hostsnamecmdenable_host_svc_checks[enable_host_svc_checks]
- link:rest_commands.html#post-hostsnamecmdenable_host_svc_notifications[enable_host_svc_notifications]
- link:rest_commands.html#post-hostsnamecmdenable_passive_host_checks[enable_passive_host_checks]
- link:rest_commands.html#post-hostsnamecmdnote[note]
- link:rest_commands.html#post-hostsnamecmdprocess_host_check_result[process_host_check_result]
- link:rest_commands.html#post-hostsnamecmdremove_host_acknowledgement[remove_host_acknowledgement]
- link:rest_commands.html#post-hostsnamecmdschedule_and_propagate_host_downtime[schedule_and_propagate_host_downtime]
Expand Down Expand Up @@ -1603,6 +1604,7 @@ list of supported commands:
- link:rest_commands.html#post-serviceshostservicecmdenable_svc_event_handler[enable_svc_event_handler]
- link:rest_commands.html#post-serviceshostservicecmdenable_svc_flap_detection[enable_svc_flap_detection]
- link:rest_commands.html#post-serviceshostservicecmdenable_svc_notifications[enable_svc_notifications]
- link:rest_commands.html#post-serviceshostservicecmdnote[note]
- link:rest_commands.html#post-serviceshostservicecmdprocess_service_check_result[process_service_check_result]
- link:rest_commands.html#post-serviceshostservicecmdremove_svc_acknowledgement[remove_svc_acknowledgement]
- link:rest_commands.html#post-serviceshostservicecmdschedule_forced_svc_check[schedule_forced_svc_check]
Expand Down Expand Up @@ -1824,6 +1826,7 @@ list of supported commands:
- link:rest_commands.html#post-systemcmdenable_notifications[enable_notifications]
- link:rest_commands.html#post-systemcmdenable_performance_data[enable_performance_data]
- link:rest_commands.html#post-systemcmdenable_service_freshness_checks[enable_service_freshness_checks]
- link:rest_commands.html#post-systemcmdlog[log]
- link:rest_commands.html#post-systemcmdread_state_information[read_state_information]
- link:rest_commands.html#post-systemcmdrestart_process[restart_process]
- link:rest_commands.html#post-systemcmdrestart_program[restart_program]
Expand Down
28 changes: 28 additions & 0 deletions docs/documentation/rest_commands.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,15 @@ This command does not require any arguments.

See http://www.naemon.io/documentation/developer/externalcommands/enable_passive_host_checks.html for details.

=== POST /hosts/<name>/cmd/note

Add host note to core log.

Required arguments:

* log


=== POST /hosts/<name>/cmd/process_host_check_result

Sends the PROCESS_HOST_CHECK_RESULT command.
Expand Down Expand Up @@ -1189,6 +1198,15 @@ This command does not require any arguments.

See http://www.naemon.io/documentation/developer/externalcommands/enable_svc_notifications.html for details.

=== POST /services/<host>/<service>/cmd/note

Add service note to core log.

Required arguments:

* log


=== POST /services/<host>/<service>/cmd/process_service_check_result

Sends the PROCESS_SERVICE_CHECK_RESULT command.
Expand Down Expand Up @@ -1486,6 +1504,16 @@ This command does not require any arguments.

See http://www.naemon.io/documentation/developer/externalcommands/enable_service_freshness_checks.html for details.

=== POST /system/cmd/log

Add custom log entry to core log.

Required arguments:

* log

See http://www.naemon.io/documentation/developer/externalcommands/log.html for details.

=== POST /system/cmd/read_state_information

Causes Naemon to load all current monitoring status information from the state retention file. Normally, state retention information is loaded when the Naemon process starts up and before it starts monitoring. WARNING: This command will cause Naemon to discard all current monitoring status information and use the information stored in state retention file! Use with care.
Expand Down
31 changes: 29 additions & 2 deletions lib/Thruk/Controller/Rest/V1/cmd.pm
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,10 @@ sub _rest_get_external_command {
}
}

my $cmd_line = "COMMAND [".time()."] ".uc($cmd->{'name'});
my $cmd_line = "COMMAND [".time()."] ".($cmd->{'cmdname'} // uc($cmd->{'name'}));
if(scalar @cmd_args > 0) {
$cmd_line .= ';'.join(';', @cmd_args);
$cmd_line .= ';' unless $cmd->{'cmdname'}; # only add leading ; for normal commands
$cmd_line .= join(';', @cmd_args);
}
my $cmd_list = [$cmd_line];

Expand Down Expand Up @@ -587,6 +588,13 @@ __DATA__
#
# See http://www.naemon.io/documentation/developer/externalcommands/enable_passive_host_checks.html for details.
# REST PATH: POST /hosts/<name>/cmd/note
# Add host note to core log.
#
# Required arguments:
#
# * log
#
# REST PATH: POST /hosts/<name>/cmd/process_host_check_result
# Sends the PROCESS_HOST_CHECK_RESULT command.
#
Expand Down Expand Up @@ -967,6 +975,13 @@ __DATA__
#
# See http://www.naemon.io/documentation/developer/externalcommands/enable_svc_notifications.html for details.
# REST PATH: POST /services/<host>/<service>/cmd/note
# Add service note to core log.
#
# Required arguments:
#
# * log
#
# REST PATH: POST /services/<host>/<service>/cmd/process_service_check_result
# Sends the PROCESS_SERVICE_CHECK_RESULT command.
#
Expand Down Expand Up @@ -1558,6 +1573,15 @@ __DATA__
#
# See http://www.naemon.io/documentation/developer/externalcommands/enable_service_freshness_checks.html for details.
# REST PATH: POST /system/cmd/log
# Add custom log entry to core log.
#
# Required arguments:
#
# * log
#
# See http://www.naemon.io/documentation/developer/externalcommands/log.html for details.
# REST PATH: POST /system/cmd/read_state_information
# Causes Naemon to load all current monitoring status information from the state retention file. Normally, state retention information is loaded when the Naemon process starts up and before it starts monitoring. WARNING: This command will cause Naemon to discard all current monitoring status information and use the information stored in state retention file! Use with care.
#
Expand Down Expand Up @@ -1758,6 +1782,7 @@ __DATA__
"enable_host_svc_checks":{"args":[],"name":"enable_host_svc_checks","nr":"15","required":[]},
"enable_host_svc_notifications":{"args":[],"name":"enable_host_svc_notifications","nr":"28","required":[]},
"enable_passive_host_checks":{"args":[],"name":"enable_passive_host_checks","nr":"92","required":[]},
"note":{"args":["log"],"cmdname":"LOG;HOST NOTE: ","docs":"Add host note to core log.","name":"note","nr":-1,"required":["log"],"thrukcmd":1},
"process_host_check_result":{"args":["plugin_state","plugin_output","performance_data"],"name":"process_host_check_result","nr":"87","required":["plugin_state","plugin_output"]},
"remove_host_acknowledgement":{"args":[],"name":"remove_host_acknowledgement","nr":"51","required":[]},
"schedule_and_propagate_host_downtime":{"args":["start_time","end_time","fixed","triggered_by","duration","comment_author","comment_data"],"name":"schedule_and_propagate_host_downtime","nr":"55","required":["comment_data"]},
Expand Down Expand Up @@ -1815,6 +1840,7 @@ __DATA__
"enable_svc_event_handler":{"args":[],"name":"enable_svc_event_handler","nr":"45","required":[]},
"enable_svc_flap_detection":{"args":[],"name":"enable_svc_flap_detection","nr":"59","required":[]},
"enable_svc_notifications":{"args":[],"name":"enable_svc_notifications","nr":"22","required":[]},
"note":{"args":["log"],"cmdname":"LOG;SERVICE NOTE: ","docs":"Add service note to core log.","name":"note","nr":-1,"required":["log"],"thrukcmd":1},
"process_service_check_result":{"args":["plugin_state","plugin_output","performance_data"],"name":"process_service_check_result","nr":"30","required":["plugin_state","plugin_output"]},
"remove_svc_acknowledgement":{"args":[],"name":"remove_svc_acknowledgement","nr":"52","required":[]},
"schedule_forced_svc_check":{"args":["start_time"],"name":"schedule_forced_svc_check","nr":"7","required":[]},
Expand All @@ -1840,6 +1866,7 @@ __DATA__
"enable_notifications":{"args":[],"name":"enable_notifications","nr":"12","required":[]},
"enable_performance_data":{"args":[],"name":"enable_performance_data","nr":"82","required":[]},
"enable_service_freshness_checks":{"args":[],"docs":"Enables freshness checks of all services on a program-wide basis. Individual services that have freshness checks disabled will not be checked for freshness.","name":"enable_service_freshness_checks","nr":-1,"required":[]},
"log":{"args":["log"],"docs":"Add custom log entry to core log.","name":"log","nr":-1,"required":["log"]},
"read_state_information":{"args":[],"docs":"Causes Naemon to load all current monitoring status information from the state retention file. Normally, state retention information is loaded when the Naemon process starts up and before it starts monitoring. WARNING: This command will cause Naemon to discard all current monitoring status information and use the information stored in state retention file! Use with care.","name":"read_state_information","nr":-1,"required":[]},
"restart_process":{"args":[],"name":"restart_process","nr":"13","required":[]},
"restart_program":{"args":[],"docs":"Restarts the Naemon process.","name":"restart_program","nr":-1,"required":[]},
Expand Down
3 changes: 3 additions & 0 deletions script/thruk_update_docs_rest.pl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ sub _update_cmds {
#'CHANGE_HOST_EVENT_HANDLER' => {"args" => ["eventhandler"], "required" => ["eventhandler"], "docs" => "Changes the event handler command for a particular host to be that specified by the \'event_handler_command\' option. The \'event_handler_command\' option specifies the short name of the command that should be used as the new host event handler. The command must have been configured in Naemon before it was last (re)started."},
#'CHANGE_HOST_CHECK_COMMAND' => {"args" => ["checkcommand"], "required" => ["checkcommand"], "docs" => "Changes the check command for a particular host to be that specified by the \'check_command\' option. The \'check_command\' option specifies the short name of the command that should be used as the new host check command. The command must have been configured in Naemon before it was last (re)started."},
'CHANGE_CUSTOM_HOST_VAR' => {"args" => ["name", "value"], "required" => ["name", "value"], "docs" => "Changes the value of a custom host variable."},
'NOTE' => {"args" => ["log"], "required" => ["log"], "docs" => "Add host note to core log.", "thrukcmd" => 1, 'cmdname' => 'LOG;HOST NOTE: ' },
},
'hostgroups' => {
'ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS' => {"docs" => "Enables passive checks for all services associated with hosts in a particular hostgroup."},
Expand All @@ -109,6 +110,7 @@ sub _update_cmds {
'CHANGE_NORMAL_SVC_CHECK_INTERVAL' => {"args" => ["interval"], "required" => ["interval"], "docs" => "Changes the normal (regularly scheduled) check interval for a particular service"},
'CHANGE_MAX_SVC_CHECK_ATTEMPTS' => {"args" => ["attempts"], "required" => ["attempts"], "docs" => "Changes the maximum number of check attempts (retries) for a particular service."},
'CHANGE_CUSTOM_SVC_VAR' => {"args" => ["name", "value"], "required" => ["name", "value"], "docs" => "Changes the value of a custom service variable."},
'NOTE' => {"args" => ["log"], "required" => ["log"], "docs" => "Add service note to core log.", "thrukcmd" => 1, 'cmdname' => 'LOG;SERVICE NOTE: ' },
},
'servicegroups' => {
'ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS' => {"docs" => "Enables the acceptance and processing of passive checks for all services in a particular servicegroup."},
Expand All @@ -127,6 +129,7 @@ sub _update_cmds {
'DISABLE_HOST_FRESHNESS_CHECKS' => {"docs" => "Disables freshness checks of all hosts on a program-wide basis."},
'CHANGE_GLOBAL_SVC_EVENT_HANDLER' => {"args" => ["eventhandler"], "required" => ["eventhandler"], "docs" => "Changes the global service event handler command to be that specified by the \'event_handler_command\' option. The \'event_handler_command\' option specifies the short name of the command that should be used as the new service event handler. The command must have been configured in Naemon before it was last (re)started."},
'CHANGE_GLOBAL_HOST_EVENT_HANDLER' => {"args" => ["eventhandler"], "required" => ["eventhandler"], "docs" => "Changes the global host event handler command to be that specified by the \'event_handler_command\' option. The \'event_handler_command\' option specifies the short name of the command that should be used as the new host event handler. The command must have been configured in Naemon before it was last (re)started."},
'LOG' => {"args" => ["log"], "required" => ["log"], "docs" => "Add custom log entry to core log."},
},
'all_host_service' => {
'DEL_DOWNTIME_BY_START_TIME_COMMENT' => {"args" => ["start_time", "comment"], "required" => [], "docs" => "This command deletes all downtimes matching the specified filters."},
Expand Down

0 comments on commit 8389a13

Please sign in to comment.