[PATCH] commands: Keep return values around for external commands and log errors

Anton Löfgren alofgren at op5.com
Mon Jun 3 08:54:50 CEST 2013


This patch does not significantly alter program flow. It simply allows us
to log errors encountered from attempted execution of external commands,
which presumably is a good thing.

Signed-off-by: Anton Lofgren <alofgren at op5.com>
---
 base/commands.c | 69 +++++++++++++++++++++++++++++++--------------------------
 1 file changed, 37 insertions(+), 32 deletions(-)

diff --git a/base/commands.c b/base/commands.c
index d0f65f7..363fc06 100644
--- a/base/commands.c
+++ b/base/commands.c
@@ -359,6 +359,7 @@ int process_external_command1(char *cmd) {
  time_t entry_time = 0L;
  int command_type = CMD_NONE;
  char *temp_ptr = NULL;
+ int external_command_ret = OK;

  log_debug_info(DEBUGL_FUNCTIONS, 0, "process_external_command1()\n");

@@ -877,7 +878,10 @@ int process_external_command1(char *cmd) {
 #endif

  /* process the command */
- process_external_command2(command_type, entry_time, args);
+ if ((external_command_ret = process_external_command2(command_type,
entry_time, args)) != OK) {
+ logit(NSLOG_EXTERNAL_COMMAND | NSLOG_RUNTIME_WARNING, TRUE, "Error:
External command failed -> %s;%s\n", command_id, args);
+ }
+

 #ifdef USE_EVENT_BROKER
  /* send data to event broker */
@@ -888,7 +892,7 @@ int process_external_command1(char *cmd) {
  my_free(command_id);
  my_free(args);

- return OK;
+ return external_command_ret;
  }


@@ -896,6 +900,7 @@ int process_external_command1(char *cmd) {
 /* top-level processor for a single external command */
 int process_external_command2(int cmd, time_t entry_time, char *args) {

+ int ret = OK;
  log_debug_info(DEBUGL_FUNCTIONS, 0, "process_external_command2()\n");

  log_debug_info(DEBUGL_EXTERNALCOMMANDS, 1, "External Command Type:
%d\n", cmd);
@@ -911,15 +916,15 @@ int process_external_command2(int cmd, time_t
entry_time, char *args) {

  case CMD_SHUTDOWN_PROCESS:
  case CMD_RESTART_PROCESS:
- cmd_signal_process(cmd, args);
+ ret = cmd_signal_process(cmd, args);
  break;

  case CMD_SAVE_STATE_INFORMATION:
- save_state_information(FALSE);
+ ret = save_state_information(FALSE);
  break;

  case CMD_READ_STATE_INFORMATION:
- read_initial_state_information();
+ ret = read_initial_state_information();
  break;

  case CMD_ENABLE_NOTIFICATIONS:
@@ -1045,7 +1050,7 @@ int process_external_command2(int cmd, time_t
entry_time, char *args) {
  case CMD_STOP_OBSESSING_OVER_HOST:
  case CMD_SET_HOST_NOTIFICATION_NUMBER:
  case CMD_SEND_CUSTOM_HOST_NOTIFICATION:
- process_host_command(cmd, entry_time, args);
+ ret = process_host_command(cmd, entry_time, args);
  break;


@@ -1065,7 +1070,7 @@ int process_external_command2(int cmd, time_t
entry_time, char *args) {
  case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
  case CMD_ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS:
  case CMD_DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS:
- process_hostgroup_command(cmd, entry_time, args);
+ ret = process_hostgroup_command(cmd, entry_time, args);
  break;


@@ -1087,7 +1092,7 @@ int process_external_command2(int cmd, time_t
entry_time, char *args) {
  case CMD_STOP_OBSESSING_OVER_SVC:
  case CMD_SET_SVC_NOTIFICATION_NUMBER:
  case CMD_SEND_CUSTOM_SVC_NOTIFICATION:
- process_service_command(cmd, entry_time, args);
+ ret = process_service_command(cmd, entry_time, args);
  break;


@@ -1107,7 +1112,7 @@ int process_external_command2(int cmd, time_t
entry_time, char *args) {
  case CMD_DISABLE_SERVICEGROUP_SVC_CHECKS:
  case CMD_ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS:
  case CMD_DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS:
- process_servicegroup_command(cmd, entry_time, args);
+ ret = process_servicegroup_command(cmd, entry_time, args);
  break;


@@ -1119,7 +1124,7 @@ int process_external_command2(int cmd, time_t
entry_time, char *args) {
  case CMD_DISABLE_CONTACT_HOST_NOTIFICATIONS:
  case CMD_ENABLE_CONTACT_SVC_NOTIFICATIONS:
  case CMD_DISABLE_CONTACT_SVC_NOTIFICATIONS:
- process_contact_command(cmd, entry_time, args);
+ ret = process_contact_command(cmd, entry_time, args);
  break;


@@ -1131,7 +1136,7 @@ int process_external_command2(int cmd, time_t
entry_time, char *args) {
  case CMD_DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS:
  case CMD_ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS:
  case CMD_DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS:
- process_contactgroup_command(cmd, entry_time, args);
+ ret = process_contactgroup_command(cmd, entry_time, args);
  break;


@@ -1142,50 +1147,50 @@ int process_external_command2(int cmd, time_t
entry_time, char *args) {

  case CMD_ADD_HOST_COMMENT:
  case CMD_ADD_SVC_COMMENT:
- cmd_add_comment(cmd, entry_time, args);
+ ret= cmd_add_comment(cmd, entry_time, args);
  break;

  case CMD_DEL_HOST_COMMENT:
  case CMD_DEL_SVC_COMMENT:
- cmd_delete_comment(cmd, args);
+ ret = cmd_delete_comment(cmd, args);
  break;

  case CMD_DELAY_HOST_NOTIFICATION:
  case CMD_DELAY_SVC_NOTIFICATION:
- cmd_delay_notification(cmd, args);
+ ret = cmd_delay_notification(cmd, args);
  break;

  case CMD_SCHEDULE_SVC_CHECK:
  case CMD_SCHEDULE_FORCED_SVC_CHECK:
- cmd_schedule_check(cmd, args);
+ ret =cmd_schedule_check(cmd, args);
  break;

  case CMD_SCHEDULE_HOST_SVC_CHECKS:
  case CMD_SCHEDULE_FORCED_HOST_SVC_CHECKS:
- cmd_schedule_check(cmd, args);
+ ret = cmd_schedule_check(cmd, args);
  break;

  case CMD_DEL_ALL_HOST_COMMENTS:
  case CMD_DEL_ALL_SVC_COMMENTS:
- cmd_delete_all_comments(cmd, args);
+ ret = cmd_delete_all_comments(cmd, args);
  break;

  case CMD_PROCESS_SERVICE_CHECK_RESULT:
- cmd_process_service_check_result(cmd, entry_time, args);
+ ret = cmd_process_service_check_result(cmd, entry_time, args);
  break;

  case CMD_PROCESS_HOST_CHECK_RESULT:
- cmd_process_host_check_result(cmd, entry_time, args);
+ ret = cmd_process_host_check_result(cmd, entry_time, args);
  break;

  case CMD_ACKNOWLEDGE_HOST_PROBLEM:
  case CMD_ACKNOWLEDGE_SVC_PROBLEM:
- cmd_acknowledge_problem(cmd, args);
+ ret = cmd_acknowledge_problem(cmd, args);
  break;

  case CMD_REMOVE_HOST_ACKNOWLEDGEMENT:
  case CMD_REMOVE_SVC_ACKNOWLEDGEMENT:
- cmd_remove_acknowledgement(cmd, args);
+ ret = cmd_remove_acknowledgement(cmd, args);
  break;

  case CMD_SCHEDULE_HOST_DOWNTIME:
@@ -1197,29 +1202,29 @@ int process_external_command2(int cmd, time_t
entry_time, char *args) {
  case CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME:
  case CMD_SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME:
  case CMD_SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME:
- cmd_schedule_downtime(cmd, entry_time, args);
+ ret = cmd_schedule_downtime(cmd, entry_time, args);
  break;

  case CMD_DEL_HOST_DOWNTIME:
  case CMD_DEL_SVC_DOWNTIME:
- cmd_delete_downtime(cmd, args);
+ ret = cmd_delete_downtime(cmd, args);
  break;

  case CMD_DEL_DOWNTIME_BY_HOST_NAME:
- cmd_delete_downtime_by_host_name(cmd, args);
+ ret = cmd_delete_downtime_by_host_name(cmd, args);
  break;

  case CMD_DEL_DOWNTIME_BY_HOSTGROUP_NAME:
- cmd_delete_downtime_by_hostgroup_name(cmd, args);
+ ret = cmd_delete_downtime_by_hostgroup_name(cmd, args);
  break;

  case CMD_DEL_DOWNTIME_BY_START_TIME_COMMENT:
- cmd_delete_downtime_by_start_time_comment(cmd, args);
+ ret = cmd_delete_downtime_by_start_time_comment(cmd, args);
  break;

  case CMD_SCHEDULE_HOST_CHECK:
  case CMD_SCHEDULE_FORCED_HOST_CHECK:
- cmd_schedule_check(cmd, args);
+ ret = cmd_schedule_check(cmd, args);
  break;

  case CMD_CHANGE_GLOBAL_HOST_EVENT_HANDLER:
@@ -1234,7 +1239,7 @@ int process_external_command2(int cmd, time_t
entry_time, char *args) {
  case CMD_CHANGE_SVC_NOTIFICATION_TIMEPERIOD:
  case CMD_CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD:
  case CMD_CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD:
- cmd_change_object_char_var(cmd, args);
+ ret = cmd_change_object_char_var(cmd, args);
  break;

  case CMD_CHANGE_NORMAL_HOST_CHECK_INTERVAL:
@@ -1248,13 +1253,13 @@ int process_external_command2(int cmd, time_t
entry_time, char *args) {
  case CMD_CHANGE_CONTACT_MODATTR:
  case CMD_CHANGE_CONTACT_MODHATTR:
  case CMD_CHANGE_CONTACT_MODSATTR:
- cmd_change_object_int_var(cmd, args);
+ ret = cmd_change_object_int_var(cmd, args);
  break;

  case CMD_CHANGE_CUSTOM_HOST_VAR:
  case CMD_CHANGE_CUSTOM_SVC_VAR:
  case CMD_CHANGE_CUSTOM_CONTACT_VAR:
- cmd_change_object_custom_var(cmd, args);
+ ret = cmd_change_object_custom_var(cmd, args);
  break;


@@ -1264,7 +1269,7 @@ int process_external_command2(int cmd, time_t
entry_time, char *args) {


  case CMD_PROCESS_FILE:
- cmd_process_external_commands_from_file(cmd, args);
+ ret = cmd_process_external_commands_from_file(cmd, args);
  break;


@@ -1282,7 +1287,7 @@ int process_external_command2(int cmd, time_t
entry_time, char *args) {
  break;
  }

- return OK;
+ return ret;
  }


--
1.8.3

------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite
It's a free troubleshooting tool designed for production
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap2




More information about the Developers mailing list