mnagel

need method to set properties in groovy code

Recommended Posts

I am trying to get an eventsource that reports when the firmware version has changed (this is something other tools "just do").  To do this, my "applies to" for auto.firmware_version works great, but then the script needs to use this logic:

if auto.firmware_version != auto.firmware_version.prev then
  generate event that says "firmware version has changed from old to new"
  set auto.firmware_version.prev to auto.firmware_version
end

I imagine I could use the API for the "set" operation, but using the API in logicmodules always makes me cringe due to lack of library support.  I detest maintaining the same code across many different modules as it is error-prone.  If there could be a hostProps.set method, that would be very helpful.  I understand this could be dangerous, so if it must have the same restrictions as propertysources, I can live with that.

Share this post


Link to post
Share on other sites

Some possible workarounds:

I think LM Config might be the better option for this, although I haven't played with it personally yet. It's designed for config files, but I don't see why the "config" file can't just be the version info.

Also rather than attempt to use properties to store state, you can try using a file on the collector, for example "../tmp/firmware_${hostname}.LastRun" then it would be easy to read in the script. There might be an issue if resource bounces around collectors though.

You might also be able to using Auto Discovery Instances with DataSources, which lets you set auto properties, but that might be tricky to implement.

 

Share this post


Link to post
Share on other sites

There are at least two reasons why not to use LMConfig.  First is cost -- it is a premium feature and as applicable as it might be here, it is insane to invoke an extra charge to get this basic concept implemented.  Second (more important) is that LM does not actually tell you what changed.  We work around this via the API to download, commit to a git repo and use a hook to get email on changes.  That could also work, but again seems like a lot to ask of users.

The file storage method could work, but if there is a collector failover or change you lose state.  Building redis or similar into the toolset would help with this sort of thing.

Share this post


Link to post
Share on other sites
On 10/18/2019 at 5:12 PM, mnagel said:

If there could be a hostProps.set method, that would be very helpful. 

+1 from me.

Share this post


Link to post
Share on other sites

I might be misunderstanding what you are trying, but why can't you convert the firmware version into a number, and alert on if it changes?

Share this post


Link to post
Share on other sites

Perhaps, but not everything in version strings can easily be converted into a number.  It might be a good enough workaround in this particular example (will see if I can make it work).  We still need to be able to manipulate actual strings sometimes so this facility is still desirable.

Share this post


Link to post
Share on other sites

You could set a property for the intended version (as a string), then use groovy to compare the current value to the intended value and return a 0|1. I'm not positive it would work without groovy, but you theoretically could do it without groovy and just look for the presence of a string matching a token. Groovy would def work though.

 

image.png.11655569647cfc82a78abc748a918dc1.png

Share this post


Link to post
Share on other sites

