Forum Discussion

lroussell's avatar
lroussell
Icon for Neophyte rankNeophyte
2 years ago

Feature Request - New property to indicate monitoring is disabled

I have a problem where my users will disable alerting on a resource that has been removed from the environment instead of deleting it. Or they may disable alerting and forget to re-enable it. With alerting disabled, my no-data datapoint alerts never trigger. In the case of removed devices, the resources just hang out there forever and never get removed because they don’t show up on my data collection failures dashboard. Devices for which the user intended to re-enable alerting eventually meet the same fate unless they go down and we don’t know about it. Either of these outcomes is bad news.

It would be nice if there were a property which would indicate that alerting for a resource has been disabled. As far as I am aware, there is currently no way to do this. Then I could create a dynamic group of devices which have monitoring disabled. As devices are populated in the group, I can investigate them. As it stands now, I have to go manually hunt them down.

  • Anonymous's avatar
    Anonymous

    The idea with it being a property is that you could create a dynamic group and either list that group on the dashboard or use a big number widget to show the number of disabled devices?

    You could write a propertysource to query the API for the “disableAlerting” attribute on the device and store that as a property:

    import javax.crypto.Mac
    import javax.crypto.spec.SecretKeySpec
    import org.apache.commons.codec.binary.Hex
    import com.santaba.agent.groovyapi.http.*
    import groovy.json.JsonSlurper
    import groovy.json.JsonOutput

    accessId = hostProps.get("alerting_status.id")
    accessKey = hostProps.get("alerting_status.key")

    def lm_get_request(_resourcePath, _queryParams, _accessId = accessId, _accessKey = accessKey) {
    account = ''
    File file = new File('../conf/agent.conf')
    file.text.eachLine{if (it =~ /company=/){ account = it.split('=')[1].trim() }}
    url = "https://" + account + ".logicmonitor.com" + "/santaba/rest"
    httpClient = HTTP.open(account + ".logicmonitor.com", 443)
    headers=calcSignature('GET',_resourcePath,accessKey,accessId) // calcSignature defined below
    headers.put("X-Version", "3")
    response = httpClient.get(url + _resourcePath + _queryParams, headers)
    responseBody = httpClient.getResponseBody()
    try {allResponse = new JsonSlurper().parseText(responseBody)}
    catch (Exception e) {allResponse = responseBody}
    return allResponse
    }

    def calcSignature(_verb,_resourcePath,_accessKey,_accessId,_data = '') {
    epoch = System.currentTimeMillis()
    requestVars = _verb + epoch + _data + _resourcePath
    hmac = Mac.getInstance("HmacSHA256")
    secret = new SecretKeySpec(_accessKey.getBytes(), "HmacSHA256")
    hmac.init(secret)
    hmac_signed = Hex.encodeHexString(hmac.doFinal(requestVars.getBytes()))
    signature = hmac_signed.bytes.encodeBase64()
    headers = [:]
    headers.put("Authorization" , "LMv1 " + _accessId + ":" + signature + ":" + epoch)
    return headers
    }

    lm_get_request("/device/devices/${hostProps.get('system.deviceId')}",'?fields=disableAlerting').each{println(it)}
    return 0
    1. Create an API token and put in the note that this is for the alerting_status PS.
    2. Take the ID and key and store them as properties on your root with the name alerting_status.id and alerting_status.key, respectively.
    3. Create a propertysource with appliesto of “alerting_status.id && alerting_status.key”
    4. Use the above as the code.
    5. Test it then send it.

    It should create a property called “auto.disablealerting” with a value of true or false. YMMV, test in sandbox, with great power, yadda-yadda-yadda. FYI, a value of false means that alerting is not disabled. A value of true means alerting is disabled.