Forum Discussion

Torfinn_Høiland's avatar
9 years ago

Dynamic geo location of object in google maps widget

Hi ! Today many devices have the ability to report gps location by f.ex. SNMP.  We would like to present a more dynamic map showing f.ex vessel position based on this. I think this could by done quiet easy by giving us ability to change system.location tag from a script. This tag has to be added manually today.

 

9 Replies

  • Hi ! Thanks for this information. This method works ok but to use it I will have to script something outside Logicmonitor. I tried to do the updates via web service https request but as this can not pass any dynamic variables i am not able to send the location data.

    A solution could be be to allow some variables in the web service path setting so you could do this.

     

     

  • Hi @Sarah Terry

    Is there any way to set the location property using a PropertySource script?  My use case is that we want to assign the value to the location property based on parsing of the names of our devices.

  • I chain two propertysources together--one to set an autoProp, and another to write that autoProp to location via REST API. The location property isn't prefaced by system, so it can't be set in just the one propertySource--i don't think. 

    In the example below, the autoProp is called "auto.loc". 

    import org.apache.http.HttpEntity
    import org.apache.http.client.methods.CloseableHttpResponse
    import org.apache.http.client.methods.HttpPatch
    import org.apache.http.impl.client.CloseableHttpClient
    import org.apache.http.impl.client.HttpClients
    import org.apache.http.util.EntityUtils
    import javax.crypto.Mac;
    import javax.crypto.spec.SecretKeySpec;
    import org.apache.commons.codec.binary.Hex;
    import org.apache.http.entity.ContentType;
    import org.apache.http.entity.StringEntity;
    import groovy.json.JsonSlurper
    import groovy.json.JsonOutput
    import org.xbill.DNS.*
    
    
    accessId = hostProps.get('lm.api.id')
    accessKey = hostProps.get('lm.api.key')
    company = 'mycompany'
    
    resourcePath = '/device/devices/' + hostProps.get('system.deviceId')
    url = 'https://' + company + '.logicmonitor.com/santaba/rest' + resourcePath + "?patchFields=customProperties&opType=replace"
    
    location = hostProps.get('auto.loc')
    customProperties = [name: 'location', value: location]
    data = [customProperties: [customProperties]]
    jsonData =  JsonOutput.toJson(data)
    StringEntity payloadEntity = new StringEntity(jsonData)
    epoch = System.currentTimeMillis()
    requestVars = "PATCH" + epoch + jsonData + resourcePath
    
    
    // construct signature
    hmac = Mac.getInstance("HmacSHA256");
    secret = new SecretKeySpec(accessKey.getBytes(), "HmacSHA256")
    hmac.init(secret)
    hmac_signed = Hex.encodeHexString(hmac.doFinal(requestVars.getBytes()))
    signature = hmac_signed.bytes.encodeBase64()
    
    
    CloseableHttpClient httpclient = HttpClients.createDefault();
    http_request = new HttpPatch(url);
    http_request.addHeader("Authorization" , "LMv1 " + accessId + ":" + signature + ":" + epoch);
    http_request.setHeader("Accept", "application/json");
    http_request.setHeader("Content-type", "application/json");
    http_request.setEntity(payloadEntity);
    response = httpclient.execute(http_request);
    responseBody = EntityUtils.toString(response.getEntity());
    code = response.getStatusLine().getStatusCode();
    
    return(0)

     

  • Anonymous's avatar
    Anonymous

    FYI, I think there is a feature request in the system to allow auto.location to also be used to populate the location for Google Map widgets. This would be the better long term solution as it would allow very simple updates to the location using existing, simple, non-API based, methods. Please reach out to your CSM to request this.

  • I've landed on this thread today because I imported the "Public IP" property source that goes out to http://ipinfo.io/json for information and then sets those auto props on my devices.  @Stuart Weenig Do I still need to upvote this by reaching out to our CSM or can you tell if the Google Map widget can use auto.location yet?  

  • Anonymous's avatar
    Anonymous

    It cannot yet. Please reach out to your CSM to get it upvoted. I'm dying to have this work.

  • @Stuart Weenig .... I just send a "Feedback" request to add auto.location support to the Map widget.  Very odd that this is not already in place.  I guess they expect you to either manually set the location property for thousands of devices or create an external application which uses the API.  The PropertySources functionality is generally a good concept but it misses in a few areas (it should support setting properties for Instances and I'm also not sold on the "auto." thing).