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
- Create an API token and put in the note that this is for the alerting_status PS.
- Take the ID and key and store them as properties on your root with the name alerting_status.id and alerting_status.key, respectively.
- Create a propertysource with appliesto of “alerting_status.id && alerting_status.key”
- Use the above as the code.
- 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.