Xymon Mailing List Archive search

Windows services on a cluster.

list Gautier Begin
Tue, 18 Sep 2012 17:32:29 +0200
Message-Id: <user-9652a16fcaa7@xymon.invalid>

Hello,

You can also use this VBS script with BBWin:

Just modify the array Lst_Srv and put there the list of the service you want to monitor and value Cluster should be the name of the cluster you want to monitore.


'''''''''''''''''''''''
'
' VBS template for BBWin
'
'
' Gautier BEGIN
' CSC Luxembourg
' 11/02/2010
'
'
' The XYMON server name, the debug level, the test/column name and the LifeTime are read from the BBWin.cfg file
'
' An execution log is created in the BBWin\logs\<Column>.log file. The VBS object associated is ObjectFileLog.
'
'
' You have to fill the value of Msg_KO and Msg_OK according your own custom test.
'
'
' You can use the ERROR variable to send your error message (0=> MSG_OK, 1=> MSG_KO)
'
'
'''''''''''''''''''''''

'''''''''''''''''''''''
'
' VBS std Variables
'
'''''''''''''''''''''''
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim Obj_FSO, WshShell, WshNetwork, xmlDoc

set Obj_FSO     = CreateObject("Scripting.FileSystemObject")
Set WshShell    = WScript.CreateObject("WScript.Shell")
Set WshNetwork  = WScript.CreateObject("WScript.Network")
Set xmlDoc      = CreateObject("Microsoft.XMLDOM")
xmlDoc.async    = "false"               ' permit to load the document in memory before computing


'''''''''''''''''''''''
'
' BBWin Variables '
'''''''''''''''''''''''
Dim Cmd, BB, PathBBWin, LOG, LifeTime, DebugLevel
Dim Msg_OK, Msg_KO, Msg, Color, Color_KO, Color_OK, Column, ERROR, Srv, Return, ExecCmd, ObjectFileLog, CFG, CFGVal, X


' To be Modified
Msg_OK = ""
Msg_KO = ""
Color_OK  = "green"
Color_KO  = "red"

' Default values
Column = "cluster"
DebugLevel  = 0
LifeTime = 10 'minutes

PathBBWin = WshShell.RegRead("HKLM\SOFTWARE\BBWin\binpath")
PathBBWin = Left(PathBBWin,Len(PathBBWin)-3)
BB     = PathBBWin & "bin\BBWinCmd.exe"
CFG    = PathBBWin & "etc\BBWin.cfg"


Return = 0
ERROR = 0

' Reading the config file


xmlDoc.load(CFG)
set CFGVal = xmlDoc.documentElement

   If Not CFGVal Is Nothing Then
        For Each x In CFGVal.selectNodes("/configuration/bbwin/setting")
                If X.getAttribute("name") = "bbdisplay" Then
                        Srv = X.getAttribute("value")
                End If

                If X.getAttribute("name") = "loglevel" Then
                        DebugLevel  = X.getAttribute("value")
                End If

                If X.getAttribute("name") = "timer" Then
                        LifeTime  = X.getAttribute("value")
                        Select Case Right(LifeTime ,1)
                                Case "m"  LifeTime = Left(LifeTime,Len(LifeTime)-1)
                                Case "h"  LifeTime = Left(LifeTime,Len(LifeTime)-1) * 60
                                Case "d"  LifeTime = Left(LifeTime,Len(LifeTime)-1) * 60 * 24
                                Case Else LifeTime = 1
                        End Select

                End If
        Next

        For Each x In CFGVal.selectNodes("/configuration/externals/load")
                If InStrRev(X.getAttribute("value"),WScript.ScriptName) > 0 Then
                        Column = X.getAttribute("name")
                End If 
        Next


    End If

LOG    = PathBBWin & "logs\" & Column & ".log"
if ( DebugLevel > 0 ) Then         set ObjectFileLog = Obj_FSO.OpenTextFile(LOG,ForAppending  ,True)
End if


'''''''''''''''''''''''
'
' Custom test
'
'''''''''''''''''''''''

Dim strComputer, ResGrp, ActiveNode, IsActiveNode Dim objWMIService, colItems, objItem Dim Service, Status, Elt, Cluster, Disp_Name

strComputer = "."
IsActiveNode = 0
Lst_Srv= Array("MSFtpsvc")      ' FTP Service Cluster = "Cluster_Name"

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\mscluster")

