2021-06-16 12:21:45 +02:00
|
|
|
#!@@GOODSH@@
|
|
|
|
# -*- sh -*-
|
|
|
|
|
|
|
|
: << =cut
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
samba - Plugin to monitor number of files held open by the CIFS clients
|
|
|
|
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
|
|
|
|
This plugin uses the following configuration variables:
|
|
|
|
|
|
|
|
[samba]
|
|
|
|
user root
|
|
|
|
env.smbstatus /usr/bin/smbstatus
|
|
|
|
env.ignoreipcshare 1
|
|
|
|
|
|
|
|
Usually "smbstatus" requires to be run as root (see "user root" above).
|
|
|
|
|
|
|
|
Environment variables:
|
|
|
|
|
|
|
|
* smbstatus: path to "smbstatus" executable
|
|
|
|
(default: search PATH and fall back to /usr/bin/smbstatus)
|
|
|
|
* ignoreipcshare: set this variable to any non-empty value to ignore IPC$ when counting shares.
|
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
|
|
|
|
Unknown author
|
|
|
|
|
|
|
|
=head1 LICENSE
|
|
|
|
|
|
|
|
GPLv2
|
|
|
|
|
|
|
|
=head1 MAGIC MARKERS
|
|
|
|
|
|
|
|
#%# family=contrib
|
|
|
|
#%# capabilities=autoconf
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
2021-06-16 12:31:21 +02:00
|
|
|
#SMBSTATUS=${smbstatus:-$(sudo command -v smbstatus)}
|
2021-06-16 12:27:07 +02:00
|
|
|
SMBSTATUS=${SMBSTATUS:-$(sudo /usr/bin/smbstatus)}
|
2021-06-16 12:21:45 +02:00
|
|
|
|
|
|
|
if [ "$1" = "autoconf" ]; then
|
|
|
|
if [ -x "$SMBSTATUS" ]; then
|
|
|
|
if "$SMBSTATUS" -V >/dev/null 2>&1; then
|
|
|
|
echo 'yes'
|
|
|
|
else
|
|
|
|
echo "no (failed to run $SMBSTATUS - maybe need to run as 'root'?)"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo 'no (smbstatus not found)'
|
|
|
|
fi
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$1" = "config" ]; then
|
|
|
|
|
|
|
|
echo 'graph_title Samba status'
|
|
|
|
echo 'graph_args -l 0'
|
|
|
|
echo 'graph_vlabel number'
|
|
|
|
echo 'graph_category samba'
|
|
|
|
echo 'proc.label processes'
|
|
|
|
echo 'lock.label locked files'
|
|
|
|
echo 'share.label Open shares'
|
2021-10-01 11:49:45 +02:00
|
|
|
echo 'user.label Active Users'
|
2021-06-16 12:21:45 +02:00
|
|
|
# Bug pointed out by kozik: there is no max field.
|
|
|
|
# echo 'max.warning 900'
|
|
|
|
# echo 'max.critical 960'
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
$SMBSTATUS -p 2>/dev/null | awk 'BEGIN {lines=0} $1 ~ /^[0-9]+/ {lines++} END {print "proc.value " lines}'
|
|
|
|
$SMBSTATUS -L 2>/dev/null | awk 'BEGIN {lines=0} $1 ~ /^[0-9]+/ {lines++} END {print "lock.value " lines}'
|
|
|
|
if [ -n "${ignoreipcshare:-}" ]; then
|
|
|
|
# shellcheck disable=SC2016
|
|
|
|
IGNORE='$1=="IPC$" {next}'
|
|
|
|
fi
|
|
|
|
$SMBSTATUS -S 2>/dev/null | awk '
|
|
|
|
BEGIN {lines=0;state=0}
|
|
|
|
$1=="Service" && state==0 {state=1; next}
|
|
|
|
/^--*$/ && state==1 {state=2; next}
|
|
|
|
state < 2 {next}
|
|
|
|
/^$/ {next}
|
|
|
|
'"$IGNORE"'
|
|
|
|
{lines++}
|
|
|
|
END {print "share.value " lines}'
|
2021-10-01 11:49:45 +02:00
|
|
|
# mg@fileserver2 11:44 ~
|
|
|
|
# > sudo smbstatus
|
|
|
|
#
|
|
|
|
# Samba version 4.11.6-Ubuntu
|
|
|
|
# PID Username Group Machine Protocol Version Encryption Signing
|
|
|
|
# ----------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
# 3996190 michaelgrote smb_users 192.168.2.180 (ipv4:192.168.2.180:59878) SMB3_11 - partial(AES-128-CMAC)
|
|
|
|
# 722 pve smb_users 192.168.2.15 (ipv4:192.168.2.15:40512) SMB3_00 - partial(HMAC-SHA256)
|
|
|
|
# 736 navidrome smb_users 192.168.2.68 (ipv4:192.168.2.68:51130) SMB3_11 - partial(AES-128-CMAC)
|
|
|
|
# 3048197 photoprism smb_users 192.168.2.35 (ipv4:192.168.2.35:33078) SMB3_11 - partial(AES-128-CMAC)
|
|
|
|
# sucht nach der Protokolversion
|
|
|
|
echo user.value "$($SMBSTATUS | grep -c SMB)"
|