Go to All Forums

Need to get a list of your monitors?

Have you ever needed to get a list of monitors and their details? I did and wrote this script to do just that.

Make sure to change the Zoho-authtoken to your own, this one is a random one I grabbed from the API documentation.



  1. #!/usr/bin/env python
    # -*- coding: utf-8 -*-

    import pycurl
    import json
    from io import BytesIO
    from optparse import OptionParser

    # Define Options
    parser = OptionParser(usage='Usage: %prog [options] arguments. Type -h for more info.')
    parser.add_option('-t', '--type',
                      type='choice',
                      choices=['dns', 'url', 'ping'],
                      help='Type of check to pull. ie: dns, ping, url',
                      dest='checkType')
    (options, args) = parser.parse_args()

    # Define how to connect to Site24x7 API
    def connectSite247(method,putData):
        c = pycurl.Curl()
        connectReturn = BytesIO()
        c.setopt(pycurl.URL, 'https://www.site24x7.com/api/monitors')
        c.setopt(pycurl.HTTPHEADER, ["Accept: application/json; version=2.0"])
        c.setopt(pycurl.HTTPHEADER, ["Authorization: Zoho-authtoken a12345b6c8de901f2gh3456ij78k901l"])
        c.setopt(c.WRITEFUNCTION, connectReturn.write)
        c.setopt (pycurl.CUSTOMREQUEST, method)
        c.setopt (pycurl.POSTFIELDS, putData)
        c.perform()
        c.close()
        connectOutput = connectReturn.getvalue()
        return connectOutput

    # Get the API Output
    listOfMonitors = json.loads(connectSite247('GET',''))

    ################################################################################
    # DO NOT CHANGE ANYTHING ABOVE THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING
    ################################################################################

    # List URL checks
    ################################################################################
    if options.checkType == 'url':
        for i in listOfMonitors['data']:
            if i['type'] == 'URL':
                print "URL:\tname:\t%s\tmon_id:\t%s\turl:\t%s" % (i['display_name'], i['monitor_id'], i['website'])

    # List DNS checks
    ################################################################################
    if options.checkType == 'dns':
        for i in listOfMonitors['data']:
            if i['type'] == 'DNS':
                print "DNS:\tname:\t%s\tmon_id:\t%s\tdns_host:\t%s\tdomain:\t%s" % (i['display_name'], i['monitor_id'], i['dns_host'], i['domain_name'])

    # List PING checks
    ################################################################################
    if options.checkType == 'ping':
        for i in listOfMonitors['data']:
            if i['type'] == 'PING':
                print "PING:\tname:\t%s\tmon_id:\t%s\thost_name:\t%s" % (i['display_name'], i['monitor_id'], i['host_name'])

You can add additional types, just make not of the changes in field names for that other types you add...

To use it to get your URL monitors, just run ./listmonitors.py -t url

The output will look like this:

URL:    name:    Wesite-Name    mon_id:    113770000025720011    url:    https://www.website.com/

Like (4) Reply
Replies (7)

Hi,

Thanks for sharing this information.

We are about to release Export Monitor option in our Admin Tab. Hope that will complement this one.

Raghavan

Like (0) Reply

Raghavan,

That is an awesome feature to add to the builtin options.
Like (0) Reply

Hi, 

The "Export Monitors" option has been released today and you can find that under "Admin -> Inventory -> Import / Export Monitors" section. 

Please check and let us know if that helps. 

Regards, 
Rafee
Like (0) Reply

That works, however it does not provide the monitorID / GroupID which is central to using your API.

Speaking of groupID.. Is there going to be an option to export Groups anytime soon?
Like (0) Reply

We will include monitor id in the exported csv.

Our primary goal in configuration export is to provide an easy way to get the list of monitors which can be used in any internal discussions. So we did not give the unique ids for all the applicable attributes which are useful for making API calls. However, we will think about providing a better way to get the unique id for each resource within client itself, so that user can make API calls easily.

We don't have any plan for providing monitor group export. Group names are already present in the monitors export. Is there any specific use case that can be solved only by monitor group export? Do you expect only group names and name of the monitors in it (or) all the configuration of the monitors too?

Like (0) Reply

Sorry for taking this long to reply ...  No special need for the Group export, just thought it would be nice to be able to select a specific group to export only those checks.

 

I did notice something interesting when I exported the monitors tho ... The monitor_id field does not seem to be formatted properly so it shows the weird format 1.33693E+17 in the column but the ID is there if we click on the cell...

 

See screenshot below....

 

Like (0) Reply

Monitor ids are being exported properly. Can you please increase the column width or change number formatting in your spreadsheet software?

Option to export monitors of a particular monitor group is already available. Hope that is what you are asking for. Exporting monitor group configurations such as group description, dependency etc is not available though.

Attachments
Image.png
Size: 654.17 KB
Like (0) Reply

Was this post helpful?