TechnologyAugust 22, 2012

Integrating Alerts via the OpsCenter REST API

Mike Bulman
Mike Bulman
Integrating Alerts via the OpsCenter REST API
import urllib, json
def getUrl(path):
    url = 'http://localhost:8888/%s' % path
    contents = urllib.urlopen(url).read()
    return json.loads(contents)
load = getUrl('MyCluster/nodes/')
print load
# Prints: 0.32
fired_alerts = getUrl('MyCluster/alerts/fired')
    "alert_rule_id": "80fc5e0a-355a-4f8f-86ef-5de8fd8fb5bb",
    "node": "",
    "current_value": 1234,
    "first_fired": 1345575248
alert_rules = getUrl('MyCluster/alert-rules')
rules_map = dict((rule['id'], rule) for rule in alert_rules)
for alert in fired_alerts:
    rule = rules_map.get(alert['alert_rule_id'])
    doSomething(alert, rule)
def doSomething(alert, rule):                                                                       
    if rule['type'] == 'rolling-avg':                                                               
        msg = "%s on node %s is at %.2f" %
                        (rule['metric'], alert['node'], alert['current_value'])
    elif rule['type'] == 'node-down':
        msg = "Node %s is down" % alert['node']
    datetime_str = time.strftime("%m/%d/%Y %H:%M:%S %Z",
    msg += " (since %s)" % datetime_str
    print msg
Discover more

One-stop Data API for Production GenAI

Astra DB gives JavaScript developers a complete data API and out-of-the-box integrations that make it easier to build production RAG apps with high relevancy and low latency.