*EDIT: To see a version that doesn't suck, click here*
I could not find a ready-made module for monitoring my KMS server with Nagios. All I wanted to know was what the current count of activations handed out by the server.
On the KMS Server
First off, some jury rigging. You have to set up a shared folder on your KMS server. In my case it was C:\nagios.
Next, create a batch file (kms_status.bat) with the following line:
Next, set kms_status.bat to run as a scheduled task. I set it to run every hour. You can set it to whatever frequency you want.
On the Nagios Server
First, because I'm lazy, I added the following to rc.local instead of editing fstab in order to mount the Windows share from the KMS server.
Next, create a file called check_kms in /usr/local/nagios/bin and copy/paste the following code into it.
You'll have to chmod +x check_kms
Add the following to /usr/local/nagios/etc/objects/commands.
The last thing you have to do is go to the configuration for your KMS server in Nagios and add the following.
Lastly, restart Nagios. For Ubuntu users: /etc/init.d/nagios restart
If all goes according to plan, you should be up and running and should look like this.
I could not find a ready-made module for monitoring my KMS server with Nagios. All I wanted to know was what the current count of activations handed out by the server.
On the KMS Server
First off, some jury rigging. You have to set up a shared folder on your KMS server. In my case it was C:\nagios.
Next, create a batch file (kms_status.bat) with the following line:
cscript C:\windows\system32\slmgr.vbs -dli > C:\nagios\kms_status.txt
Next, set kms_status.bat to run as a scheduled task. I set it to run every hour. You can set it to whatever frequency you want.
On the Nagios Server
First, because I'm lazy, I added the following to rc.local instead of editing fstab in order to mount the Windows share from the KMS server.
mount -t cifs //[KMSSERVERADDRESS]/[SHARENAME] /media/net -o domain=[DOMAIN],username=[USERNAME],password=[PASSWORD]
Next, create a file called check_kms in /usr/local/nagios/bin and copy/paste the following code into it.
#!/bin/bash
COUNT=`grep -i "count" /media/net/kms_status.txt | awk '{print $3}' | tr '\r' ' '`
if [ $COUNT -le 24 ]
then
echo "CRITICAL: Current Count: "$COUNT". The count is too low for KMS to work."
exit 2
elif [ $COUNT -ge 25 ]
then echo "OK: Current Count: "$COUNT". You can go have another cup of coffee now."
exit 0
else
echo "UNKNOWN: Something is wrong. kms_status.txt might not be available."
exit 3
fi
You'll have to chmod +x check_kms
Add the following to /usr/local/nagios/etc/objects/commands.
define command{
command_name check_kms
command_line ./usr/local/nagios/bin/check_kms
}
The last thing you have to do is go to the configuration for your KMS server in Nagios and add the following.
define service{
use generic-service
host_name [KMS SERVER NAME]
service_description KMS
check_command check_kms
}
Lastly, restart Nagios. For Ubuntu users: /etc/init.d/nagios restart
If all goes according to plan, you should be up and running and should look like this.
Amazing article. Its really helpful post.
ReplyDelete