Forum Discussion

drewwats's avatar
9 years ago

If I had one wish... Alert conditions being met could trigger execution of a script

 

If I had one wish... Alert conditions being met could trigger execution of a script

I know this may not be on the near-term radar, but this would be the feature that takes the product to the next level. Fortunately, most of the functionality is already in place; scripts can be ran on remote machines as a datasource. Adding the ability to run our own custom groovy (or whatever) scripts would allow error recovery actions and self-healing. Just guessing, but many customers may be willing to pay more for this. 

I just wanted to put this idea out in the forums and see what happens...

  • This is on my wishlist too as all the necessary infrastructure appears to be already in the Collector agent.  I would see it as an extension to the options available for Alert Rules.  

  • A way to solve this might be creating a datasource which runs every x minutes, depending on your needs. This datasource executes a perl script somehow similar to the one below. The example script we use to get the number of open alerts, and trigger an alert if the number reaches a specific threshold. It will need some modification...

    The script executes an rpc call to LM getting the results on which you want to trigger the execution. If the monitored value is above the threshold some action is taken. Based on the output of the script you could even set an alert on the fact that the script is executed. It's not directly bound to a datasource, but could work.

    #!/usr/bin/env perl
    
    # Replace  parameters below to suit your situation
    $userName="myUsername";
    $password="mySecret";
    $sitename="mySite";
    $siteurl="mySite.logicmonitor.com";
    $groupId="1";
    
    $curlopt="'https://$siteurl/santaba/rpc/getAlerts?c=$sitename&u=$userName&p=$password&hostGroupId=$groupId'";
    $curlrun="env curl -s $curlopt";
    
    # Now we have the command to run
    $alertwarn=0;
    $alerterr=0;
    $alertcrit=0;
    
    open(FILE, "-|", $curlrun) or die $!;
    
    while (<FILE>) {
      $alertwarn++ if /warn/;
      $alerterr++ if /error/;
      $alertcrit++ if /critical/;
    }
    close $handle;
    
    $alerttotal=$alertwarn+$alerterr+$alertcrit;
    
    if ($alerttotal > 30) {
      # execute any required action
      # execution more action 
      $scriptresult=1;
    } else {
      $scriptresult=0;
    }
    
    print "ScriptResult" . $scriptresult . "\n";