diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-07-01 15:35:43 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-07-08 13:29:25 +0200 |
commit | d8f933bd00a5cc416da00cd26c9d13f7a1c02486 (patch) | |
tree | 6f8773b69418463485d1196389a6c264f3cf3a6e /modules/profile/files | |
parent | 25c99a635507abfe6af4a1f0a9fc5a103d1880c0 (diff) | |
download | Puppet-d8f933bd00a5cc416da00cd26c9d13f7a1c02486.tar.gz Puppet-d8f933bd00a5cc416da00cd26c9d13f7a1c02486.tar.zst Puppet-d8f933bd00a5cc416da00cd26c9d13f7a1c02486.zip |
Add monitoring
Diffstat (limited to 'modules/profile/files')
-rw-r--r-- | modules/profile/files/monitoring/check_command | 113 | ||||
-rw-r--r-- | modules/profile/files/monitoring/check_md_raid | 32 |
2 files changed, 145 insertions, 0 deletions
diff --git a/modules/profile/files/monitoring/check_command b/modules/profile/files/monitoring/check_command new file mode 100644 index 0000000..2c7eded --- /dev/null +++ b/modules/profile/files/monitoring/check_command | |||
@@ -0,0 +1,113 @@ | |||
1 | #!/usr/bin/perl | ||
2 | |||
3 | use strict; | ||
4 | use Getopt::Std; | ||
5 | $| = 1; | ||
6 | |||
7 | my %opts; | ||
8 | getopts('hr:C:c:s:o:', \%opts); | ||
9 | |||
10 | my $STATE_OK = 0; | ||
11 | my $STATE_WARNING = 1; | ||
12 | my $STATE_CRITICAL = 2; | ||
13 | my $STATE_UNKNOWN = 3; | ||
14 | |||
15 | if ($opts{'h'} || scalar(%opts) == 0) { | ||
16 | &print_help(); | ||
17 | exit($STATE_OK); | ||
18 | } | ||
19 | |||
20 | my $command = $opts{'c'}; | ||
21 | if ($command eq '') { | ||
22 | print "You must provide a command to check.\n"; | ||
23 | exit($STATE_UNKNOWN); | ||
24 | } | ||
25 | |||
26 | my $expected_output = $opts{'o'}; | ||
27 | my $expected_status = $opts{'s'}; | ||
28 | my $other_command = $opts{'C'}; | ||
29 | |||
30 | if ($other_command eq '' and $expected_status eq '' and $expected_output eq '') { | ||
31 | $expected_status = 0; | ||
32 | } | ||
33 | |||
34 | my $cmd = $command . ' 2>&1'; | ||
35 | my $other_cmd; | ||
36 | if ($other_command ne '') { | ||
37 | $other_cmd = $other_command . ' 2>&1'; | ||
38 | } | ||
39 | |||
40 | my $run_as; | ||
41 | if ($opts{'r'}) { | ||
42 | $run_as = $opts{'r'}; | ||
43 | $cmd = "sudo -u $run_as -n $cmd"; | ||
44 | |||
45 | if ($other_command ne '') { | ||
46 | $other_cmd = "sudo -u $run_as -n $other_cmd"; | ||
47 | } | ||
48 | |||
49 | } | ||
50 | |||
51 | my $cmd_result = `$cmd`; | ||
52 | my $other_cmd_result; | ||
53 | if ($other_command ne '') { | ||
54 | $other_cmd_result = `$other_cmd`; | ||
55 | chomp($other_cmd_result); | ||
56 | } | ||
57 | |||
58 | chomp($cmd_result); | ||
59 | if ($cmd_result =~ /sudo/i) { | ||
60 | print "$command CRITICAL - No sudo right to run the command\n"; | ||
61 | exit($STATE_UNKNOWN); | ||
62 | } elsif ($expected_status ne '') { | ||
63 | if ($? != $expected_status) { | ||
64 | print "$command CRITICAL - Response status $?\n"; | ||
65 | exit($STATE_CRITICAL); | ||
66 | } else { | ||
67 | print "$command OK - Response status $?\n"; | ||
68 | exit($STATE_OK); | ||
69 | } | ||
70 | } elsif ($other_command ne '') { | ||
71 | if ($cmd_result ne $other_cmd_result) { | ||
72 | print "$command CRITICAL - Expected output not matching other command output\n"; | ||
73 | exit($STATE_CRITICAL); | ||
74 | } else { | ||
75 | print "$command OK - Expected output matching other command output\n"; | ||
76 | exit($STATE_OK); | ||
77 | } | ||
78 | } else { | ||
79 | if ($cmd_result !~ /$expected_output/) { | ||
80 | print "$command CRITICAL - Expected output not matching\n"; | ||
81 | exit($STATE_CRITICAL); | ||
82 | } else { | ||
83 | print "$command OK - Expected output matching\n"; | ||
84 | exit($STATE_OK); | ||
85 | } | ||
86 | } | ||
87 | |||
88 | sub print_help() { | ||
89 | print << "EOF"; | ||
90 | Check whether the given command responds as expected. One of -o -C or -s must be selected. | ||
91 | |||
92 | Options: | ||
93 | -h | ||
94 | Print detailed help screen | ||
95 | |||
96 | -c | ||
97 | command to run (required) | ||
98 | |||
99 | -C | ||
100 | other command to compare output | ||
101 | |||
102 | -r user | ||
103 | Run as user via sudo. | ||
104 | |||
105 | -s | ||
106 | status code to check | ||
107 | |||
108 | -o | ||
109 | output to check | ||
110 | |||
111 | EOF | ||
112 | } | ||
113 | |||
diff --git a/modules/profile/files/monitoring/check_md_raid b/modules/profile/files/monitoring/check_md_raid new file mode 100644 index 0000000..9c79a7a --- /dev/null +++ b/modules/profile/files/monitoring/check_md_raid | |||
@@ -0,0 +1,32 @@ | |||
1 | #!/bin/bash | ||
2 | # | ||
3 | # Created by Sebastian Grewe, Jammicron Technology | ||
4 | # | ||
5 | |||
6 | # Get count of raid arrays | ||
7 | RAID_DEVICES=`grep ^md -c /proc/mdstat` | ||
8 | |||
9 | # Get count of degraded arrays | ||
10 | RAID_STATUS=`grep "\[.*_.*\]" /proc/mdstat -c` | ||
11 | |||
12 | # Is an array currently recovering, get percentage of recovery | ||
13 | RAID_RECOVER=`grep recovery /proc/mdstat | awk '{print $4}'` | ||
14 | |||
15 | # Check raid status | ||
16 | # RAID recovers --> Warning | ||
17 | if [[ $RAID_RECOVER ]]; then | ||
18 | STATUS="WARNING - Checked $RAID_DEVICES arrays, recovering : $RAID_RECOVER" | ||
19 | EXIT=1 | ||
20 | # RAID ok | ||
21 | elif [[ $RAID_STATUS == "0" ]]; then | ||
22 | STATUS="OK - Checked $RAID_DEVICES arrays." | ||
23 | EXIT=0 | ||
24 | # All else critical, better save than sorry | ||
25 | else | ||
26 | STATUS="CRITICAL - Checked $RAID_DEVICES arrays, $RAID_STATUS have FAILED" | ||
27 | EXIT=2 | ||
28 | fi | ||
29 | |||
30 | # Status and quit | ||
31 | echo $STATUS | ||
32 | exit $EXIT | ||