ScienceLogic / EM7 – Monitoring VMware vShield Edges – Part 1

This is a two part series, and the scripts used in this are for information only, you will need to make changes to the scripts in order to use them.

If like the company I work for you happen to use ScienceLogic EM7 as your monitoring tool, and you make use of VMware vShield Edges for your customer edges, then like us you have probably run into a an issue where an edge fails in such a way that ScienceLogic EM7 doesn’t report the edge down. I decided to write a snippet to check the status of the edge.

Now the first issue is that although Science Logic EM7 detects the vShield edges via vCenter, it has no idea that they are infact vShield edges, as far as ScienceLogic is concerned they are just virtual machines. This is also true of vCenter, and does explain why there is no easy way of matching “Edge-Id’s” to ScienceLogic EM7 device entries.

So the first thing we need to do is have an easy way of linking the ScienceLogic EM7 device entries, to a vShield “Edge-id”, this will allow our status checking script to run against the correct vShield manager.

(If your environment only has a single vShield Manager, skip to the end and grab the single manager copy of the script.)

So firstly, we need to extend the ScienceLogic EM7 device schema to contain two additional fields, I have named them c-edge_id and c-edge_manager, they will contain the edge-id (used by vShield manager to identify the edge), and c-edge_manager which simply contains the DNS name on which that edge exists.

To extend the schema, you need to post against the api, i used the below (CAUTION, this will remove any CURRENT custom attributes, if you have current custom attributes, you need to add them to the below code.);

curl -u username:password -k -i -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d '{"c-edge_id":{"label":"ID_from_vshield_Edge","type":"string","index":"index"},"c-edge_manager":{"label":"EdgeManager","type":"string","index":"index"}}' https://apiurl/api/api_custom_field/device


Once done, you now need a script that runs through all your devices and adds the required information. I would recommend coming up with a naming convention to make this task easier, all our Edges are named vse-xxx. So we only look for those devices in the database.

Here is the code to add the edge-id;

import base64
import logging
import datetime
import xml.etree.ElementTree as ET
import MySQLdb as db
import requests
import json
##list of vShield Managers that need to be queried.
edgemanagers = ["edgemanager1,edgemanager2"]

#now loop through all edges
for address in edgemanagers:
    #username and password for vSheild manager api
    apicredstring = 'username:password' 
    #url on which to query the edge status on
    apiurl = "https://" + address + "/api/3.0/edges" 
    #create 64bit auth encode
    apicreds = base64.b64encode(apicredstring)
    apiauthheader = "Basic %s" % apicreds
    #create vShield api headers
    apiheaders = {"Authorization" : apiauthheader , "Accept" : "application/xml"}
    #em7 username and password
    em7apicredstring = 'username:password'
    #create em7 api 64bit auth encode
    em7apicreds = base64.b64encode(em7apicredstring)
    em7apiauthheader = "Basic %s" % em7apicreds
    #create em7 api headers
    em7apiheaders = {"Authorization" : em7apiauthheader , "Accept" : "application/xml" ,"content-type": "application/xml"}
    # Connect to vShield Edge manager and get a list of ALL edges
    r = requests.get(apiurl,headers=apiheaders, verify=False)
    # grab the return data from the request and load it into python xml interp
    xml = r.content
    root = ET.fromstring(str(xml))
    #loop through all the top level items (called "edge")
    for edge in root.getiterator('edgeSummary'):
        #grab its name
        name = edge.find('name').text
        #grab its edge id
        edgeid =  edge.find('id').text
        #create the search string used to get the device id back from Sciencelogic EM7
        sqlstring = "SELECT id FROM legend_device where device like " + "'" + name +"%'"
        conn = db.connect(user='username', passwd='password', host='database-ip', port=7706, db="master_dev")
        cur = conn.cursor()
        #execute sql string
        data = cur.fetchall()
        #loop through all returned rows and add the edge id and manager 
        for row in data:
            #create payload, setting the c-edge_manager and c-edge_id as "name" and "edgeid" from above.
            payload = '<?xml version="1.0"?><Device><c-edge_id>'+edgeid+'</c-edge_id><c-edge_manager>'+address+'</c-edge_manager></Device>'
            em7apiurl = "https://api-ip/api/device/" + str(row[0])
                #post the change to sciencelogic em7 api
                r =, data=payload, headers=em7apiheaders, verify=False)
                print "oops"


Now that script has been run, hopefully your devices will have an edgeid and edgemanager set, you will need to query the API to see this, as it does not show in the gui.

I have this script running every time a new device is discovered, (Post to follow on how to do this), to ensure that no new edges are missed.

Thats it for this post, next time ill show the code on how I actually query the vShield manager and how I organise this in the GUI.

As ever any questions/comments/corrections, leave a message.

ScienceLogic EM7 , , ,

1 comment

  1. Srini

    I am able to execute small python snippet in Linux machine, but not from sciencelogic. from the tool output showing none, can you give a idea why I’m not getting output for python snippets

Leave a Reply

Your email address will not be published. Required fields are marked *