Ejemplo n.º 1
0
def unlink_alarm_and_notification(event_rule_id):
    HEADERS['X-Auth-Token'] = vnf_data.get_appformix_token()

    url = alarm_notification_url
    resp = requests.get(url=url, headers=HEADERS, verify=False)
    rjson = resp.json()

    links = rjson['ServiceKeyEventRuleProfile']
    link_id = ''
    for item in links:
        if item['ServiceKeyEventRule']['EventRuleId'] == event_rule_id:
            link_id = item['ServiceKeyEventRule']['Id']
            continue

    delete_url = ''
    if link_id != '':
        delete_url = url + '/' + link_id
        resp = requests.get(url=delete_url, headers=HEADERS, verify=False)
    else:
        print "Id of notification_alarm is invalid: %s" % (link_id)

    if resp.status_code != 200:
        rjson = resp.json()
        print('DELETE fail to unlink Notification Service {}: {}'.format(
            delete_url, resp.text))
        return False

    print "... Removed link between Notification and alarm"
    return True
Ejemplo n.º 2
0
def create_custom_notify():
    HEADERS['X-Auth-Token'] = vnf_data.get_appformix_token()
    data = {
        "NotificationEndpoint": "http://192.168.250.4:9999",
        "NotificationSystemType": "Custom_Notifier",
        "ServiceKey": "webhook-service",
        "Verify": "False",
        "ServiceName": "webhook-service"
    }
    try:
        resp = requests.post(url=notification_url,
                             headers=HEADERS,
                             data=json.dumps(data),
                             verify=False)
        if resp.status_code != 200:
            rjson = resp.json()
            if ('already exists' in rjson['message']):
                print 'Alarm exists in AppFormix'
                return True
            print('Post fail to add Notification Service {}: {}'.format(
                notification_url, resp.text))
            return False
        time.sleep(3)
        print "... Successfully added Custom Notification Service"
        return 'webhook-service'
    except Exception as e:
        print '... Exception in Adding custom notification service {}'.format(
            e)
        return False
Ejemplo n.º 3
0
def remove_alarm(data):
    HEADERS['X-Auth-Token'] = vnf_data.get_appformix_token()
    try:
        durl = alarm_url + '/' + data
        resp = requests.delete(url=durl, headers=HEADERS, verify=False)
        if resp.status_code != 200:
            print('Post fail to alarms {}: {}'.format(durl, resp.text))
            return False
        task_id = json.loads(resp.text).get('task_id')
        utils.poll_for_task_state(task_url, task_id)
    except Exception as e:
        print '... Exception in remove the alarm rule {}'.format(e)
        return False
    print '... Successfully deleted alarm'
    return True
Ejemplo n.º 4
0
def get_custom_notify():
    HEADERS['X-Auth-Token'] = vnf_data.get_appformix_token()
    try:
        url = notification_url + '/webhook-service'
        resp = requests.get(url=url, headers=HEADERS, verify=False)
        #print resp.status_code
        if resp.status_code == 404:
            create_custom_notify()

        ### Custom Service exists ###
        elif resp.status_code == 200:
            rjson = resp.json()
            #print rjson
            if rjson['ServiceKeyUser']['ServiceKey'] == 'webhook-service':
                return 'webhook-service'
    except Exception as e:
        print 'Exception in Getting custom notification service {}'.format(e)
        return False
Ejemplo n.º 5
0
def delete_single_network_device(device_id):
    HEADERS['X-Auth-Token'] = vnf_data.get_appformix_token()
    try:
        resp = requests.delete(url=url + "/{0}".format(device_id),
                               data=None,
                               headers=HEADERS,
                               verify=False)
        if resp.status_code != 200:
            print('Delete failed to network_device_definition {}: {}'.format(
                url, resp.text))
            return False
        task_id = json.loads(resp.text).get('task_id')
        utils.poll_for_task_state(task_url, task_id)
    except Exception as e:
        print 'Exception in deleting the network_device config {}'.format(e)
        return False
    print 'Successfully deleted Network Device - {}'.format(device_id)
    return True
Ejemplo n.º 6
0
def link_alarm_and_notification(event_rule_id):
    HEADERS['X-Auth-Token'] = vnf_data.get_appformix_token()
    data = {"EventRuleId": event_rule_id, "ServiceKey": 'webhook-service'}
    url = alarm_notification_url
    resp = requests.post(url=url,
                         headers=HEADERS,
                         data=json.dumps(data),
                         verify=False)
    if resp.status_code != 200:
        #print data
        rjson = resp.json()
        if ('already exists' in rjson['message']):
            print 'Alarm exists in AppFormix'
            return True
        print('Post fail to link Notification Service {}: {}'.format(
            url, resp.text))
        return False
    print "... Added Notification service to alarm"
    return True
Ejemplo n.º 7
0
def post_alarm(data):
    HEADERS['X-Auth-Token'] = vnf_data.get_appformix_token()
    try:
        resp = requests.post(url=alarm_url,
                             data=data,
                             headers=HEADERS,
                             verify=False)
        if resp.status_code != 200:
            rjson = resp.json()
            if ('already exists' in rjson['message']):
                print '... Alarm already exists in AppFormix'
                return True
            print('Post fail to alarms {}: {}'.format(alarm_url, resp.text))
            return False
        task_id = json.loads(resp.text).get('task_id')
        utils.poll_for_task_state(task_url, task_id)
    except Exception as e:
        print 'Exception in post the alarm rule {}'.format(e)
        return False
    print '... Successfully added alarm'
    return True
Ejemplo n.º 8
0
def post_single_network_device(data):
    HEADERS['X-Auth-Token'] = vnf_data.get_appformix_token()
    try:
        #print "/POST DATA: \n%s\n####\n" %data
        resp = requests.post(url=url, data=data, headers=HEADERS, verify=False)
        if resp.status_code != 200:
            rjson = resp.json()
            if ('already exists' in rjson['message']):
                print 'Device exists in AppFormix'
                return True
            print('Post fail to network_device_definition {}: {}'.format(
                url, resp.text))
            return False
        task_id = json.loads(resp.text).get('task_id')
        utils.poll_for_task_state(task_url, task_id)
    except Exception as e:
        traceback.print_exc()
        print 'Exception in post the network_device config {}'.format(e)
        return False
    print 'Successfully added Network Device'
    return True