Forum Discussion

domenicbetters's avatar
11 months ago
Solved

Is there a way to set custom property values from your groovy script in your datasource?

Hey there.  I’m relatively new to logic monitor and I received a request from a client.  

The request is as follows.  

They wanted us to be able to provide not only blocked processes alerts for their SQL dbs but also for us to provide a breakdown of what is blocking what.

My solution to this was to edit the datasource that contains the processblocked datapoint.  I made some good progress.  I was able to create a custom property field for the instances that I’m monitoring.  I then edited the script for the collector attribute so that in theory that if particular datapoint (processessblocked) shows a value of greater than 0, it uses hostSets() to change that custom property value to the blocker session ids using some custom sql script within. 

When I test it using the test button pointed at my sql server, it works exactly as i expected.  It shows the default value of the property unless it hits that block process value of 1 or more.  then the property reads with the needed info.  

However after I save the datasource.  And put this in to practice, no matter what the custom property on those instances never update or change.  
I also tried applying similar logic to the active discovery script with the same results.  Seems to work fine through testing but then nothing in the actual instance changes.  

I can post any or all of the groovy script if need be.  Is it something simple like some sort of syntax I’m not getting or am I not even in the right area to do what I’m attempting to do?

Any help would be appreciated and like I said, I’ll gladly provide any more info or code if need be.  

Thanks

  • Ok, well, it can’t be through any of the built in methods since they will only allow you to output numerical data. So, unless you can somehow map the value of “blocker” to a number, your best bet will be to write a block of code that takes the value of “blocker” and either writes it as a property or the instance description or something. We’re back to this. You’ll need to write a block of code to go in the collection script to PATCH each instance with the property/value of “blocker”. 

    LM has pretty good Python and Go SDKs, but they don’t have an SDK for their native Groovy language, so you’ll have to write this all out on your own. Even the examples on their website mostly use Python instead of Groovy to access their own API. (Ug, why isn’t python natively supported in LM yet?) You might put in a ticket to support to see if they have examples in Groovy that they can point you to. I gave up trying to get Groovy to work and most of my custom datasources are written in python.

    I realize this doesn’t help that much, but it’s the direction you’ll probably have to go.

70 Replies