]> granicus.if.org Git - icinga2/blob - test/externalcommands/process_check_result
Add docu for icinga2-build-key and icinga2-build-ca.
[icinga2] / test / externalcommands / process_check_result
1 #!/bin/sh
2
3 #/******************************************************************************
4 # * Icinga 2                                                                   *
5 # * Copyright (C) 2012-2013 Icinga Development Team (http://www.icinga.org/)   *
6 # *                                                                            *
7 # * This program is free software; you can redistribute it and/or              *
8 # * modify it under the terms of the GNU General Public License                *
9 # * as published by the Free Software Foundation; either version 2             *
10 # * of the License, or (at your option) any later version.                     *
11 # *                                                                            *
12 # * This program is distributed in the hope that it will be useful,            *
13 # * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
14 # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
15 # * GNU General Public License for more details.                               *
16 # *                                                                            *
17 # * You should have received a copy of the GNU General Public License          *
18 # * along with this program; if not, write to the Free Software Foundation     *
19 # * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
20 # ******************************************************************************/
21 usage(){
22 cat << EOF
23 usage: $0 options
24  This script sends check results to an icinga(2) cmd pipe.
25  OPTIONS:
26     -h        Show this message
27     -c        External command pipe file path, e.g. '/var/run/icinga2/icinga2.cmd'
28     -H        Host name for the check result
29     -S        Service name for the check result. If not provided, a host check result is assumed.
30     -r        Return code of the check result
31     -o        Output of the checkresult
32 EOF
33 }
34
35
36 ECHO="/bin/echo"
37 CMDFILE="/var/run/icinga2/cmd/icinga2.cmd"
38 HOST=""
39 SERVICE=""
40 RETURNCODE=0
41 OUTPUT="icinga2 extcmdfile test @ `date +%s`"
42
43 while getopts ":c:H:S:r:o:h" opt; do
44   case $opt in
45     h)
46       usage
47       exit 1
48       ;;
49     c)
50       CMDFILE=$OPTARG
51       ;;
52     H)
53       HOST=$OPTARG
54       ;;
55     S)
56       SERVICE=$OPTARG
57       ;;
58     r)
59       RETURNCODE=$OPTARG
60       ;;
61     o)
62       OUTPUT=$OPTARG
63       ;;
64     \?)
65       echo "Invalid option: -$OPTARG" >&2
66       usage
67       exit 1
68       ;;
69     :)
70       echo "Option -$OPTARG requires an argument." >&2
71       usage
72       exit 1
73       ;;
74   esac
75 done
76
77 DATETIME=`date +%s`
78
79 if [ -z "$HOST" ]; then
80   echo "Host name missing. Please use -H with a valid host name."
81   usage
82   exit 1;
83 fi
84
85 if [ -z "$SERVICE" ]; then
86   CMDLINE="[$DATETIME] PROCESS_HOST_CHECK_RESULT;$HOST;$RETURNCODE;$OUTPUT"
87 else
88   CMDLINE="[$DATETIME] PROCESS_SERVICE_CHECK_RESULT;$HOST;$SERVICE;$RETURNCODE;$OUTPUT"
89 fi
90
91 echo "Sending '$ECHO $CMDLINE >> $CMDFILE'"
92 `$ECHO $CMDLINE >> $CMDFILE`
93
94 exit 0