KS-Soft. Network Management Solutions
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister    ProfileProfile    Log inLog in 

Monitoring ESXi servers with Python script

 
Post new topic   Reply to topic    KS-Soft Forum Index -> Configuration, Maintenance, Troubleshooting
View previous topic :: View next topic  
Author Message
rc



Joined: 01 Aug 2005
Posts: 100

PostPosted: Fri Apr 17, 2009 7:08 am    Post subject: Monitoring ESXi servers with Python script Reply with quote

Hi @ all,

ESXi servers does not support SNMP gets. But there is an open source script in Python available (check_esx_wbem.py) to monitor ESXi servers. The script was written for Nagios-oriented monitoring but it can translate for another monitoring tool by re-defining exit codes.

Now my question:

Has anyone taken this script for monitoring ESXi servers with hostmonitor?

Here is a sample setup for Whatsup monitoring tool:
http://www.stephenjc.com/2009/01/whatsup-vmware-esxi-monitor-these.html

I have installed Python 2.6 and pywbem under Windows. Then I run from the command line check_esx_wbem.py and it works so far.

But how to use in Hostmonitor?

With best regards
Enrico
Back to top
View user's profile Send private message
KS-Soft Europe



Joined: 16 May 2006
Posts: 2832

PostPosted: Fri Apr 17, 2009 7:51 am    Post subject: Reply with quote

There are several ways to use Python script with HostMonitor.

1. "Active Script" test method: http://www.ks-soft.net/hostmon.eng/mframe.htm#tests.htm#script
To make it work properly, you have to type manually "python" into "Language" box in "Test Properties" window and provide Python script, that suits "Active Script" method requirements:
Requirements to the script:
HostMonitor has just a few requirements:
==================================================================
1. script must contain "performtest" function. HM always call function with this name
2. "performtest" function must not have any parameters
3. "performtest" function must return string value. This string contains two parts separated by colon (. First obligatory part contains test status, it can take following values:

* "Host is alive"
* "No answer"
* "Unknown"
* "Unknown host"
* "Ok"
* "Bad"
* "Bad contents"

Second optional part contains "Reply" value, HostMonitor displays this value in Reply field, writes to log files, uses to displays charts (Log Analyzer), etc.
Several examples:
return "Host is alive:1000 ms" | Jscript; Status: Host is alive; Reply: 1000 ms
return "Unknown host:" | Jscript; Status: Unknown host; Reply: empty
performtest = "Ok:300 Kb" | VBscript; Status: Ok; Reply: 300 Kb
performtest = "Bad:90 %" | VBscript; Status: Bad; Reply: 90 %
3a. If you want Log Analyzer will be able correctly process "Reply" values and displays charts, use one of the following formats for "Reply" value:

* decimal_number (like '123', '0', '6456.45'. as decimal separator use symbol that is specified on your system, usually a dot (.) or a comma (,))
* decimal_number + space + 'Kb' (like '512 Kb', '64 Kb')
* decimal_number + space + 'Mb' (like '1024 Mb', '5 Mb')
* decimal_number + space + 'Gb' (like '12 Gb', '4 Gb')
* decimal_number + space + '%' (like '50 %', '99 %')
* decimal_number + space + 'ms' (like '100 ms', '5400 ms')

==================================================================


2. "Shell Script" test method: http://www.ks-soft.net/hostmon.eng/mframe.htm#tests.htm#chkShell
Into "Start cmd" input box in "Script Manager" window you should type: cmd /c Python %Script% %Params%
Into "Script" area you should type your Pythons script. Please note: Script should suit requirements:
==================================================================

1. First obligatory part - marker "scriptres" tells to HostMonitor or RMA that this string is the result string.

2. Second obligatory part represents the test status, it can take one of the following values: Host is alive, No answer,Unknown, Unknown host, Ok, Bad, Bad contents

3. Third optional part contains Reply value, HostMonitor displays this value in Reply field, writes to log files, uses to displays charts (Log Analyzer), etc. If you want Log Analyzer to process Reply values correctly and display charts, use one of the following formats for Reply value:
* decimal_number (like "123", "0", "6456.45". as decimal separator use symbol that is specified on your system, usually a dot (.) or a comma (,))
* decimal_number + space + "Kb" (like "512 Kb", "64 Kb")
* decimal_number + space + "Mb" (like "1024 Mb", "5 Mb")
* decimal_number + space + "Gb" (like "12 Gb", "4 Gb")
* decimal_number + space + "%" (like "50 %", "99 %")
* decimal_number + space + "ms" (like "100 ms", "5400 ms")

Several examples:
String printed by script "Status" of the test "Reply" field of the test
scriptres:Host is alive:1000 ms Host is alive 1000 ms
scriptres:Unknown host: Unknown host
scriptres:Ok:300 Kb Ok 300 Kb
scriptres:Bad:90 % Bad 90 %

==================================================================


3. "External" test method: http://www.ks-soft.net/hostmon.eng/mframe.htm#tests.htm#execheck
You may write a Python script, that returns some particular exit code. According to this exit code, HostMonitor will warn you.
To start Python script using "External" test method, you should type the line, like the following into "External program" box in "Test Properties" window:

Please note: all foregoing methods require "ActivePython" to be installed on machine, where HostMonitor (or RMA) is running.
http://www.activestate.com/activepython/

You may find several examples in \Examples\Scripts subfolder of HostMonitor folder. Unfortunatelly, there is no python scripts. However, I think, you may use VB and JS scripts as an example.

Regards,
Max
Back to top
View user's profile Send private message Send e-mail Visit poster's website
greyhat64



Joined: 14 Mar 2008
Posts: 246
Location: USA

PostPosted: Fri Apr 17, 2009 12:51 pm    Post subject: Reply with quote

Max,
I'm curious. . .
I use Active or Shell test methods for my scripts, and have always reserved the External test method for compiled code.
I think I understand all the methods pretty well, but, when you have the choice, which one should you use?

Are certain scripting environments better suited for Active or Shell scripting?

And if I have a VBScript, which could work with all three methods, is there performance advantage one method has over another?

All three, thankfully, have timeout options. External test method even has a 'kill' option. Should stability or reliability be a determining factor in selecting a method?

I look forward to your response!
Back to top
View user's profile Send private message Send e-mail
KS-Soft



Joined: 03 Apr 2002
Posts: 12795
Location: USA

PostPosted: Fri Apr 17, 2009 1:01 pm    Post subject: Reply with quote

If your script returns just bad/good status using exit code, External test should work just a little bit faster than Shell Script.
Otherwise (when you need status and reply) I would prefer Shell Script over Active Script, Shell Script may start many instances/threads without problems.

Regards
Alex
Back to top
View user's profile Send private message Visit poster's website
greyhat64



Joined: 14 Mar 2008
Posts: 246
Location: USA

PostPosted: Fri Apr 17, 2009 1:05 pm    Post subject: Reply with quote

Alex,
Great, concise answer and it clears things up considerably. Thanks!
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    KS-Soft Forum Index -> Configuration, Maintenance, Troubleshooting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

KS-Soft Forum Index