def rules_delete(Id): db = Db(config.alerting_db) try: db.delete_rule(int(Id)) except Exception, e: # pylint: disable=W0703 errors["rules_delete"] = ("Couldn't delete rule: %s" % e, traceback.format_exc())
def rules_list(): db = Db(config.alerting_db) if 'rules' in errors: del errors['rules'] try: body = template('templates/body.rules', errors=errors, rules=db.get_rules()) except Exception, e: errors['rules'] = ("Couldn't list rules: %s" % e, traceback.format_exc())
def rules_add_submit(): expr = request.forms.get('expr') val_warn = float(request.forms.get('val_warn')) val_crit = float(request.forms.get('val_crit')) dest = request.forms.get('dest') if 'rules_add' in errors: del errors['rules_add'] try: rule = Rule(None, expr, val_warn, val_crit, dest) db = Db(config.alerting_db) db.add_rule(rule) except Exception, e: # pylint: disable=W0703 errors["rules_add"] = ("Couldn't add rule: %s" % e, traceback.format_exc())
def rules_add(expr=''): form = RuleAddForm(request.forms) if request.method == 'GET': form.expr.data = expr if request.method == 'POST' and form.validate(): try: if 'rules_add' in errors: del errors['rules_add'] rule = rule_from_form(form) db = Db(config.alerting_db) db.add_rule(rule) except Exception, e: # pylint: disable=W0703 errors["rules_add"] = ("Couldn't add rule: %s" % e, traceback.format_exc()) return redirect('/rules')
def rules_edit(Id=None): db = Db(config.alerting_db) if Id is not None: rule = db.get_rule(int(Id)) else: rule = db.get_rule(int(request.forms['Id'])) form = RuleEditForm(request.forms, rule) if request.method == 'POST' and form.validate(): try: if 'rules_add' in errors: del errors['rules_add'] form.populate_obj(rule) db = Db(config.alerting_db) db.edit_rule(rule) except Exception, e: # pylint: disable=W0703 errors["rules_add"] = ("Couldn't add rule: %s" % e, traceback.format_exc()) return redirect('/rules')
def rules_view(Id): db = Db(config.alerting_db) rule = db.get_rule(int(Id)) body = template('templates/body.rule', errors=errors, rule=rule) return render_page(body)
import structured_metrics app_dir = os.path.dirname(__file__) if app_dir: os.chdir(app_dir) import config config = make_config(config) import preferences if not config.alerting: print "alerting disabled in config" os.exit(0) s_metrics = structured_metrics.StructuredMetrics(config) db = Db(config.alerting_db) rules = db.get_rules() output = EmailOutput(config) def submit_maybe(result): if result.to_report(): output.submit(result) db.save_notification(result) print "sent notification!" else: print "no notification" for rule in rules: