Forum Discussion

mnagel's avatar
mnagel
Icon for Professor rankProfessor
5 years ago

need method to set properties in groovy code

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.

20 Replies

  • Anonymous's avatar
    Anonymous

    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:

     

    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.

  • Anonymous's avatar
    Anonymous

    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:

     

    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.

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

  • Anonymous's avatar
    Anonymous

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

  • On 10/19/2019 at 3:42 AM, mnagel said:

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

     +1 from me

  • I am also looking for this feature.

    My use case is different but basically it boils down to "How can I maintain a variable between executions of a script"

    I will be doing the 'file in tmp' suggestion, but as stated this is flawed as it might disappear, get cleaned out, etc. My use case is not sensitive to failure so this will work, but a hostProps.set would be ideal.

    For a more sensitive flow that required maintaining of state, I did a API request to the devices endpoint in Logic monitor to 'set' properties with a limited api user account created for this purpose. Basically got a 'two way flow' working: LM -> Collector and Collector -> LM (though the API). It was so dirty I showered after.

  • Anonymous's avatar
    Anonymous

    I can post the link later but there is a script caching capability that will allow you to carry values from one run of a script to the next through a cache on the collector.

  • Does this work between collectors in ABCG? Like if a device balances to another collector or if there is a failover/failback?

  • Anonymous's avatar
    Anonymous

    No. ABCG don't share a single cache.

    You should have logic in your code to compensate when the cache doesn't have the data so that it can be fetched brand new if needed. Typical cache logic is build for performance so you don't have to do "heavy" calls for stuff that doesn't change that often. But if that thing doesn't exist in the cache you should do the heavy call and store it in cache for subsequent runs.