Home Directory

Search Exchange

Search All Sites

Nagios Live Webinars

Let our experts show you how Nagios can help your organization.

Contact Us

Phone: 1-888-NAGIOS-1
Email: sales@nagios.com

Login

Remember Me

Directory Tree

Directory

DutchEagleon

Reviews(2)
byDutchEagleon, May 20, 2016
CPU Stats/Memory Used Plugin - Top 5 CPU/Memory Consuming Processes for Unix Servers
I tested both of them on CentOS 7.2, the CPU check worked after dos2unix.
But the MEM check needed some more changes.

The script used "machinfo" but this isn't a command in CentOS. So I used "cat /proc/meminfo | grep Memtotal"
I also changed the total free memory, to this command:

# Total memory available
totalmem=`cat /proc/meminfo | grep -i memtotal`
totalmem=`echo $totalmem | awk '{print $2}'`
#totalmem=`echo "$totalmem * 1024" | bc`
#echo "TotalMem=$totalmem"

#Total Free Memory
freemem=`cat /proc/meminfo | grep -i memfree`
freemem=`echo $freemem | awk '{print $2}'`

I also had a problem with "bc", I constantly got a error about the decimal that was included.
But I changed the calculation so it wouldn't get the error anymore:

# Total memory used
usedmem=`echo "$totalmem - $freemem" | bc -l`
#echo "UsedMem=$usedmem"

#Percent Used Mem for Calculation.
percused=`echo $usedmem / $totalmem | bc -l`

#Percent Used Mem
percentused=`echo "scale=0;($percused * 100/1)" | bc -l`

#echo "PercentUsedMem=$percentused"
percentfree=`echo "100 - $percentused" | bc -l`

And I got an integer expression on line 123, so I changed the command a bit.
OUTPUT=";Top 5 Memory Processes(memKB,pname,pid): " ;
for word in $COMMAND; do
i=`expr $i + 1`
j=`expr $j + 1`
if [[ $i -eq 3 ]]; then
i=0;
if [ $j -eq 15 ]; then
OUTPUT="$OUTPUT `echo $word`" ;
else
OUTPUT="$OUTPUT `echo $word, `" ;
fi
else
if [ "$i%3" = "1" ]; then ## It was this: [ $i%3 -eq 1 ] ##
OUTPUT="$OUTPUT `echo $word"KB"`" ;
else
OUTPUT="$OUTPUT `echo $word `" ;
fi
fi
done

After I made this changes it worked fine.
byDutchEagleon, October 16, 2015
SNMP Printer Check
Good Script, Very helpful.
I only had some problems with the STATUS and PAGECOUNT.

The STATUS Problem I solved with the help of a previous review, that you had to change "idle(3)"); to "idle"). After I made that change it worked fine.

The PAGECOUNT problem wasn't really a problem but more like it was missing something. The PAGECOUNT showed me the total number of pages printed color and black together.

But I wanted to see the color PAGECOUNT and black PAGECOUNT separately,
So I had to make some changes to the script.

The original PAGECOUNT function looks like this:

function check_page_count(){
PAGE_COUNT=$(snmpget -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.43.10.2.1.4.1.1 2>/dev/null | sed -e :x -e 's/\([0-9][0-9]*\)\([0-9][0-9][0-9]\)/\1,\2/' -e 'tx')

EXIT_STRING="Pagecount is $PAGE_COUNT"
PERFDAT="Pages=$PAGE_COUNT;"
return 0
}

The long number (1.3.6.1.2.1.43.10.2.1.4.1.1 2) is a OID, an OID is object identifier and this one is used to get the PAGECOUNT Total.

But like I said I wanted to see the PAGECOUNT for color and Black separately, so I did some research of what the OID's are for this and I found them on an forum.

1.3.6.1.4.1.253.8.53.13.2.1.6.1.20.33(COLOR)
1.3.6.1.4.1.253.8.53.13.2.1.6.1.20.34(BLACK)

I think they are officially for a Xerox Printer, but I think they will also work for other printers you just have to test. I didn't have any other printers available then Xerox.

So the changes is made are this:

function check_page_count1(){
PAGE_COUNT=$(snmpget -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.4.1.253.8.53.13.2.1.6.1.20.33 2>/dev/null | sed -e :x -e 's/\([0-9][0-9]*\)\([0-9][0-9][0-9]\)/\1,\2/' -e 'tx')
EXIT_STRING="Pagecount is $PAGE_COUNT"
PERFDAT="Pages=$PAGE_COUNT;"
return 0
}

function check_page_count2(){
PAGE_COUNT=$(snmpget -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.4.1.253.8.53.13.2.1.6.1.20.34 2>/dev/null | sed -e :x -e 's/\([0-9][0-9]*\)\([0-9][0-9][0-9]\)/\1,\2/' -e 'tx')
EXIT_STRING="Pagecount is $PAGE_COUNT"
PERFDAT="Pages=$PAGE_COUNT;"
return 0
}
function check_page_count3(){
PAGE_COUNT=$(snmpget -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.43.10.2.1.4.1.1 2>/dev/null | sed -e :x -e 's/\([0-9][0-9]*\)\([0-9][0-9][0-9]\)/\1,\2/' -e 'tx')
EXIT_STRING="Pagecount is $PAGE_COUNT"
PERFDAT="Pages=$PAGE_COUNT;"
return 0
}

As you can see the commands stay the same only OID changes and the name of the function. I kept the original PAGECOUNT for the total number.

After you have done this you will need to changes the main code, you will have to add the commands to name you can use.

You will need to make the following changes around line 880:

else
STRING_TYPE=$(echo "$ALL_MARKERS" | tr -d "\n" | cut -d " " -f3)
case "$CHECK" in
"MESSAGES")
check_messages
;;
"MODEL")
check_model
;;
"CONSUM")
check_consumables "$PARAMETER"
;;
"CONSUMX")
check_exact_consumable "$PARAMETER"
;;
"TRAY")
check_paper_trays "$PARAMETER"
;;
"PAGECOUNTCOLOR")
check_page_count1
;;
"PAGECOUNTBLACK")
check_page_count2
;;
"PAGECOUNTTOTAL")
check_page_count3
;;
"DEVICES")
check_device_status
;;
"STATUS")
check_printer_status
;;
"DISPLAY")
check_display
;;
*) # no parameters were passed, or a parameter was incorrect (wrong spelling, etc.)
echo 'Invalid check specified by -x parameter.'
echo ''
print_help
;;
esac

EXIT_CODE=$?

As you can see I have added PAGECOUNTCOLOR, PAGECOUNTBLACK and PAGECOUNTTOTAL, so when you have made these changes you can also put the help function.

You will get something like this:

echo ''
echo ' PAGECOUNTTOTAL'
echo ' How many pages this printer has processed for black and color'
echo ''
echo ' PAGECOUNTBLACK'
echo ' How many pages this printer has processed for black'
echo ''
echo ' PAGECOUNTCOLOR'
echo ' How many pages this printer has processed for color'


That's all the changes I made, I just find it handy to know all the number instead of just the total one.

And I wanted to post it here so maybe more people can use it so they don't have to search for it on google.

Maybe it's a thing for in the next version.