def main(): execute('send log Application subscriber_listener.py started') logging.basicConfig( filename='application_run.log', level=logging.DEBUG, format= '%(asctime)s.%(msecs)03d %(levelname)s %(module)s - %(funcName)s: %(message)s', datefmt='%Y-%m-%d %H:%M:%S') global IOS_XE_HOST_IP, DEVICE_HOSTNAME, DEVICE_LOCATION # retrieve the ios xe device management ip address, Gi0/0 IOS_XE_HOST_IP = execute('sh run int gi1 | in ip address').split(' ')[3] # retrieve the device hostname using RESTCONF DEVICE_HOSTNAME = netconf_restconf.get_restconf_hostname( IOS_XE_HOST_IP, IOS_XE_USER, IOS_XE_PASS) print(str('\nThe device hostname: ' + DEVICE_HOSTNAME)) """ The following commands are if Cisco DNA Center is available # get DNA C AUth JWT token dnac_token = dnac_apis.get_dnac_jwt_token(DNAC_AUTH) DEVICE_LOCATION = dnac_apis.get_device_location(DEVICE_HOSTNAME, dnac_token) print(str("\nDevice Location: " + DEVICE_LOCATION)) """ # init the PubNub channel pubnub = pubnub_init(DEVICE_HOSTNAME) pubnub.add_listener(MySubscribeCallback()) pubnub.subscribe().channels(CHANNEL).execute()
auth=(SNOW_DEV, SNOW_PASS), data=json.dumps(payload), headers=headers) print('\nServiceNow REST API call response: ' + str(response.status_code)) incident_json = response.json() incident_number = incident_json['result']['number'] logging.debug('Incident created: ' + incident_number) return incident_number # main application logging.basicConfig( filename='application_run.log', level=logging.DEBUG, format= '%(asctime)s.%(msecs)03d %(levelname)s %(module)s - %(funcName)s: %(message)s', datefmt='%Y-%m-%d %H:%M:%S') device_name = netconf_restconf.get_restconf_hostname(IOS_XE_HOST, IOS_XE_USER, IOS_XE_PASS) comments = ('The device with the name: ' + str(device_name) + ' created this test incident using APIs') incident = create_incident('Device Notification - ' + str(device_name), comments, SNOW_DEV, 3) print('Created ServiceNow Incident with the number: ', str(incident)) print('\nEnd Application Run')
f = open(new_cfg_fn) new_cfg = f.readlines() f.close diff = compare_configs(old_cfg, new_cfg) print diff f = open('/bootflash/BlitzAdvanced/ios_xe_programmability/diff', 'w') f.write(diff) f.close if diff != '': # retrieve the device hostname using RESTCONF device_name = netconf_restconf.get_restconf_hostname( DEV_IP, DEV_USER, DEV_PASS) # retrieve the serial number using Python cli device_info = cli("sh ver | in Processor board ID") device_info_list = device_info.split(' ') device_sn = device_info_list[-1] # retrieve the device location using DNA C REST APIs # dnac_token = dnac_apis.get_dnac_jwt_token(DNAC_AUTH) # location = dnac_apis.get_device_location(device_name, dnac_token) location = "Lake Oswego/OR/USA" # define the incident description and comment short_description = "Unauthorized Configuration Change - IOS XE Automation" comment = "The device with the name: " + device_name + "\n has detected an Unauthorized Configuration Change" comment += "\n\nThe device SN is: " + device_sn
parser = argparse.ArgumentParser() parser.description = 'The monitored route the application will alert on' parser.add_argument('route') args = parser.parse_args() monitored_route = args.route DNAC_AUTH = HTTPBasicAuth(DNAC_USER, DNAC_PASS) global IOS_XE_HOST_IP, DEVICE_HOSTNAME, DEVICE_LOCATION # retrieve the ios xe device management ip address, Gi0/0, not the VPG IP address IOS_XE_HOST_IP = execute('sh run int gi1 | in ip address').split(' ')[3] # retrieve the device hostname using RESTCONF DEVICE_HOSTNAME = netconf_restconf.get_restconf_hostname( IOS_XE_HOST_IP, IOS_XE_USER, IOS_XE_PASS) print(str('\nThe device hostname: ' + DEVICE_HOSTNAME)) # create a new Service Now incident description = 'Monitored route: ' + monitored_route + ' Lost, device hostname: ' + DEVICE_HOSTNAME comment = 'The device with the name: ' + DEVICE_HOSTNAME + ' has detected the loss of a critical route' comment += '\n\nThe route: ' + monitored_route + ' - is missing from the routing table' snow_incident = service_now_apis.create_incident(description, comment, SNOW_DEV, 1) """ # The following commands to be use when Cisco DNA Center is available # get DNA C AUth JWT token
parser = argparse.ArgumentParser() parser.description = 'The monitored route the application will alert on' parser.add_argument('route') args = parser.parse_args() monitored_route = args.route DNAC_AUTH = HTTPBasicAuth(DNAC_USER, DNAC_PASS) execute('send log "monitor_route.py" Application Run started') print(str('\n\n"monitor_route.py" Application Run started')) # retrieve the ios xe device management ip address, Gi0/0, not the VPG IP address ios_xe_host_ip = execute('sh run int gi1 | in ip address').split(' ')[3] # retrieve the device hostname using RESTCONF device_hostname = netconf_restconf.get_restconf_hostname( ios_xe_host_ip, IOS_XE_USER, IOS_XE_PASS) print(str('\nThe device hostname: ' + device_hostname)) # create a new Service Now incident description = 'Monitored route: ' + monitored_route + ' Lost, device hostname: ' + device_hostname comment = 'The device with the name: ' + device_hostname + ' has detected the loss of a critical route' comment += '\n\nThe route: ' + monitored_route + ' - is missing from the routing table' snow_incident = service_now_apis.create_incident(description, comment, SNOW_DEV, 1) # The following commands to be use when Cisco DNA Center is available # get DNA C AUth JWT token dnac_token = dnac_apis.get_dnac_jwt_token(DNAC_AUTH)