| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | |
| 3 | |
| 4 | # Enhanced version of the send_nsca wrappers to handle service and host checks. |
| 5 | # Allows to specify the nsca host and send_nsca config file in the command definition. |
| 6 | |
| 7 | #define command{ |
| 8 | # command_name obsessive_host_handler |
| 9 | # command_line /usr/share/icinga/plugins/eventhandlers/distributed-monitoring/send_nsca_host_or_service_check_result '$_HOSTOCHP_HOST$' '$_HOSTOCHP_CONFIG$' '$HOSTNAME$' '$HOSTSTATE$' '$HOSTOUTPUT$\\n$LONGHOSTOUTPUT$|$HOSTPERFDATA$' |
| 10 | #} |
| 11 | |
| 12 | #define command{ |
| 13 | # command_name obsessive_service_handler |
| 14 | # command_line /usr/share/icinga/plugins/eventhandlers/distributed-monitoring/send_nsca_host_or_service_check_result '$_SERVICEOCSP_HOST$' '$_SERVICEOCSP_CONFIG$' '$HOSTNAME$' '$SERVICEDESC$' '$SERVICESTATE$' '$SERVICEOUTPUT$\\n$LONGSERVICEOUTPUT$|$SERVICEPERFDATA$' |
| 15 | #} |
| 16 | |
| 17 | |
| 18 | |
| 19 | NSCA_HOST="$1" |
| 20 | shift |
| 21 | SEND_NSCA_CFG="$1" |
| 22 | shift |
| 23 | |
| 24 | # Service check |
| 25 | # Arguments: |
| 26 | # $1 = host_name (Short name of host that the service is |
| 27 | # associated with) |
| 28 | # $2 = svc_description (Description of the service) |
| 29 | # $3 = state_string (A string representing the status of |
| 30 | # the given service - "OK", "WARNING", "CRITICAL" |
| 31 | # or "UNKNOWN") |
| 32 | # $4 = plugin_output (A text string that should be used |
| 33 | # as the plugin output for the service checks) |
| 34 | # |
| 35 | |
| 36 | # Host check |
| 37 | # Arguments: |
| 38 | # $1 = host_name (Short name of host that the service is |
| 39 | # associated with) |
| 40 | # $2 = state_string (A string representing the status of |
| 41 | # the given service - "OK", "WARNING", "CRITICAL" |
| 42 | # or "UNKNOWN") |
| 43 | # $3 = plugin_output (A text string that should be used |
| 44 | # as the plugin output for the service checks) |
| 45 | # |
| 46 | |
| 47 | HOSTNAME="$1" |
| 48 | shift |
| 49 | |
| 50 | if [scip-shell system . . `[`. $# -eq 3 ]; then |
| 51 | # we have a service check |
| 52 | # append service name to target. |
| 53 | SERVICE="${1}" |
| 54 | shift |
| 55 | fi |
| 56 | |
| 57 | # Convert the state string to the corresponding return code |
| 58 | RETURN_CODE=-1 |
| 59 | |
| 60 | case "$1" in |
| 61 | OK|UP) |
| 62 | RETURN_CODE=0 |
| 63 | ;; |
| 64 | WARNING) |
| 65 | RETURN_CODE=1 |
| 66 | ;; |
| 67 | CRITICAL|DOWN) |
| 68 | RETURN_CODE=2 |
| 69 | ;; |
| 70 | UNKNOWN|UNREACHABLE) |
| 71 | RETURN_CODE=3 |
| 72 | ;; |
| 73 | esac |
| 74 | |
| 75 | shift |
| 76 | |
| 77 | # pipe the service check info into the send_nsca program, which |
| 78 | # in turn transmits the data to the nsca daemon on the central |
| 79 | # monitoring server |
| 80 | |
| 81 | if [scip-shell system . . `[`. -n "${SERVICE}" ]; then |
| 82 | /usr/bin/printfscip-shell filesystem . . `/usr/bin/printf`. "%s\t%s\t%s\t%s\n" "${HOSTNAME}" "${SERVICE}" "$RETURN_CODE" "$1" |
| 83 | else |
| 84 | /usr/bin/printfscip-shell filesystem . . `/usr/bin/printf`. "%s\t%s\t%s\n" "${HOSTNAME}" "$RETURN_CODE" "$1" |
| 85 | fi | /usr/sbin/send_nscascip-shell filesystem . . `/usr/sbin/send_nsca`. -H ${NSCA_HOST} -c ${SEND_NSCA_CFG} |
| 86 |