Set colItems = objWMIService.ExecQuery("Select * from mscluster_nodetoactivegroup")
For Each objItem in colItems         ResGrp = Treatment(objItem.PartComponent)

        If ResGrp = Cluster Then
                ActiveNode = Treatment(objItem.GroupComponent)
                If ActiveNode = WshNetwork.ComputerName Then IsActiveNode = 1
        End If
Next

' Test the state of the services
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Service ")

For Each objItem in colItems
        Service = objItem.Name         Status = objItem.State         Disp_Name =  objItem.DisplayName
         For Each Elt in Lst_Srv
                If Elt = Service Then 
                        If  (( IsActiveNode = 1 ) and ( Status = "Running" )) Then                                 Msg_OK = "&" & Color_OK & " The service " & Disp_Name & " is running on the active node of the cluster " & Cluster & vbCRLF & Msg_OK
                        Elseif  (( IsActiveNode = 0 ) and ( Status = "Stopped" )) Then
                                Msg_OK = "&" & Color_OK & " The service " & Disp_Name & " is stopped on the passive node of the cluster " & Cluster & vbCRLF & Msg_OK
                        Else
                                ERROR = 1
                                If IsActiveNode = 1 Then
                                        Msg_KO = "&" & Color_KO & " The service " & Disp_Name & " is " & Status & " on the active node of the cluster " & Cluster & vbCRLF & Msg_KO
                                Else
                                        Msg_KO = "&" & Color_KO & " The service " & Disp_Name & " is " & Status & " on the passive node of the cluster " & Cluster & vbCRLF & Msg_KO
                                End If
                        End If
                End If
        Next
Next


