Location / credentials / any custom property updater DataSource (framework)

Recommended Posts

  • LogicMonitor Staff
Posted (edited)

This is a DataSource that enables you to update any single custom property on any collector-monitored resource.

Example use case / how this came to be:

Let's imagine for a moment that you have a collection of monitored resources on a mobile piece of kit, for example a sea-going vessel. One of those resources is a GPS locator device, out of which you can retrieve latitude and longitude values, and you'd like to use those to populate the 'location' property for the resource in LogicMonitor, such that your various vessel locations can be shown on a LogicMonitor dashboard.

This DataSource will let you do exactly that.

It's a framework, into which you'll still have to put a bit of effort, namely, you need to add code to actually find the value you want to set/update on the resource. Obviously enough I have no idea what that might be in your case...

However, all the rest of the work - actually updating the resource using the LogicMonitor API - is done for you.

Yes, you could use this to grab data from another property, such as an auto.prop set by a simple PropertySource.

Yes, you could put the same code into a PropertySource or ConfigSource if that were appropriate for your use case, give or take some tweaks to the outputs.

Yes, you could use this to pull SNMP location data from a device, although "3rd floor back office cabinet, rack 2, shelf 6" won't translate well onto a Google Maps widget.

You will need to:

1. Create LM API token credentials (ID and key) for a user with rights to manage the resource(s) in question. Set these as apiaccessid.key and apiaccesskey.key properties for the resource(s);

2. In the DataSource script, ensure line 27 defines the custom property name you want to update:

customPropertyToBeUpdated = 'location';

Note this must be a property that you can access via managing the resource - this excludes any auto.xxx and system.xxx properties;

3. Create and put whatever necessary code into the try{} block of the getNewPropertyValue() function (lines 32-49 in the template), that returns the desired property value as a string.

Note that depending on what that code is, you may need to add further imports to the top of the script;

4. Set a polling interval that makes sense for the rate of change of value;

5. Change the AppliesTo rule from false() to whatever is appropriate.

What it does:

1. Runs your code to get a new property value;

2. Checks that this would be a change from the existing property value (or absence of property);

3. If it is a change, calls the LM API and updates (or creates) that custom property.

It'll graph results on a success/failure basis, and alert if you're missing API credentials or if those credentials are inadequate for the resource.

And, look, see, location data:

183009685_Screenshot2021-04-28at18_12_30.thumb.png.11398fefa0cc6fdf5c5bb30762a899c5.png 1659621568_Screenshot2021-04-28at18_12_20.thumb.png.a9dd6af05c5d1caa04fea896d2c8ca95.png

...granted, you can't tell I didn't just manually do that...


Although designed and released as a location updater, bits of this code started life as an SNMP community string updater (by testing multiple community strings from a list, and setting the one that works: https://communities.logicmonitor.com/topic/1867-pick-one-from-multiple-snmp-community-strings/), so could be used for that or for updating any property.


This script updates exactly one property. If you wanted to update multiple properties, you could clone the DS for each, or you could adapt the script to loop over multiple properties. If you do the clone route, note that the clones will not all run at the same time, so if you're trying to update a username and a password, that's going to leave a mismatch for a period. Also, we have a proper, in-platform, credentials vault integration on the way anyway.

v1.2: 3C2PMM


Edited by Antony Hawkins
v1.2 published
  • Like 2
Link to post
Share on other sites
  • LogicMonitor Staff

NB. Remember this calls the API to make any necessary changes. If you make 1,000 clones to change 1,000 properties on 1,000 devices once every minute, you will crash into API rate limiting and things won't work as expected.

Be sensible with deployment and update time intervals. Your ship is not moving that far every minute...

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.