root / plugins / ssh / sshd_log @ 17f78427
Historique | Voir | Annoter | Télécharger (5,13 ko)
| 1 | 4ab213e1 | Artem Sheremet | #!/bin/sh |
|---|---|---|---|
| 2 | 26181ead | Thomas Riccardi | |
| 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 | 8f68d6e6 | Thomas Riccardi | type - "GAUGE" or "DERIVE" |
| 27 | default: GAUGE |
||
| 28 | |||
| 29 | 26181ead | Thomas Riccardi | If the "logfile" environment variable is set to "journald" the sshd |
| 30 | logs are read from journald, filtering on program "sshd". The filtering |
||
| 31 | cdb82255 | Thomas Riccardi | may be changed using "journalctlargs". |
| 32 | 26181ead | Thomas Riccardi | |
| 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 | cdb82255 | Thomas Riccardi | env.journalctlargs --unit=sshd.service |
| 53 | 26181ead | Thomas Riccardi | |
| 54 | 8f68d6e6 | Thomas Riccardi | 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 | 26181ead | Thomas Riccardi | =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 | 4ab213e1 | Artem Sheremet | # |
| 78 | # config (required) |
||
| 79 | # autoconf (optional - used by munin-config) |
||
| 80 | 26181ead | Thomas Riccardi | |
| 81 | 4ab213e1 | Artem Sheremet | |
| 82 | LOG=${logfile:-/var/log/secure}
|
||
| 83 | cdb82255 | Thomas Riccardi | JOURNALCTL_ARGS=${journalctlargs:-_COMM=sshd}
|
| 84 | 8f68d6e6 | Thomas Riccardi | TYPE=${type:-GAUGE}
|
| 85 | if [ "$LOG" = "journald" -a "$TYPE" = "DERIVE" ]; then |
||
| 86 | TYPE=ABSOLUTE |
||
| 87 | fi |
||
| 88 | 4ab213e1 | Artem Sheremet | |
| 89 | |||
| 90 | if [ "$1" = "autoconf" ]; then |
||
| 91 | e6a18b5a | Thomas Riccardi | if [ "$LOG" = "journald" ]; then |
| 92 | cdb82255 | Thomas Riccardi | # shellcheck disable=SC2086,SC2034 |
| 93 | if journalctl --no-pager --quiet --lines=1 $JOURNALCTL_ARGS | read -r DUMMY; then |
||
| 94 | ff68f641 | Thomas Riccardi | echo "yes" |
| 95 | e6a18b5a | Thomas Riccardi | else |
| 96 | cdb82255 | Thomas Riccardi | echo "no (journald empty log for '$JOURNALCTL_ARGS' not found)" |
| 97 | e6a18b5a | Thomas Riccardi | fi |
| 98 | 4ab213e1 | Artem Sheremet | else |
| 99 | e6a18b5a | Thomas Riccardi | if [ -r "$LOG" ]; then |
| 100 | ff68f641 | Thomas Riccardi | echo "yes" |
| 101 | e6a18b5a | Thomas Riccardi | else |
| 102 | ff68f641 | Thomas Riccardi | echo "no (logfile '$LOG' not readable)" |
| 103 | e6a18b5a | Thomas Riccardi | fi |
| 104 | 4ab213e1 | Artem Sheremet | fi |
| 105 | ff68f641 | Thomas Riccardi | exit 0 |
| 106 | 4ab213e1 | Artem Sheremet | fi |
| 107 | |||
| 108 | if [ "$1" = "config" ]; then |
||
| 109 | c04acf95 | Thomas Riccardi | echo 'graph_title SSHD login stats from' "$LOG" |
| 110 | 4ab213e1 | Artem Sheremet | echo 'graph_args --base 1000 -l 0' |
| 111 | echo 'graph_vlabel logins' |
||
| 112 | 3a6fdce8 | dipohl | echo 'graph_category' security |
| 113 | 4ab213e1 | Artem Sheremet | |
| 114 | echo 'LogPass.label Successful password logins' |
||
| 115 | e6a18b5a | Thomas Riccardi | echo 'LogPass.min 0' |
| 116 | echo 'LogPass.type' "$TYPE" |
||
| 117 | |||
| 118 | 4ab213e1 | Artem Sheremet | echo 'LogPassPAM.label Successful login via PAM' |
| 119 | e6a18b5a | Thomas Riccardi | echo 'LogPassPAM.min 0' |
| 120 | echo 'LogPassPAM.type' "$TYPE" |
||
| 121 | |||
| 122 | 4ab213e1 | Artem Sheremet | echo 'LogKey.label Successful PublicKey logins' |
| 123 | e6a18b5a | Thomas Riccardi | echo 'LogKey.min 0' |
| 124 | echo 'LogKey.type' "$TYPE" |
||
| 125 | |||
| 126 | 4ab213e1 | Artem Sheremet | echo 'NoID.label No identification from user' |
| 127 | e6a18b5a | Thomas Riccardi | echo 'NoID.min 0' |
| 128 | echo 'NoID.type' "$TYPE" |
||
| 129 | |||
| 130 | 4ab213e1 | Artem Sheremet | echo 'rootAttempt.label Root login attempts' |
| 131 | e6a18b5a | Thomas Riccardi | echo 'rootAttempt.min 0' |
| 132 | echo 'rootAttempt.type' "$TYPE" |
||
| 133 | |||
| 134 | e178be64 | Thomas Riccardi | echo 'InvUsr.label Invalid user login attempts' |
| 135 | e6a18b5a | Thomas Riccardi | echo 'InvUsr.min 0' |
| 136 | echo 'InvUsr.type' "$TYPE" |
||
| 137 | |||
| 138 | 4ab213e1 | Artem Sheremet | echo 'NoRDNS.label No reverse DNS for peer' |
| 139 | e6a18b5a | Thomas Riccardi | echo 'NoRDNS.min 0' |
| 140 | echo 'NoRDNS.type' "$TYPE" |
||
| 141 | |||
| 142 | 4ab213e1 | Artem Sheremet | echo 'Breakin.label Potential Breakin Attempts' |
| 143 | e6a18b5a | Thomas Riccardi | echo 'Breakin.min 0' |
| 144 | echo 'Breakin.type' "$TYPE" |
||
| 145 | |||
| 146 | 4ab213e1 | Artem Sheremet | exit 0 |
| 147 | fi |
||
| 148 | |||
| 149 | 8f68d6e6 | Thomas Riccardi | if [ "$LOG" = "journald" -a "$TYPE" = "ABSOLUTE" ]; then |
| 150 | e6a18b5a | Thomas Riccardi | 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 | cdb82255 | Thomas Riccardi | # shellcheck disable=SC2086 |
| 163 | 8f68d6e6 | Thomas Riccardi | 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 | e6a18b5a | Thomas Riccardi | else |
| 169 | c04acf95 | Thomas Riccardi | cat "$LOG" |
| 170 | e6a18b5a | Thomas Riccardi | 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 | 4ab213e1 | Artem Sheremet | /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 | e6a18b5a | Thomas Riccardi | END{if (cursor_file != "") { print "journald-cursor " $3 > cursor_file };for(i in c){print i".value " c[i]} }' |