Function Treatment(String)

        Treatment = Replace(Right(String,Len(String) - InStr(String,"=")),"""","")

End Function 
'''''''''''''''''''''''
'
' Sending the alarm
'
'''''''''''''''''''''''


If ( ERROR = 0 ) Then
        Color = Color_OK
        Msg = Msg_OK
Else
        If InStr(Msg_KO,"red") > 0 Then
                Color = "red"
        Else
                Color = "yellow"         End If
        Msg = Msg_KO & vbCRLF & Msg_OK
End if
Msg = Now() & vbCRLF & Msg

'WScript.Echo Msg
'WScript.Quit

LifeTime = LifeTime * 3
Cmd = Chr(34) & BB & Chr(34) & " " & Srv & " status " & WshNetwork.ComputerName & " " & Column & " " & Color & " " & Chr(34) & MSG & Chr(34) & " " & LifeTime

On Error Resume Next
Set ExecCmd = WshShell.Exec(Cmd)

' Old version of VBS
If Err.Number <> 0 Then
        Return = WshShell.Run("C:\progra~1\BBWin\bin\BBWinCmd.exe " & Srv & " status " & WshNetwork.ComputerName & " " & Column & " " & Color & " " & Chr(34) & MSG & Chr(34) & " " & LifeTime, 0, True)
Else
        Return = ExecCmd.ExitCode
End If

On Error Goto 0


If ( DebugLevel > 0 ) Then
        If ( Return <> 0 ) Then
                ObjectFileLog.WriteLine(Now() & " " & Cmd & " Output error code: " & Return )
        Else
                if ( DebugLevel = 4 ) Then
                        ObjectFileLog.WriteLine(Now() & " " & Cmd & " Output error code: " & Return )
                End if
        End if
End if

'''''''''''''''''''''''
'
' Destruction of Objects
'
'''''''''''''''''''''''
' Objects of the test

set objWMIService = Nothing
set colItems      = Nothing
set objItem       = Nothing


' Std BBWin Objects


if ( DebugLevel > 0 ) Then         ObjectFileLog.Close
        set ObjectFileLog  = Nothing
End if
set ExecCmd      = Nothing
set WshNetwork   = Nothing
set WshShell     = Nothing
set Obj_FSO      = Nothing set xmlDoc       = Nothing set X            = Nothing 
Cordialement, Regards,Mit freundlichen Grüßen,

Gautier BEGIN

Admin and Tools Team Lead
CSC Computer Sciences Luxembourg S.A.
12D Impasse Drosbach
L-1882 Luxembourg

Global Outsourcing Service | p:+352 24 834 276 | m:+352 621 229 172 | user-083785ae1711@xymon.invalid | www.csc.com


CSC • This is a PRIVATE message. If you are not the intended recipient, please delete without copying and kindly advise us by e-mail of the mistake in delivery.  NOTE: Regardless of content, this e-mail shall not operate to bind CSC to any order or other contract unless pursuant to explicit written agreement or government initiative expressly permitting the use of e-mail for such purpose
 • CSC Computer Sciences SAS • Registered Office: Immeuble Le Balzac, 10 Place des Vosges, 92072 Paris La Défense Cedex, France • Registered in France: RCS Nanterre B 315 268 664


From:   "Neil Simmonds" <user-8188d25e65e4@xymon.invalid>
To:     "Xymon mailinglist" <xymon at xymon.com>
Date:   09/18/2012 03:35 PM
Subject:        Re: [Xymon] Windows services on a cluster.
Sent by:        xymon-bounces at xymon.com


Hi Thomas,

I looked at that and it doesn't really do what I want as it only differentiates between red,blue,purple or green,yellow,clear. 
If it set different values for the different colours then it would be a lot better. 
I think I might be able to do something with it, but it will mean changes to some of my scripting. We have a script that alerts to tests that are active but not in critical,cfg as we mainly use the critical view for our operators so I just have to work out how to add the exclusions for svcs column on the 2 servers I want to compare. If I do that I can happily have them turning red and therefore use combo.cfg


Not ideal in this situation but it looks like it's the most workable solution.

Regards,
Neil.
-----Original Message-----
From: Thomas Kähn [mailto:user-04e2bc8a3755@xymon.invalid]
Sent: 18 September 2012 12:22
To: Neil Simmonds
Cc: Xymon mailinglist
Subject: Re: [Xymon] Windows services on a cluster.

Hi Neil,

On Tue, Sep 18, 2012 at 11:51:25AM +0100, Neil Simmonds wrote:
Has anyone done anything in Xymon for monitoring windows services 
across
a cluster.

I've got a set of services I need to monitor and as long as they are
running on one of 2 servers then all is OK.
I can't seem to find a way to do this in Xymon. Has anyone done
something like this?
I haven't tried myself. But you could try to use bbwin as client in
conjunction with the combostatus feature:

http://bbwin.sourceforge.net/ http://xymon.sourceforge.net/xymon/help/manpages/man5/combo.cfg.5.html 
Best regards
Thomas Kähn
--
Thomas Kähn
Technik, Network Engineering & Design; Content Delivery Platform & IP
NETCOLOGNE Gesellschaft für Telekommunikation mbH
Am Coloneum 9 | 50829 Köln

www.netcologne.de 
Geschäftsführer:
Dr. Hans Konle (Sprecher)
Dipl.-Ing. Karl-Heinz Zankel

Vorsitzender des Aufsichtsrates:
Dr. Andreas Cerbe

HRB 25580, AG Köln


Diese Nachricht (inklusive aller Anhänge) ist vertraulich. Sollten
Sie diese Nachricht versehentlich erhalten haben, bitten wir, den
Absender (durch Antwort-E-Mail) hiervon unverzüglich zu informieren
und die Nachricht zu löschen. Die E-Mail darf in diesem Fall weder
vervielfältigt noch in anderer Weise verwendet werden.
Name & Registered Office: EXPRESS GIFTS LIMITED, 2 GREGORY ST, HYDE, CHESHIRE, ENGLAND, SK14 4TH, Company No. 00718151.
Express Gifts Limited is authorised and regulated by the Financial Services Authority

NOTE: This email and any information contained within or attached in a separate file is confidential and intended solely for the Individual to whom it is addressed. The information or data included is solely for the purpose indicated or previously agreed. Any information or data included with this e-mail remains the property of Findel PLC and the recipient will refrain from utilising the information for any purpose other than that indicated and upon request will destroy the information and remove it from their records. Any views or opinions presented are solely those of the author and do not necessarily represent those of Findel PLC. If you are not the intended recipient, be advised that you have received this email in error and that any use, dissemination, forwarding, printing, or copying of this email is strictly prohibited. No warranties or assurances are made in relation to the safety and content of this e-mail and any attachments. No liability is accepted for any consequences arising from it. Findel Plc reserves the right to monitor all e-mail communications through its internal and external networks. If you have received this email in error please notify our IT helpdesk on +44(0) 1254 303030