Projet

Général

Profil

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

root / plugins / ssh / sshd_log @ e178be64

Historique | Voir | Annoter | Télécharger (4,68 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
If the "logfile" environment variable is set to "journald" the sshd
27
logs are read from journald, filtering on program "sshd". The filtering
28
may be changed using "journalctlarg".
29

    
30

    
31
Config examples for /etc/munin/plugin-conf.d/munin-node:
32

    
33
  [sshd_log]
34
      user root
35
      group root
36
      env.logfile /var/log/messages
37

    
38
Config example with journald:
39

    
40
  [sshd_log]
41
      group systemd-journal
42
      env.logfile journald
43

    
44
Config example with journald on the sshd.service unit only:
45

    
46
  [sshd_log]
47
      group systemd-journal
48
      env.logfile journald
49
      env.journalctlarg --unit=sshd.service
50

    
51
=head1 MAGIC MARKERS
52

    
53
  #%# family=auto
54
  #%# capabilities=autoconf
55

    
56
=head1 AUTHOR
57

    
58
Revision 2.0  2016/11/11 15:42:00  Thomas Riccardi
59
Revision 1.2  2010/03/19 15:03:00  pmoranga
60
Revision 1.1  2009/04/26 23:28:00  ckujau
61
Revision 1.0  2009/04/22 22:00:00  zlati
62

    
63
=cut
64

    
65

    
66
# Script parameters:
67
#
68
#       config   (required)
69
#       autoconf (optional - used by munin-config)
70

    
71

    
72
LOG=${logfile:-/var/log/secure}
73
JOURNALCTL_ARG=${journalctlarg:-_COMM=sshd}
74

    
75

    
76
if [ "$1" = "autoconf" ]; then
77
        if [ "$LOG" = "journald" ]; then
78
                if journalctl --no-pager --quiet --lines=1 "$JOURNALCTL_ARG" | read -r DUMMY; then
79
                        echo "yes"
80
                else
81
                        echo "no (journald empty log for '$JOURNALCTL_ARG' not found)"
82
                fi
83
        else
84
                if [ -r "$LOG" ]; then
85
                        echo "yes"
86
                else
87
                        echo "no (logfile '$LOG' not readable)"
88
                fi
89
        fi
90
        exit 0
91
fi
92

    
93
if [ "$1" = "config" ]; then
94

    
95
        if [ "$LOG" = "journald" ]; then
96
                TYPE=ABSOLUTE
97
        else
98
                TYPE=DERIVE
99
        fi
100

    
101
        echo 'graph_title SSHD login stats from' "$LOG"
102
        echo 'graph_args --base 1000 -l 0'
103
        echo 'graph_vlabel logins'
104
        echo 'graph_category' security
105

    
106
        echo 'LogPass.label Successful password logins'
107
        echo 'LogPass.min 0'
108
        echo 'LogPass.type' "$TYPE"
109

    
110
        echo 'LogPassPAM.label Successful login via PAM'
111
        echo 'LogPassPAM.min 0'
112
        echo 'LogPassPAM.type' "$TYPE"
113

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

    
118
        echo 'NoID.label No identification from user'
119
        echo 'NoID.min 0'
120
        echo 'NoID.type' "$TYPE"
121

    
122
        echo 'rootAttempt.label Root login attempts'
123
        echo 'rootAttempt.min 0'
124
        echo 'rootAttempt.type' "$TYPE"
125

    
126
        echo 'InvUsr.label Invalid user login attempts'
127
        echo 'InvUsr.min 0'
128
        echo 'InvUsr.type' "$TYPE"
129

    
130
        echo 'NoRDNS.label No reverse DNS for peer'
131
        echo 'NoRDNS.min 0'
132
        echo 'NoRDNS.type' "$TYPE"
133

    
134
        echo 'Breakin.label Potential Breakin Attempts'
135
        echo 'Breakin.min 0'
136
        echo 'Breakin.type' "$TYPE"
137

    
138
        exit 0
139
fi
140

    
141
if [ "$LOG" = "journald" ]; then
142
        CURSOR_FILE="$MUNIN_STATEFILE"
143
        # read cursor
144
        # format: "journald-cursor <cursor>"
145
        CURSOR=
146
        if [ -f "$CURSOR_FILE" ]; then
147
                CURSOR=$(awk '/^journald-cursor / {print $2}' "$CURSOR_FILE")
148
        fi
149
else
150
        CURSOR_FILE=
151
fi
152

    
153
if [ "$LOG" = "journald" ]; then
154
        journalctl --no-pager --quiet --show-cursor ${CURSOR:+"--after-cursor=$CURSOR"} "$JOURNALCTL_ARG"
155
else
156
        cat "$LOG"
157
fi | \
158
    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; }
159
     /sshd\[.*Accepted password for/{c["LogPass"]++}
160
     /sshd\[.*Accepted publickey for/{c["LogKey"]++}
161
     /sshd\[.*Did not receive identification string/{c["NoID"]++}
162
     /sshd\[.*Failed password for root/{c["rootAttempt"]++}
163
     /sshd\[.*Invalid user/{c["InvUsr"]++}
164
     /sshd\[.*POSSIBLE BREAK-IN ATTEMPT!/{c["Breakin"]++}
165
     /sshd\[.*keyboard-interactive\/pam/{c["LogPassPAM"]++}
166
     /sshd\[.*reverse mapping checking getaddrinfo/{c["NoRDNS"]++}a
167
     END{if (cursor_file != "") { print "journald-cursor " $3 > cursor_file };for(i in c){print i".value " c[i]} }'