Hi Team,
we need to add the alert in Nagios monitoring to monitor open files for specific user in a linux server.
please suggest me on this .
Thanks in advance.
Regards,
Chandra
Plugin to check open files for a specific user
-
benjaminsmith
- Posts: 5324
- Joined: Wed Aug 22, 2018 4:39 pm
- Location: saint paul
Re: Plugin to check open files for a specific user
HI Chandra,
Haven't had a chance to test this yet, but there's a community plugin on the Nagios Exchange available for this type of check.
https://exchange.nagios.org/directory/P ... sh/details
We have a few guides with directions on how to test and configure a community plugin. Let me know if you need any assistance or have questions.
Managing Plugins In Nagios XI
Third-Party Plugins in Nagios XI
Benjamin
Haven't had a chance to test this yet, but there's a community plugin on the Nagios Exchange available for this type of check.
https://exchange.nagios.org/directory/P ... sh/details
We have a few guides with directions on how to test and configure a community plugin. Let me know if you need any assistance or have questions.
Managing Plugins In Nagios XI
Third-Party Plugins in Nagios XI
Benjamin
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: Plugin to check open files for a specific user
Hi Benjamin,
Thanks for your response.
Actually , we are trying to get monitor for number of open files for a jboss user.
However, we already tried with plug in "check_open_files.sh". But we are getting error while executing.
please find attachment for error reference.
we used the below script.
#!/bin/bash
#
# Inspired by: http://pissedoffadmins.com/nagios/nagio ... check.html
#
# Author: Gregor Binder
# Mail: [email protected]
SUDO=/bin/sudo
LSOF=/sbin/lsof
AWK=/bin/awk
WC=/bin/wc
ERROR_CODE=-1
if [ -z "$1" ]; then
echo "Usage: $0 username"
echo " username: Username to check for to much open files"
exit $ERROR_CODE
else
USER=$1
fi
function checkExitStatus {
if [ $1 -ne 0 ]; then
echo "!!! command failure !!! $2"
exit -1
fi
}
# check if the username is valid
$LSOF -u jboss &> /dev/null
checkExitStatus $? "Username wrong"
# check if ah PID is available for the user
PID=`ps -u $USER | tail -1 | awk '{print $1}'`
checkExitStatus $? "No PID found"
OPEN_F=`$SUDO cat /proc/$PID/limits | grep "open files" | awk '{print $5}'`
LSOF=`$SUDO $LSOF -u $USER | $WC -l`
PERCDONE_PRE=$(echo "scale=2;(($LSOF/$OPEN_F) * 100)" |bc)
PERCDONE=`echo $PERCDONE_PRE | cut -d. -f1`
if [ $PERCDONE -lt 84 ]; then
ERROR_CODE=0
printf "FILES OK - $PERCDONE %% with $LSOF files open|files=$LSOF;;;\n"
else
if [ $PERCDONE -ge 85 ] && [ $PERCDONE -le 94 ]; then
ERROR_CODE=1
printf "FILES WARN - $PERCDONE %% with $LSOF files open|files=$LSOF;;;\n"
elif [ $PERCDONE -ge 95 ]; then
ERROR_CODE=2
printf "FILES CRIT - $PERCDONE %% with $LSOF files open|files=$LSOF;;;\n"
fi
fi
exit $ERROR_CODE
Thanks for your response.
Actually , we are trying to get monitor for number of open files for a jboss user.
However, we already tried with plug in "check_open_files.sh". But we are getting error while executing.
please find attachment for error reference.
we used the below script.
#!/bin/bash
#
# Inspired by: http://pissedoffadmins.com/nagios/nagio ... check.html
#
# Author: Gregor Binder
# Mail: [email protected]
SUDO=/bin/sudo
LSOF=/sbin/lsof
AWK=/bin/awk
WC=/bin/wc
ERROR_CODE=-1
if [ -z "$1" ]; then
echo "Usage: $0 username"
echo " username: Username to check for to much open files"
exit $ERROR_CODE
else
USER=$1
fi
function checkExitStatus {
if [ $1 -ne 0 ]; then
echo "!!! command failure !!! $2"
exit -1
fi
}
# check if the username is valid
$LSOF -u jboss &> /dev/null
checkExitStatus $? "Username wrong"
# check if ah PID is available for the user
PID=`ps -u $USER | tail -1 | awk '{print $1}'`
checkExitStatus $? "No PID found"
OPEN_F=`$SUDO cat /proc/$PID/limits | grep "open files" | awk '{print $5}'`
LSOF=`$SUDO $LSOF -u $USER | $WC -l`
PERCDONE_PRE=$(echo "scale=2;(($LSOF/$OPEN_F) * 100)" |bc)
PERCDONE=`echo $PERCDONE_PRE | cut -d. -f1`
if [ $PERCDONE -lt 84 ]; then
ERROR_CODE=0
printf "FILES OK - $PERCDONE %% with $LSOF files open|files=$LSOF;;;\n"
else
if [ $PERCDONE -ge 85 ] && [ $PERCDONE -le 94 ]; then
ERROR_CODE=1
printf "FILES WARN - $PERCDONE %% with $LSOF files open|files=$LSOF;;;\n"
elif [ $PERCDONE -ge 95 ]; then
ERROR_CODE=2
printf "FILES CRIT - $PERCDONE %% with $LSOF files open|files=$LSOF;;;\n"
fi
fi
exit $ERROR_CODE
You do not have the required permissions to view the files attached to this post.
Re: Plugin to check open files for a specific user
Hi,
Please install "lsof" to run this script.
Also, I looked at the URL below, you must add the followings to the sudoer file
https://github.com/wefixit-AT/nagios_check_open_files
Here's the output of the command:
Regards,
Vinh
Please install "lsof" to run this script.
Code: Select all
yum install lsof
https://github.com/wefixit-AT/nagios_check_open_files
Code: Select all
Cmnd_Alias NRPE_CHECK_OPEN_FILES = /bin/cat /proc/*/limits, /sbin/lsof -u *
nrpe ALL=(ALL) NOPASSWD: NRPE_CHECK_OPEN_FILES
Code: Select all
[root@VT-NagiosXI-61 ~]# ./check_open_file.sh apache
FILES OK - 53 % with 2206 files open|files=2206;;;
Regards,
Vinh
Re: Plugin to check open files for a specific user
Hi ,
LSOF command already installed in server .
And we added the two lines in sudoers file , but after added lines sudo users facing issues to login and showing wrong entry in sudoers file.
And then, i created one script with lsof command to check open files for jboss user and getting the output.
But , not able to set thresholds for this.
Please find attachments.
So, need help to set thresholds for this or script to monitor for open files for a particular user
LSOF command already installed in server .
And we added the two lines in sudoers file , but after added lines sudo users facing issues to login and showing wrong entry in sudoers file.
And then, i created one script with lsof command to check open files for jboss user and getting the output.
But , not able to set thresholds for this.
Please find attachments.
So, need help to set thresholds for this or script to monitor for open files for a particular user
You do not have the required permissions to view the files attached to this post.
Re: Plugin to check open files for a specific user
You could use something like this:So, need help to set thresholds for this or script to monitor for open files for a particular user
Code: Select all
#!/bin/bash
count=`lsof -u jboss | wc -l`
warn=$1
crit=$2
if (("$count" <= "$warn")); then
echo "OK: $count open files is within the accepted thresholds"
exit 0
fi
if (("$count" <= "$crit")) && (("$count" > "$warn")); then
echo "Warning: $count open files exceed the warning threshold of $warn"
exit 1
fi
if (("$count" > "$crit")); then
echo "Critical: $count open files exceed the critical threshold of $crit"
exit 2
fiExample:
Code: Select all
./check_open_files_jboss1.sh 1000 2000Hope this helps.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: Plugin to check open files for a specific user
Hi lmiltchev ,
Thanks for your help.
Used script & Set the thresholds , its working fine.
Regards,
Chandra
Thanks for your help.
Used script & Set the thresholds , its working fine.
Regards,
Chandra
Re: Plugin to check open files for a specific user
I am glad I could help! 
Be sure to check out our Knowledgebase for helpful articles and solutions!