1
+ import devpackage .DataProvider as DeviceDataProvider
2
+ import simplejson
3
+
4
+ dp = DeviceDataProvider .DeviceDataProvider (context )
5
+ ctype = DeviceDataProvider .CollectionType
6
+
7
+ def main ():
8
+ dp .job_execution_log ("Executing the show interfaces summary script" )
9
+
10
+ # Capture script inputs
11
+ #inputs = context.get("INPUTS")
12
+ #parsed_json = simplejson.loads(inputs)
13
+
14
+ pre_result = dp .get_fields_as_dict_list ("show interfaces summary" , ctype .PRE , "UP" )
15
+ post_result = dp .get_fields_as_dict_list ("show interfaces summary" , ctype .POST , "UP" )
16
+ print (pre_result )
17
+ print (post_result )
18
+
19
+ dp .job_execution_log ("Analyzing show interfaces summary" )
20
+
21
+ # Get pre from command results
22
+ preUP = ""
23
+ for x in pre_result :
24
+ preUP = x .get ("UP" )
25
+ break
26
+
27
+ # Get post from command results
28
+ postUP = ""
29
+ for x in post_result :
30
+ postUP = x .get ("UP" )
31
+ break
32
+
33
+ dp .job_execution_log ("UP Number in command " + preUP )
34
+ dp .job_execution_log ("UP Number in command " + postUP )
35
+
36
+ # Determine post results
37
+ passmsg = preUP + " less than or equal " + postUP
38
+ errmsg = preUP + " grather than " + postUP
39
+ if preUP <= postUP :
40
+ dp .add_post_status_field ("All Types" , preUP , passmsg , "Passed" )
41
+ dp .publish_post_status (True , "Analysis Check passed" )
42
+ elif preUP > postUP :
43
+ dp .add_post_status_field ("All Types" , preUP , errmsg , "Failed" )
44
+ dp .publish_post_status (False , "Analysis Check failed" )
45
+
46
+ json = dp .publish_status ()
47
+ return json
0 commit comments