Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / icinga / icinga_checks @ 743395a6

Historique | Voir | Annoter | Télécharger (3,21 ko)

1 5633f925 mafri
#!/bin/sh
2
3
: << =cut
4
=head1 NAME
5
6
icinga_checks - Plugin to monitor results of icinga monitoring
7
8
=head1 CONFIGURATION
9
10
No configuration
11
12 743395a6 Lars Kruse
=head1 AUTHORS
13 5633f925 mafri
14 743395a6 Lars Kruse
Copyright (C) 2019 mafri (with help from sumpfralle and ndo84bw)
15 5633f925 mafri
16
=head1 LICENSE
17
18 743395a6 Lars Kruse
GNU General Public License v3.0 only
19
20
SPDX-License-Identifier: GPL-3.0-only
21 5633f925 mafri
22
=head1 MAGIC MARKERS
23
24
 #%# family=auto
25
 #%# capabilities=autoconf
26
27
=cut
28
29
ICINGACLI=${ICINGACLI:-$(command -v icingacli)}
30
JQ=${JQ:-$(command -v  jq)}
31
32
33
if [ "$1" = "autoconf" ] ; then
34
    if [ ! -x "$ICINGACLI" ]; then
35
        echo "no (could not find 'icingacli')"
36
    elif [ ! -x "$JQ" ]; then
37
        echo "no (could not find 'jq')"
38
    else
39
        echo "yes"
40
    fi
41
    exit
42
fi
43
44
set -e
45
46
if [ "$1" = "config" ]; then
47
48
    echo "multigraph icinga_host_checks"
49
    echo "graph_title Icinga Host Checks"
50
    echo 'graph_args --base 1000'
51
    echo 'graph_vlabel Count'
52
    echo 'graph_category icinga'
53
    echo "up.label Up"
54
    echo "down.label Down"
55
    echo "unreachable.label Unreachable"
56
    echo "pending.label Pending"
57
    echo "up.draw AREA"    
58
    echo "down.draw STACK"
59
    echo "unreachable.draw STACK"
60
    echo "pending.draw STACK"
61
62
63
    echo "multigraph icinga_service_checks"
64
    echo "graph_title Icinga Service Checks"
65
    echo 'graph_args --base 1000'
66
    echo 'graph_vlabel Count'
67
    echo 'graph_category icinga'
68
    echo "ok.label Ok"
69
    echo "warning.label Warning"
70
    echo "critical.label Critical"
71
    echo "unknown.label Unknown"
72
    echo "pending.label Pending"
73
    echo "ok.draw AREA"
74
    echo "warning.draw STACK"
75
    echo "critical.draw STACK"
76
    echo "unknown.draw STACK"
77
    echo "pending.draw STACK"
78
79
    exit
80
fi
81
82
if [ ! -x "$ICINGACLI" ]; then
83
    echo "could not find 'icingacli'" >&2
84
    exit 1
85
elif [ ! -x "$JQ" ]; then
86
    echo "could not find 'jq'" >&2
87
    exit 1
88
fi
89
90
output=$("$ICINGACLI" monitoring list hosts --format=json)
91
host_up=$(    echo "$output" | "$JQ" -r '.[] | select(.host_state == 0) | .host_name'  | wc -l )
92
host_down=$(  echo "$output" | "$JQ" -r '.[] | select(.host_state == 1) | .host_name'  | wc -l )
93
host_pend=$(  echo "$output" | "$JQ" -r '.[] | select(.host_state == 2) | .host_name'  | wc -l )
94
host_unre=$(  echo "$output" | "$JQ" -r '.[] | select(.host_state == 3) | .host_name'  | wc -l )
95
96
echo "multigraph icinga_host_checks"
97
echo "up.value $host_up"
98
echo "down.value $host_down"
99
echo "pending.value $host_pend"
100
echo "unreachable.value $host_unre"
101
102
output=$("$ICINGACLI" monitoring list services --format=json)
103
service_ok=$(  echo "$output" | "$JQ" -r '.[] | select(.service_state == 0) | .host_name + .service_name'  | wc -l )
104
service_warn=$(echo "$output" | "$JQ" -r '.[] | select(.service_state == 1) | .host_name + .service_name'  | wc -l )
105
service_crit=$(echo "$output" | "$JQ" -r '.[] | select(.service_state == 2) | .host_name + .service_name'  | wc -l )
106
service_pend=$(echo "$output" | "$JQ" -r '.[] | select(.service_state == 3) | .host_name + .service_name'  | wc -l )
107
service_unkn=$(echo "$output" | "$JQ" -r '.[] | select(.service_state == 4) | .host_name + .service_name'  | wc -l )
108
109
echo "multigraph icinga_service_checks"
110
echo "ok.value $service_ok"
111
echo "warning.value $service_warn"
112
echo "critical.value $service_crit"
113
echo "unknown.value $service_unkn"
114
echo "pending.value $service_pend"