Skip navigation
3213 Views 6 Replies Latest reply: Feb 9, 2012 4:18 AM by Milos Vujkovic RSS
Milos Vujkovic Rank: White Belt 12 posts since
Aug 23, 2011
Currently Being Moderated

Feb 7, 2012 7:55 AM

Report on specific Windows service(s) availability

Hello guys,

 

I enabled monitoring of almost all critical Windows services in our environment using WMI. I used quite primitive approach: written down all server roles, and their accompanying services. So now I have bunch of monitored services, ranging from Domain Services to Exchange, on all production servers.

 

Next task in line is difficult for my knowledge of Zenoss I need to be able to create availability reports of critical services in certain time frames. Example would be:

 

 

- What was the availability of Exchange (or AD, SQL, third-party software..) services in the last month / week? Not only total %, but also how many times did they drop, and for how long.

 

etc, etc, from update services to custom business applications.

 

 

My plan was to manually collect availability reports of indivudial services, group them together based on function, and create some fancy Excell sheet.

 

To be honest with you, I have no idea how to achieve this. I tried looking around Zenoss community portal and documents, but I have found nothing close to my demands.

 

I hope someone could steer me in right direction

 

P.S. I am aware of service-specific ZenPacks, like for Exchange, Active Directory, SQL.. But thats for monitoring. I am stuck with reporting

  • jmp242 ZenossMaster 4,060 posts since
    Mar 7, 2007

    I don't know if this will help or not, but take a look at the IPSLA Zenpack?http://community.zenoss.org/docs/DOC-3436

    There's also an availability report zenpack:

    http://community.zenoss.org/docs/DOC-5899

     

    They might give you some example code anyway...

     

    --

    James Pulver

    ZCA Member

    LEPP Computer Group

    Cornell University

  • Shane Scott ZenossMaster 1,373 posts since
    Jul 6, 2009

    Milos:

     

    You'll need to write an sql query that fetches from the events database service up and down events for each event over a range and calculates the uptime.

     

    --Shane

  • Shane Scott ZenossMaster 1,373 posts since
    Jul 6, 2009

    Milos:

     

    Here's a python script that connects to the events database and determines availability of devices via ping up/down events. You should be able to tweak this for what you need.

     

    #!/usr/bin/env python

    import Globals

    from Products.ZenUtils.ZenScriptBase import ZenScriptBase

    from transaction import commit

     

    dmd = ZenScriptBase(connect=True, noopts=True).dmd

     

    from Products.ZenUtils import Time

    import re

    import sys

     

    from optparse import OptionParser

     

    parser = OptionParser()

     

    parser.add_option("-s", "--start-date", dest="startDate",

                      help="Select Start Date [MM/DD/YYYY]", metavar="StartDate")

     

    parser.add_option("-e", "--end-date", dest="endDate",

                      help="Select End Date [MM/DD/YYYY]", metavar="EndDate")

     

    parser.add_option("-y", "--epoch-start", dest="startDateEpoch",

                      help="Select start time in seconds", metavar="SECONDS")

     

    parser.add_option("-z", "--epoch-end", dest="endDateEpoch",

                      help="Select end time in seconds", metavar="SECONDS")

     

    (options, args) = parser.parse_args()

     

    if not options.startDate and not options.endDate and not options.startDateEpoch and not options.endDateEpoch:

        parser.print_help()

        sys.exit()

     

    import MySQLdb

     

    conn = MySQLdb.connect (host = "localhost",

                            user = "zenoss",

                            passwd = "zenoss",

                            db = "events")

    cursor = conn.cursor ()

     

    if not options.startDateEpoch and not options.endDateEpoch:

        if options.startDate and options.endDate:

            startDate = options.startDate

            endDate = options.endDate

            startDate, endDate = map(Time.ParseUSDate, (startDate, endDate))

            startDate = min(startDate, endDate - 1)

        else:

            print "Start and end options need to be used in conjunction with each other."

            sys.exit()

    else:

        if options.startDateEpoch and options.endDateEpoch:

            startDate = options.startDateEpoch

            endDate = options.endDateEpoch

        else:

            print "Start and end options need to be used in conjunction with each other."

            sys.exit()

     

    print 'Device,Availability'

     

    for d in dmd.Devices.getSubDevices():

     

        cursor.execute (

        """

        SELECT sum(lastTime - firstTime)

                FROM (

                        SELECT device, component, firstTime, lastTime

                        FROM history

                        WHERE severity >= 5 AND lastTime >= %s

                                        AND firstTime >= %s

                                        AND firstTime <= %s AND lastTime <= %s AND firstTime != lastTime

                                        AND eventClass = '/Status/Ping' AND prodState >= 1000

                                        AND device = '%s'

                        UNION

                        SELECT device, component, firstTime, lastTime

                        FROM status

                        WHERE severity >= 5 AND lastTime >= %s

                                        AND firstTime >= %s

                                        AND firstTime <= %s AND lastTime <= %s AND firstTime != lastTime

                                        AND eventClass = '/Status/Ping' AND prodState >= 1000

                                        AND device = '%s'

        )

        AS U

        """

        % (startDate,startDate,endDate,endDate,d.id,startDate,startDate,endDate,endDate,d.id))

     

        totaldown = cursor.fetchone()

     

        checkspan = cursor.execute (

        """

        SELECT device, component, firstTime, lastTime

                FROM (

                        SELECT device, component, firstTime, lastTime

                        FROM history

                        WHERE severity >= 5 AND lastTime >= %s

                                        AND firstTime <= %s AND firstTime != lastTime

                                        AND eventClass = '/Status/Ping' AND prodState >= 1000

                                        AND device = '%s'

                        UNION

                        SELECT device, component, firstTime, lastTime

                        FROM status

                        WHERE severity >= 5 AND lastTime >= %s

                                        AND firstTime <= %s AND firstTime != lastTime

                                        AND eventClass = '/Status/Ping' AND prodState >= 1000

                                        AND device = '%s'

        )

        AS U

        """

        % (endDate,startDate,d.id,endDate,startDate,d.id))

     

        cursor.execute (

        """

        SELECT lastTime

                FROM (

                        SELECT device, component, firstTime, lastTime

                        FROM history

                        WHERE severity >= 5 AND lastTime <= %s

                                        AND lastTime >= %s AND firstTime < %s AND firstTime != lastTime

                                        AND eventClass = '/Status/Ping' AND prodState >= 1000

                                        AND device = '%s'

                        UNION

                        SELECT device, component, firstTime, lastTime

                        FROM status

                        WHERE severity >= 5 AND lastTime <= %s

                                        AND lastTime >= %s AND firstTime < %s AND firstTime != lastTime

                                        AND eventClass = '/Status/Ping' AND prodState >= 1000

                                        AND device = '%s'

        )

        AS U

        """

        % (endDate,startDate,startDate,d.id,endDate,startDate,startDate,d.id))

     

        leadin = cursor.fetchone()

     

        cursor.execute (

        """

        SELECT firstTime

                FROM (

                        SELECT device, component, firstTime, lastTime

                        FROM history

                        WHERE severity >= 5 AND firstTime <= %s

                                        AND firstTime >= %s AND lastTime > %s AND firstTime != lastTime

                                        AND eventClass = '/Status/Ping' AND prodState >= 1000

                                        AND device = '%s'

                        UNION

                        SELECT device, component, firstTime, lastTime

                        FROM status

                        WHERE severity >= 5 AND firstTime <= %s

                                        AND firstTime >= %s AND lastTime > %s AND firstTime != lastTime

                                        AND eventClass = '/Status/Ping' AND prodState >= 1000

                                        AND device = '%s'

        )

        AS U

        """

        % (endDate,startDate,endDate,d.id,endDate,startDate,endDate,d.id))

     

        leadout = cursor.fetchone()

     

        try:

            totaldown = float(totaldown[0])

        except:

            totaldown = 0

     

        try:

            leadin = float(leadin[0])

        except:

            leadin = 0

     

        try:

            leadout = float(leadout[0])

        except:

            leadout = 0

     

        if checkspan == 1:

            availability = 0

        else:

            if leadin and leadout:

                totaldown = totaldown + (leadin - startDate) + (endDate - leadout)

            else:

                if leadin:

                    totaldown = totaldown + (leadin - startDate)

                if leadout:

                    totaldown = totaldown + (endDate - leadout)

     

            availability = round(100 - ((totaldown / (endDate - startDate)) * 100),3)

     

     

        print '%s,%s' % (d.id,availability)

     

    Best,

    --Shane (Hackman238)

More Like This

  • Retrieving data ...

Legend

  • Correct Answers - 4 points
  • Helpful Answers - 2 points