Projet

Général

Profil

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

root / plugins / ssh / sshd_log @ 17f78427

Historique | Voir | Annoter | Télécharger (5,13 ko)

1
#!/bin/sh
2

    
3
: <<=cut
4

    
5
=head1 NAME
6

    
7
sshd_log - Munin plugin to monitor auth.log or journald for sshd
8
           server events.
9

    
10
=head1 CONFIGURATION
11

    
12
This plugin requires read permission for the logfile or journald.
13

    
14
On busy servers you can change value type to COUNTER and set min to 0
15
to avoid minus peaks at logrotate.
16

    
17
The following environment variables are used by this plugin:
18

    
19
 logfile  - path to the auth log file, or "journald" to use journald.
20
            default: /var/log/secure
21

    
22
 journalctlargs - space separated list of arguments to pass to
23
                  journalctl to get the sshd logs.
24
                  default: _COMM=sshd
25

    
26
 type - "GAUGE" or "DERIVE"
27
         default: GAUGE
28

    
29
If the "logfile" environment variable is set to "journald" the sshd
30
logs are read from journald, filtering on program "sshd". The filtering
31
may be changed using "journalctlargs".
32

    
33

    
34
Config examples for /etc/munin/plugin-conf.d/munin-node:
35

    
36
  [sshd_log]
37
      user root
38
      group root
39
      env.logfile /var/log/messages
40

    
41
Config example with journald:
42

    
43
  [sshd_log]
44
      group systemd-journal
45
      env.logfile journald
46

    
47
Config example with journald on the sshd.service unit only:
48

    
49
  [sshd_log]
50
      group systemd-journal
51
      env.logfile journald
52
      env.journalctlargs --unit=sshd.service
53

    
54
Config example with journald and type DERIVE:
55

    
56
  [sshd_log]
57
      group systemd-journal
58
      env.logfile journald
59
      env.type DERIVE
60

    
61
=head1 MAGIC MARKERS
62

    
63
  #%# family=auto
64
  #%# capabilities=autoconf
65

    
66
=head1 AUTHOR
67

    
68
Revision 2.0  2016/11/11 15:42:00  Thomas Riccardi
69
Revision 1.2  2010/03/19 15:03:00  pmoranga
70
Revision 1.1  2009/04/26 23:28:00  ckujau
71
Revision 1.0  2009/04/22 22:00:00  zlati
72

    
73
=cut
74

    
75

    
76
# Script parameters:
77
#
78
#       config   (required)
79
#       autoconf (optional - used by munin-config)
80

    
81

    
82
LOG=${logfile:-/var/log/secure}
83
JOURNALCTL_ARGS=${journalctlargs:-_COMM=sshd}
84
TYPE=${type:-GAUGE}
85
if [ "$LOG" = "journald" -a "$TYPE" = "DERIVE" ]; then
86
        TYPE=ABSOLUTE
87
fi
88

    
89

    
90
if [ "$1" = "autoconf" ]; then
91
        if [ "$LOG" = "journald" ]; then
92
                # shellcheck disable=SC2086,SC2034
93
                if journalctl --no-pager --quiet --lines=1 $JOURNALCTL_ARGS | read -r DUMMY; then
94
                        echo "yes"
95
                else
96
                        echo "no (journald empty log for '$JOURNALCTL_ARGS' not found)"
97
                fi
98
        else
99
                if [ -r "$LOG" ]; then
100
                        echo "yes"
101
                else
102
                        echo "no (logfile '$LOG' not readable)"
103
                fi
104
        fi
105
        exit 0
106
fi
107

    
108
if [ "$1" = "config" ]; then
109
        echo 'graph_title SSHD login stats from' "$LOG"
110
        echo 'graph_args --base 1000 -l 0'
111
        echo 'graph_vlabel logins'
112
        echo 'graph_category' security
113

    
114
        echo 'LogPass.label Successful password logins'
115
        echo 'LogPass.min 0'
116
        echo 'LogPass.type' "$TYPE"
117

    
118
        echo 'LogPassPAM.label Successful login via PAM'
119
        echo 'LogPassPAM.min 0'
120
        echo 'LogPassPAM.type' "$TYPE"
121

    
122
        echo 'LogKey.label Successful PublicKey logins'
123
        echo 'LogKey.min 0'
124
        echo 'LogKey.type' "$TYPE"
125

    
126
        echo 'NoID.label No identification from user'
127
        echo 'NoID.min 0'
128
        echo 'NoID.type' "$TYPE"
129

    
130
        echo 'rootAttempt.label Root login attempts'
131
        echo 'rootAttempt.min 0'
132
        echo 'rootAttempt.type' "$TYPE"
133

    
134
        echo 'InvUsr.label Invalid user login attempts'
135
        echo 'InvUsr.min 0'
136
        echo 'InvUsr.type' "$TYPE"
137

    
138
        echo 'NoRDNS.label No reverse DNS for peer'
139
        echo 'NoRDNS.min 0'
140
        echo 'NoRDNS.type' "$TYPE"
141

    
142
        echo 'Breakin.label Potential Breakin Attempts'
143
        echo 'Breakin.min 0'
144
        echo 'Breakin.type' "$TYPE"
145

    
146
        exit 0
147
fi
148

    
149
if [ "$LOG" = "journald" -a "$TYPE" = "ABSOLUTE" ]; then
150
        CURSOR_FILE="$MUNIN_STATEFILE"
151
        # read cursor
152
        # format: "journald-cursor <cursor>"
153
        CURSOR=
154
        if [ -f "$CURSOR_FILE" ]; then
155
                CURSOR=$(awk '/^journald-cursor / {print $2}' "$CURSOR_FILE")
156
        fi
157
else
158
        CURSOR_FILE=
159
fi
160

    
161
if [ "$LOG" = "journald" ]; then
162
        # shellcheck disable=SC2086
163
        if [ "$TYPE" = "ABSOLUTE" ]; then
164
                journalctl --no-pager --quiet --show-cursor ${CURSOR:+"--after-cursor=$CURSOR"} $JOURNALCTL_ARGS
165
        else
166
                journalctl --no-pager --quiet --since=$(date -dlast-sunday +%Y-%m-%d) $JOURNALCTL_ARGS
167
        fi
168
else
169
        cat "$LOG"
170
fi | \
171
    awk -v cursor_file="$CURSOR_FILE" 'BEGIN{c["LogPass"]=0;c["LogKey"]=0;c["NoID"]=0;c["rootAttempt"]=0;c["InvUsr"]=0;c["LogPassPAM"]=0;c["Breakin"]=0;c["NoRDNS"]=0; }
172
     /sshd\[.*Accepted password for/{c["LogPass"]++}
173
     /sshd\[.*Accepted publickey for/{c["LogKey"]++}
174
     /sshd\[.*Did not receive identification string/{c["NoID"]++}
175
     /sshd\[.*Failed password for root/{c["rootAttempt"]++}
176
     /sshd\[.*Invalid user/{c["InvUsr"]++}
177
     /sshd\[.*POSSIBLE BREAK-IN ATTEMPT!/{c["Breakin"]++}
178
     /sshd\[.*keyboard-interactive\/pam/{c["LogPassPAM"]++}
179
     /sshd\[.*reverse mapping checking getaddrinfo/{c["NoRDNS"]++}a
180
     END{if (cursor_file != "") { print "journald-cursor " $3 > cursor_file };for(i in c){print i".value " c[i]} }'