How Tos > Add Custom WMI Monitors VBS Method

Add Custom WMI Monitors VBS Method

Tags:  

Steps to add custom WMI monitors that are collected using a VB Script

If you are good at writing scripts and know how to query a Windows device and get the data you want, then this page is for you. MSP Center offers some hooks using which you can write scripts and add more monitors into the system than what it offers by default.

Steps involved
  1. write the script
  2. test the script
  3. save it under c:\programfiles\adventnet\me\probe\conf\application\scripts
  4. make entries in probe/conf/application/hostresource.xml
  5. restart the probe
  6. update central database
  7. update probe database
  8. restart central
  9. test the monitor

Example: VmWare Free Size Monitor
One of our customers Hakan Dönmez had a requirement where he wanted to monitor free size in VPX_DATASTORE database of the vmware virtual center (now vcenter). This is how he achieved it using MSP Center.

Step1: Write the VBScript
VMDatastoreDetails.vbs

'Script for polling Datastore info
'By Hakan Dönmez


Option Explicit
Dim strComputer, strUsername, strPassword
Dim strName, intFreeSpace, intSize
Dim conn, rs, strSQL, strMsg

On Error Resume Next
strSQL = "select name, capacity, free_space from VPX_DATASTORE"
set conn = createobject("ADODB.Connection")


Select Case WScript.Arguments.Count
    Case 1
        WScript.Quit(0)
    Case 3
        strComputer = Wscript.Arguments(0)
        strUsername = Wscript.Arguments(1)
        strPassword = Wscript.Arguments(2)
        conn.open "Provider=SQLOLEDB.1;Password=" & strPassword & ";Persist Security Info=True;" & _
        "User ID=" & strUsername & ";Initial Catalog=VIM_VCDB;
Data Source=" & strComputer & "\SQLEXP_VIM"
        set rs = createobject("ADODB.Recordset")
       
    Case Else
        WScript.Quit(0)
   
End Select
If Err.Number = 0 Then
    rs.open strSQL, conn
On Error Goto 0
    While not rs.eof
        strName = rs.fields(0).value
        intFreeSpace = rs.fields(2).value
        intSize = rs.fields(1).value
            strMsg = strMsg & _
                 strName & vbTab & _
                 CStr( Int( ( intSize )  ) ) & _
                 vbTab & _
                 CStr( Int( ( intFreeSpace )  ) ) & _
                 vbTab & _
                 CStr( Int( ( intSize ) -( intFreeSpace ) )  ) & _
                 vbTab & _
                 CStr( Int(  ( 100 * (( intSize ) -( intFreeSpace ) ) / intSize) ) ) & _
                 vbCrLf
        rs.movenext
    Wend
rs.close
conn.close
set rs= nothing
set conn = nothing
Else
    'wscript.echo "Error"
End If
    strMsg = vbCrlf & "Drive:" & vbTab & "Size:" & vbTab & "Free:"
& vbTab & "Used:" & vbTab & "% Used:" &_
    vbcrlf & _
    strMsg
    Wscript.Echo strMsg
WSCript.Quit(0)


Step 2 : Test the VB Script

Use cscript filename.vbs and test the script locally


Step 3: Save the script

Save the script under probe/conf/application/scripts folder



Step 4: Make entries in hostresource.xml file

  • Edit probe/conf/application/hostresource.xml file using a text editior such as VIM
  • Search for "ID=Windows XP"
  • Copy the following lines and paste them under the Windows XP line

    <CATEGORY ID="VMDatastoreDetails" command="VMDatastoreDetails.vbs" parseAll="true" ignoreLines="3" description="Monitoring the space used in each datastore in VM environment">

       <ENTITY ID="VMDatastoreDetails" applyThresholdOver="curValue" threshold="Th6" storeHistory="true" units="%" storeValue="curValue" comparePreValue="false">

        <PARSE token="1" name="partitionName" isEntityName="true"/>

        <PARSE token="5" name="curValue"/>

      </ENTITY>

    </CATEGORY>

    like this



  • Do the same for ID=Windows 2003, 2008, Vista, 2000, NT etc (based on what OS your monitored devices will be available)
Step 5: Restart the probe

  • Just restart the probe once

Step 6: Go to central and add a new monitor

  • Open central URL and go to Admin-> Monitoring Templates-> Windows Base WMI Template->New Monitor-> Add Bulk
  • Provide the following info
    • name= VMDatastoreDetails
    • oid=VMDatastoreDetails  
      *  - the OID should be the same as CATEGORYID in the hostresource.xml file
    • Tabular = yes
    • Interval = 5 mins
    • Units = %
    • Thersold = provide if you wish



    once you add check if the monitor is shown in the template right hand side as shown below


    • Click save in the template to save the monitor
    • Choose cancel in the next screen

Step 7: Update database and change protocol from SNMP to WMI

  • connect to mysql and execute the following query
    select * from graphdetails where graphname like "%VMDatastore%"



  • now run this query
    update graphdetails set protocolid=(select protocolid from protocoldetails where protocolname="WMI") where graphname like "%VMDatastore%"



  • Run the same query in probe database

Step 8: Restart Central
  • Restart the central server

Step 9: Test the monitor
  • Go to central server
  • Add the VMDatastoreDetails monitor to a device
  • Check if the monitor works











 RSS of this page

rtttrrb