コード例 #1
0
def configure_ns_alerts(nsId, nsdId, nsd, vnfds, deployed_vnfs_info):
    """
    """
    # parse NSD / VNFDs to get the list of monitoring jobs to be configured and its information
    # ! we need the input of the vnfds, to have the endpoints!
    alerts_dict = {}
    alert_db_entity = {}
    # 5Growth I4 R1: AIML scaling rules have prevalence over autoscaling rules
    auto_scaling = True
    if "aimlRules" in nsd["nsd"].keys():
        for rule in nsd["nsd"]["aimlRules"]:
            if (rule["problem"] == "scaling"):
                auto_scaling = False
                log_queue.put(["DEBUG", "Scaling operation driven by AIML"])
            else:
                auto_scaling = True
                log_queue.put(
                    ["DEBUG", "Scaling operation driven by Autoscaling rules"])
    if (auto_scaling):
        log_queue.put(["DEBUG", "Configuring Alerts"])
        alerts = get_pm_alerts(nsd, deployed_vnfs_info, nsId)
        # for each job request the Monitoring Configuration Manager to configure the alert and save the alert_id
        for alert_idx, alert in enumerate(alerts):
            alert_request = {
                "alertName": alert['rule_id'],
                'query': alert['query'],
                "labels": [
                    # {
                    #     "key": "string",
                    #     "value": "string"
                    # }
                ],
                'severity': alert['severity'],
                'value': alert['value'],
                'kind': alert['kind'],
                'for': str(alert['thresholdTime']) + "s",
                'target': alert['target']
            }
            result_alert = create_alert(alert_request)
            # send alert request
            alert_id = result_alert['alertId']
            alerts[alert_idx].update({'alertId': alert_id})
            alerts[alert_idx].update({'nsId': nsId})
            alerts_dict[alert_id] = alerts[alert_idx]
            # create object to save in db alerts
            alert_db_entity = {}
            alert_db_entity['alert_id'] = alert_id
            alert_db_entity['status'] = ""
            alert_db_entity['nsd_id'] = nsdId
            alert_db_entity['ns_id'] = nsId
            alert_db_entity['rule_id'] = alert['rule_id']
            alert_db_entity['thresholdTime'] = alert['thresholdTime']
            alert_db_entity['cooldownTime'] = alert['cooldownTime']
            alert_db_entity['enabled'] = alert['enabled']
            alert_db_entity['ruleActions'] = alert['ruleActions']
            alert_db_entity['target'] = alert['target']
            alert_db_entity['timestamp'] = ""
            alert_db.create_alert_record(alert_db_entity)
    # save the list of alerts in the database
    ns_db.set_alert_info(nsId, alerts_dict)
コード例 #2
0
def delete_ns_alerts(nsId):
    """
    """
    # parse NSD / VNFDs to get the list of alerts to be configured and its information
    alerts = ns_db.get_alerts_info(nsId)
    for alert in alerts:
        delete_alert(alert)
    # delete monitor jobs from database by posting an empty list
    ns_db.set_alert_info(nsId, [])
コード例 #3
0
def configure_ns_alerts(nsId, nsdId, nsd, vnfds, deployed_vnfs_info):
    """
    """
    # parse NSD / VNFDs to get the list of monitoring jobs to be configured and its information
    # ! we need the input of the vnfds, to have the endpoints!
    alerts_dict = {}
    alert_db_entity = {}
    alerts = get_pm_alerts(nsd, deployed_vnfs_info, nsId)
    # for each job request the Monitoring Configuration Manager to configure the alert and save the alert_id
    for alert_idx, alert in enumerate(alerts):
        alert_request = {
            "alertName": alert['rule_id'],
            'query': alert['query'],
            "labels": [
                # {
                #     "key": "string",
                #     "value": "string"
                # }
            ],
            'severity': alert['severity'],
            'value': alert['value'],
            'kind': alert['kind'],
            'for': str(alert['thresholdTime']) + "s",
            'target': alert['target']
        }
        result_alert = create_alert(alert_request)
        # send alert request
        alert_id = result_alert['alertId']
        alerts[alert_idx].update({'alertId': alert_id})
        alerts[alert_idx].update({'nsId': nsId})
        alerts_dict[alert_id] = alerts[alert_idx]
        # create object to save in db alerts
        alert_db_entity = {}
        alert_db_entity['alert_id'] = alert_id
        alert_db_entity['status'] = ""
        alert_db_entity['nsd_id'] = nsdId
        alert_db_entity['ns_id'] = nsId
        alert_db_entity['rule_id'] = alert['rule_id']
        alert_db_entity['thresholdTime'] = alert['thresholdTime']
        alert_db_entity['cooldownTime'] = alert['cooldownTime']
        alert_db_entity['enabled'] = alert['enabled']
        alert_db_entity['ruleActions'] = alert['ruleActions']
        alert_db_entity['target'] = alert['target']
        alert_db_entity['timestamp'] = ""
        alert_db.create_alert_record(alert_db_entity)
    # save the list of alerts in the database
    ns_db.set_alert_info(nsId, alerts_dict)