Révision b315a1c8
Improve vsftpd plugin
- Allow log file path to be configured via plugin-conf.d env.logfile
- Add counters for successful and failed renames
- Switch to use DERIVE and min 0 to fix problems during rotation and show request counts per period
- Improve performance for large log files by using awk
| plugins/ftp/vsftpd | ||
|---|---|---|
| 1 |
LOGFILE=/var/log/vsftpd.log |
|
| 1 |
#!/bin/bash |
|
| 2 |
|
|
| 3 |
logfile=${logfile:-/var/log/vsftpd.log}
|
|
| 2 | 4 |
|
| 3 | 5 |
if [ "$1" = "autoconf" ]; then |
| 4 |
if [ -f "${LOGFILE}" ]; then
|
|
| 5 |
echo yes
|
|
| 6 |
exit 0 |
|
| 7 |
else
|
|
| 8 |
echo no
|
|
| 9 |
exit 1 |
|
| 10 |
fi
|
|
| 6 |
if [ -f "${logfile}" ]; then
|
|
| 7 |
echo yes
|
|
| 8 |
exit 0
|
|
| 9 |
else
|
|
| 10 |
echo no
|
|
| 11 |
exit 1
|
|
| 12 |
fi
|
|
| 11 | 13 |
fi |
| 12 | 14 |
|
| 13 | 15 |
if [ "$1" = "config" ]; then |
| 14 |
echo 'graph_title FTP Server' |
|
| 15 |
echo 'graph_args --base 1000 -l 0' |
|
| 16 |
echo 'graph_vlabel Requests' |
|
| 17 |
echo 'graph_category FTP' |
|
| 18 |
echo 'ftp_c.label connections' |
|
| 19 |
echo 'ftp_sl.label successful_logins' |
|
| 20 |
echo 'ftp_fl.label failed_logins' |
|
| 21 |
echo 'ftp_su.label successful_uploads' |
|
| 22 |
echo 'ftp_fu.label failed_uploads' |
|
| 23 |
echo 'ftp_sd.label successful_downloads' |
|
| 24 |
echo 'ftp_fd.label failed_downloads' |
|
| 25 |
echo 'ftp_sde.label successful_deletes' |
|
| 26 |
echo 'ftp_fde.label failed_deletes' |
|
| 27 |
exit 0 |
|
| 16 |
cat <<EOF |
|
| 17 |
graph_title vsftpd Server |
|
| 18 |
graph_args --base 1000 -l 0 |
|
| 19 |
graph_vlabel Requests |
|
| 20 |
graph_category ftp |
|
| 21 |
ftp_c.label connections |
|
| 22 |
ftp_c.type DERIVE |
|
| 23 |
ftp_c.min 0 |
|
| 24 |
ftp_sl.label successful_logins |
|
| 25 |
ftp_sl.type DERIVE |
|
| 26 |
ftp_sl.min 0 |
|
| 27 |
ftp_fl.label failed_logins |
|
| 28 |
ftp_fl.type DERIVE |
|
| 29 |
ftp_fl.min 0 |
|
| 30 |
ftp_su.label successful_uploads |
|
| 31 |
ftp_su.type DERIVE |
|
| 32 |
ftp_su.min 0 |
|
| 33 |
ftp_fu.label failed_uploads |
|
| 34 |
ftp_fu.type DERIVE |
|
| 35 |
ftp_fu.min 0 |
|
| 36 |
ftp_sd.label successful_downloads |
|
| 37 |
ftp_sd.type DERIVE |
|
| 38 |
ftp_sd.min 0 |
|
| 39 |
ftp_fd.label failed_downloads |
|
| 40 |
ftp_fd.type DERIVE |
|
| 41 |
ftp_fd.min 0 |
|
| 42 |
ftp_sr.label successful_renames |
|
| 43 |
ftp_sr.type DERIVE |
|
| 44 |
ftp_sr.min 0 |
|
| 45 |
ftp_fr.label failed_renames |
|
| 46 |
ftp_fr.type DERIVE |
|
| 47 |
ftp_fr.min 0 |
|
| 48 |
ftp_sde.label successful_deletes |
|
| 49 |
ftp_sde.type DERIVE |
|
| 50 |
ftp_sde.min 0 |
|
| 51 |
ftp_fde.label failed_deletes |
|
| 52 |
ftp_fde.type DERIVE |
|
| 53 |
ftp_fde.min 0 |
|
| 54 |
EOF |
|
| 55 |
exit 0 |
|
| 28 | 56 |
fi |
| 29 | 57 |
|
| 30 |
ftp_c=U |
|
| 31 |
ftp_sl=U |
|
| 32 |
ftp_fl=U |
|
| 33 |
ftp_su=U |
|
| 34 |
ftp_fu=U |
|
| 35 |
ftp_sd=U |
|
| 36 |
ftp_fd=U |
|
| 37 |
ftp_sde=U |
|
| 38 |
ftp_fde=U |
|
| 39 |
|
|
| 40 |
ftp_c=`grep "CONNECT" ${LOGFILE} | wc -l`
|
|
| 41 |
ftp_sl=`grep "OK LOGIN" ${LOGFILE} | wc -l`
|
|
| 42 |
ftp_fl=`grep "FAIL LOGIN" ${LOGFILE} | wc -l`
|
|
| 43 |
ftp_su=`grep "OK UPLOAD" ${LOGFILE} | wc -l`
|
|
| 44 |
ftp_fu=`grep "FAIL UPLOAD" ${LOGFILE} | wc -l`
|
|
| 45 |
ftp_sd=`grep "OK DOWNLOAD" ${LOGFILE} |wc -l`
|
|
| 46 |
ftp_fd=`grep "FAIL DOWNLOAD" ${LOGFILE} | wc -l`
|
|
| 47 |
ftp_sde=`grep "OK DELETE" ${LOGFILE} |wc -l`
|
|
| 48 |
ftp_fde=`grep "FAIL DELETE" ${LOGFILE} | wc -l`
|
|
| 49 |
|
|
| 50 |
echo "ftp_c.value ${ftp_c}"
|
|
| 51 |
echo "ftp_sl.value ${ftp_sl}"
|
|
| 52 |
echo "ftp_fl.value ${ftp_fl}"
|
|
| 53 |
echo "ftp_su.value ${ftp_su}"
|
|
| 54 |
echo "ftp_fu.value ${ftp_fu}"
|
|
| 55 |
echo "ftp_sd.value ${ftp_sd}"
|
|
| 56 |
echo "ftp_fd.value ${ftp_fd}"
|
|
| 57 |
echo "ftp_sde.value ${ftp_sde}"
|
|
| 58 |
echo "ftp_fde.value ${ftp_fde}"
|
|
| 58 |
if [ -f "${logfile}" ]; then
|
|
| 59 |
awk ' |
|
| 60 |
BEGIN {
|
|
| 61 |
counts["ftp_c"] = 0; |
|
| 62 |
counts["ftp_sl"] = 0; |
|
| 63 |
counts["ftp_fl"] = 0; |
|
| 64 |
counts["ftp_su"] = 0; |
|
| 65 |
counts["ftp_fu"] = 0; |
|
| 66 |
counts["ftp_sd"] = 0; |
|
| 67 |
counts["ftp_fd"] = 0; |
|
| 68 |
counts["ftp_sr"] = 0; |
|
| 69 |
counts["ftp_fr"] = 0; |
|
| 70 |
counts["ftp_sde"] = 0; |
|
| 71 |
counts["ftp_fde"] = 0; |
|
| 72 |
} |
|
| 73 |
/CONNECT/ { counts["ftp_c"]++; next; }
|
|
| 74 |
/OK LOGIN/ { counts["ftp_sl"]++; next; }
|
|
| 75 |
/FAIL LOGIN/ { counts["ftp_fl"]++; next; }
|
|
| 76 |
/OK UPLOAD/ { counts["ftp_su"]++; next; }
|
|
| 77 |
/FAIL UPLOAD/ { counts["ftp_fu"]++; next; }
|
|
| 78 |
/OK DOWNLOAD/ { counts["ftp_sd"]++; next; }
|
|
| 79 |
/FAIL DOWNLOAD/ { counts["ftp_fd"]++; next; }
|
|
| 80 |
/OK RENAME/ { counts["ftp_sr"]++; next; }
|
|
| 81 |
/FAIL RENAME/ { counts["ftp_fr"]++; next; }
|
|
| 82 |
/OK DELETE/ { counts["ftp_sde"]++; next; }
|
|
| 83 |
/FAIL DELETE/ { counts["ftp_fde"]++; next; }
|
|
| 84 |
END {
|
|
| 85 |
for (idx in counts) {
|
|
| 86 |
printf "%s.value %d\n", idx, counts[idx]; |
|
| 87 |
} |
|
| 88 |
} |
|
| 89 |
' "${logfile}"
|
|
| 90 |
else |
|
| 91 |
cat <<EOF |
|
| 92 |
ftp_c.value U |
|
| 93 |
ftp_sl.value U |
|
| 94 |
ftp_fl.value U |
|
| 95 |
ftp_su.value U |
|
| 96 |
ftp_fu.value U |
|
| 97 |
ftp_sd.value U |
|
| 98 |
ftp_fd.value U |
|
| 99 |
ftp_sr.value U |
|
| 100 |
ftp_fr.value U |
|
| 101 |
ftp_sde.value U |
|
| 102 |
ftp_fde.value U |
|
| 103 |
EOF |
|
| 104 |
fi |
|
Formats disponibles : Unified diff