ScienceLogic Logo

Polling XML Values with ScienceLogic

Most Network Management Systems are built to make it easy to poll data via SNMP. But ‘interesting’ data is not always available via SNMP. Sometimes it’s in another format, such as XML. I’m working with ScienceLogic quite a lot recently, and it makes it easy to poll that data, alert on it, and integrate it with all the other sources of data, into dashboards, reports, etc. Here’s a quick walk-through of polling data in XML format, and adding it to ScienceLogic.

Portland Temperature

I’m going to use the NOAA weather data as an example of data in XML format. Let’s assume we wanted to poll the temperature for Portland, Oregon, and display it on a graph. Here’s what our data source looks like:

  


    NOAA's National Weather Service
    http://weather.gov/
    
        http://weather.gov/images/xml_logo.gif
        NOAA's National Weather Service
        http://weather.gov
    
    15 minutes after the hour
    60
    Portland, Portland International Airport, OR
    KPDX
    45.59578
    -122.60917
    Last Updated on Mar 27 2015, 7:53 pm PDT
        Fri, 27 Mar 2015 19:53:00 -0700
    Overcast
    61.0 F (16.1 C)
    61.0
    16.1
    63
    Southwest at 13.8 MPH (12 KT)
    Southwest
    220
    13.8
    12
    1017.5 mb
    1017.5
    30.05
    48.0 F (8.9 C)
    48.0
    8.9
    59 F (15 C)
        59
        15
    10.00
    http://forecast.weather.gov/images/wtf/small/
    http://www.weather.gov/data/obhistory/KPDX.html
    novc.png
    http://www.weather.gov/data/METAR/KPDX.1.txt
    http://weather.gov/disclaimer.html
    http://weather.gov/disclaimer.html
    http://weather.gov/notice.html

The key part is between the <temp_c> tags. We need to extract that value, and poll it. To do this in ScienceLogic, we need to define a Credential, which will include the URL, and then we need to create a ‘Dynamic Application’ that tells ScienceLogic which tags to extract, and how to present the data.

Once that’s done, we’ll assign the credential and Dynamic Application to a device, and it should start collecting data.

XML Credentials

Go to System -> Manage -> Credentials, and go Create -> SOAP/XML Credential. You’ll get a pop-up like this:

xml_credential

Give it a name – in this case we’ll use “PortlandWeather”, and set the URL to http://w1.weather.gov/xml/current_obs/KPDX.xml. You’ll see there’s a heap of other settings we could set for authentication, headers, etc, but in this case we can leave them all at default. Note that ScienceLogic takes cURL options. So if you’ve done your testing with cURL, and you’ve been using some custom options, it should be very easy to transfer.

Dynamic Application

Now we need to set up the XML tag parsing, and how to present the data. Go to System -> Manage -> Applications. Click on Actions -> Create New Dynamic Application. On the first page, set the Application Type to “XML Performance”, set the name, and set the Poll Frequency (5 minutes in this case). Then click Save, and it should look like this:

dynamic_app_properties

 

Go to the Collections tab. This is where we tell ScienceLogic which tags we’re looking for, what format the data is in, and any formulae/translations that need to be applied. Let’s give our collection a name “Temperature”, and then put in the tags we’re looking for. This is in the format <parent_tag>….<intermediate_tag(s)>…<node tag>. Looking through our XML above, we can see that we just need <current_observation><temp_c>>. We could apply a formula here – e.g. to convert between Fahrenheit and Celsius – and we can also set a Description. We don’t need to do any of that. The other key item is the “Class Type” – this tells ScienceLogic how to handle that data. If it was an Interface counter, it would always go up, and ScienceLogic would need to calculate the rate of change. It could also be a text label. But in this case it’s a value that can go up and down, and we want to plot the current value. So we use “Performance Gauge””:

xml_app_collections

 

Save that, then go to the Presentations tab. This defines which values get displayed, and we can apply more formulae if required. We can set pop-up guide text, and the display units. Click on the Wrench next to our item, and change the name to “Portland, OR”, and set the data unit to ºC. Make sure you set the “Active State” to Enabled:

xml_app_presentation

We won’t worry about Thresholds or Alerts yet. Save that, and let’s put it together.

Pulling it Together – Devices, Applications and Credentials

We’ve created the pieces, now we need to pull it together, so it starts collecting data.

First, we need a device to associate the data with. You might already have one, or you can create a “Virtual” Device. Go to Registry -> Devices -> Device Manager, then Actions -> Create Virtual Device. Create a Virtual SOAP-XML Transactions Device, and call it “Weather”.

Now open the Device Properties page for that device, and go to the Collections tab. Go Action -> Add Dynamic Application. Scroll down and find your new Temperature Application. Now select the PortlandWeather Credential on the right-hand side, and click Save. You should now have this:

dev_collections

 

At this point, we should be all good. You could click the Lightning Bolt icon, to test it out and review the debugs, or you can just go to the Device Performance tab, and look for the data (you may have to wait a few minutes for it to start showing up). You should start to see something like this:

dev_perf_results

Easy as that! Obviously that’s a fairly simple example, but you can start to do much more interesting things. It gets much more interesting if you start looking at caching results, and re-using them elsewhere. The basic XML polling will only take you so far though – sooner or later you need to do some custom data manipulation. That’s when you move to “Snippet” applications, that let you insert custom Python code. Very powerful, but a bit more complicated.

Comments are closed.