Forum Discussion
- Sarah_TerryProduct Manager
You can currently add/update the location property for a device using our RPC API: http://www.logicmonitor.com/support/rpc-api-developers-guide/manage-devices/update-a-device/
You should use opType=add in your request to add the property and opType=replace to update the property.
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.
- MoshProfessor
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.
- Joe_TranAdvisor
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)
- Antony_HawkinsEmployee
I realise this is some years later, but if anyone else happens across this thread wondering the same thing, I wrote a DataSource that does exactly this (updates the location property, or any property, of a monitored resource) in April 2021.
It was specifically for sea-going vessels, by coincidence, and updates a defined property using the LogicMonitor REST API:
/topic/7219-location-credentials-any-custom-property-updater-datasource-framework/ - 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.
- ShackAdvisor
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
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).
Related Content
- 2 years ago
- 9 months ago