Location / credentials / any custom property updater DataSource (framework)
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:
...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: a href="https://communities.logicmonitor.com/topic/1867-pick-one-from-multiple-snmp-community-strings/" rel="">https://communities.logicmonitor.com/topic/1867-pick-one-from-multiple-snmp-community-strings/), so could be used for that or for updating any property.
Caveats:
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