Sure, that would work, but would be super maintenance intensive.  I am just trying to do something SolarWinds can do out of the box, but as I often find, there are walls up all over the place :(.

Share this post


Link to post
Share on other sites

Yeah, if you don't want to pay for the tool specifically designed to do it, you get workarounds that are usually intensive/clunky.  LM can also do it out of the box: LMConfig.

That said, what's the pain you're trying to solve? Are you trying to know which devices are on which firmware? Are you trying to catch when someone upgrades a device without you knowing? You could do a property source to get the firmware (if it's not already there) and create auto-populated group(s) on the desired firmware(s) and another where the firmware isn't what you want it to be.  For that matter, regarding my previous though around building a datasource and comparing against properties, you could so something similar. Use a property source that runs only once a day to automatically generate ##intended.version##. Then run the DS more frequently comparing current to ##intended.version##. Differences would result in a value that could open an alarm.

Share this post


Link to post
Share on other sites

LMConfig is wrong for several reasons (which I thought I addressed earlier):

  * it is a premium feature that may not be subscribed to and if the only option here, a very large mallet for a simple problem
  * LMConfig does not report changes (we workaround this via API grabs with git email-on-push integration, but this is not a general solution for folks)

Again, this is the example that caused me to think of how to best solve the problem -- another client uses SolarWinds and they get a notice when the firmware version changes.  With strings and everything.  I thought of a way to solve it that would buy us all a general improvement and hostProps.set was the answer.  I'll take others, but LMConfig is not it.

Share this post


Link to post
Share on other sites

As far as a general table of results, that would also be awesome.  Unfortunately, the only option for that is reports since dynamic tables cannot present properties, only numeric datapoints.  Reports cannot be embedded in anything, including email, so they can't work for that.  It would be super cool to have stuff like that in a widget with a bonus if there was a "changed recently" colorization option or even just a sort by change date.

Share this post


Link to post
Share on other sites

Totally agreed that LMConfig should be included in base. That one's above my paygrade.

Unless I miss your meaning, I think LMConfig does alert on changes:

image.png.e1d9413c1354a4f25610567017676e6f.png

 

Quote

As far as a general table of results, that would also be awesome.  Unfortunately, the only option for that is reports since dynamic tables cannot present properties, only numeric datapoints.  Reports cannot be embedded in anything, including email, so they can't work for that.  It would be super cool to have stuff like that in a widget with a bonus if there was a "changed recently" colorization option or even just a sort by change date.

 

Not sure i'm following you on this. I have used what you would probably call a more-difficult-than-necessary workaround and pulled properties into a datasource as a datapoint. Would still have to be numeric, but could be shoehorned to work.

The real question is whether you think of LM as a platform or a product. It can't be both. If you think of it as a product, you're at the mercy of product management to implement the stuff you want, which isn't likely to happen unless you flex sales opportunities. If you think of it as a platform, the only real limitation should be your imagination and ability to put up with getting as close as possible to your goal while perhaps getting there a different way.

Share this post


Link to post
Share on other sites

Totally agreed that LMConfig should be included in base. That one's above my paygrade.

Unless I miss your meaning, I think LMConfig does alert on changes:

image.png.e1d9413c1354a4f25610567017676e6f.png

 

Quote

As far as a general table of results, that would also be awesome.  Unfortunately, the only option for that is reports since dynamic tables cannot present properties, only numeric datapoints.  Reports cannot be embedded in anything, including email, so they can't work for that.  It would be super cool to have stuff like that in a widget with a bonus if there was a "changed recently" colorization option or even just a sort by change date.

 

Not sure i'm following you on this. I have used what you would probably call a more-difficult-than-necessary workaround and pulled properties into a datasource as a datapoint. Would still have to be numeric, but could be shoehorned to work.

The real question is whether you think of LM as a platform or a product. It can't be both. If you think of it as a product, you're at the mercy of product management to implement the stuff you want, which isn't likely to happen unless you flex sales opportunities. If you think of it as a platform, the only real limitation should be your imagination and ability to put up with getting as close as possible to your goal while perhaps getting there a different way.

 

Don't get me wrong. hostProps.set is desperately needed.

Share this post


Link to post
Share on other sites

LMConfig does not send changes.  It can alert that "something changed", which is about as useful as a red light in your car console saying "something is wrong".

As far as the rest -- the issue is there is currently no viable way to solve this without bolting on an API method entirely outside of LM.  I can do this, but I hate being forced to do it all the time.  There are some simple fixes, like allow tables to display properties and allow setting properties without cutting and pasting 50+ lines of API code repeatedly (glad you are on that one!), that would make things much better.  I have had numerous conversations with product development folks and improvements happen all the time.  Unfortunately, most of those are the glitzy marketable types, and the lower level nuts and bolts tend to get less attention.

Share this post


Link to post
Share on other sites

Ah, I see what you mean. I think there is a FR in to have the changed lines, before lines, and after lines as tokens so they can be included in the alarm message.

I'm going to silently nod about the rest (pun intended).

Share this post


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.

Guest
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.