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

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.