WEBVTT

1
00:00.000 --> 00:04.680
Now so far we have been able to send show commands to our target devices.

2
00:04.680 --> 00:08.720
Now whilst this is useful for you as a human engineer to actually be able to

3
00:08.720 --> 00:09.200
see the

4
00:09.200 --> 00:13.860
output of these commands, quite honestly this is not the best data to work with

5
00:13.860 --> 00:15.000
programmatically

6
00:15.000 --> 00:19.680
quite simply because the information comes back just as a regular string blob.

7
00:19.680 --> 00:24.020
Now we know with respect to Python it's much better to work with this type of

8
00:24.020 --> 00:24.720
structure

9
00:24.720 --> 00:27.760
data whereby we have access to these Python objects.

10
00:27.760 --> 00:31.840
Now the cool thing is with NetMico there actually is integration with something
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

10
00:27.760 --> 00:31.840
Now the cool thing is with NetMico there actually is integration with something

11
00:31.840 --> 00:32.400
known as

12
00:32.400 --> 00:34.120
text FSM.

13
00:34.120 --> 00:38.420
So what has happened is that the network automation community online has

14
00:38.420 --> 00:39.160
utilized this

15
00:39.160 --> 00:44.700
particular utility known as text FSM and generated particular templates that

16
00:44.700 --> 00:46.040
actually transfer

17
00:46.040 --> 00:51.430
or rather transform should I say transform that regular string like data into

18
00:51.430 --> 00:52.240
structure

19
00:52.240 --> 00:54.160
data that we can easily parse.

20
00:54.160 --> 00:57.120
Let me show you what I mean. If you just happen to search for text FSM

21
00:57.120 --> 00:58.080
templates and click

22
00:58.080 --> 01:01.560
on this link here within the network to code get up.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

22
00:58.080 --> 01:01.560
on this link here within the network to code get up.

23
01:01.560 --> 01:05.230
See if you just scroll on down and go into this folder here for NTC templates

24
01:05.230 --> 01:05.560
and then

25
01:05.560 --> 01:07.080
templates once again.

26
01:07.080 --> 01:10.380
What you're going to see are tons and tons and tons of these text files, some

27
01:10.380 --> 01:10.640
for

28
01:10.640 --> 01:14.120
Arista, some for Junotware, some for Cisco, so on and so forth.

29
01:14.120 --> 01:18.060
They're pretty much if you scroll on down to Cisco iOS, like right here, what

30
01:18.060 --> 01:18.760
we're actually

31
01:18.760 --> 01:22.720
seeing here is all of the available show commands that these templates have

32
01:22.720 --> 01:23.680
been configured

33
01:23.680 --> 01:27.400
to translate the string data into these Python objects.

34
01:27.400 --> 01:31.600
So say for example, we wanted to go and send a show command for SNMP.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

34
01:27.400 --> 01:31.600
So say for example, we wanted to go and send a show command for SNMP.

35
01:31.600 --> 01:32.920
Let's check this here.

36
01:32.920 --> 01:36.400
So scrolling on down we have the command show SNMP community.

37
01:36.400 --> 01:41.520
If we open this up, what we see here is this funny looking information.

38
01:41.520 --> 01:44.370
Now this looked pretty confusing and the good thing is we don't have to care

39
01:44.370 --> 01:44.840
anything

40
01:44.840 --> 01:45.840
about it.

41
01:45.840 --> 01:46.840
We're not trying to write it.

42
01:46.840 --> 01:48.160
We just want to use it.

43
01:48.160 --> 01:49.160
So here's the thing.

44
01:49.160 --> 01:51.040
NetMico makes it really quite easy.

45
01:51.040 --> 01:56.450
So if I just copy over example five and I create a new one called example seven

46
01:56.450 --> 01:56.800
dot

47
01:56.800 --> 01:58.280
py, let's open this up.

48
01:58.280 --> 01:59.280
Okay.

49
01:59.280 --> 02:00.280
So check this out.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

49
01:59.280 --> 02:00.280
So check this out.

50
02:00.280 --> 02:01.280
All we're doing is what we saw before.

51
02:01.280 --> 02:05.180
We're going to open up our file right here, look through all of our devices and

52
02:05.180 --> 02:05.480
send

53
02:05.480 --> 02:06.480
the show command.

54
02:06.480 --> 02:09.400
Now the show command we're sending here is show IP interface brief.

55
02:09.400 --> 02:15.520
Let's actually change this to be show, rather than snow show SNMP community.

56
02:15.520 --> 02:16.760
Okay, save this.

57
02:16.760 --> 02:21.960
So let's quickly just try the actual script right here and to enter and look at

58
02:21.960 --> 02:22.240
this right

59
02:22.240 --> 02:23.240
here.

60
02:23.240 --> 02:26.710
We get the output for the first device as well as a second, third and then at

61
02:26.710 --> 02:27.280
the bottom

62
02:27.280 --> 02:28.280
the fourth device.

63
02:28.280 --> 02:31.710
Now right now we can't just call these dictionary keys to return particular
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

63
02:28.280 --> 02:31.710
Now right now we can't just call these dictionary keys to return particular

64
02:31.710 --> 02:32.440
pieces of data

65
02:32.440 --> 02:35.240
because it is all just regular string data.

66
02:35.240 --> 02:40.420
However, if we just use this simple option by saying comma and then say use

67
02:40.420 --> 02:41.720
text FSM and

68
02:41.720 --> 02:43.440
specify the value is true.

69
02:43.440 --> 02:47.360
If I just save this and run the script again and to enter now we actually see

70
02:47.360 --> 02:47.800
here the

71
02:47.800 --> 02:50.600
information is coming back as structured data.

72
02:50.600 --> 02:53.360
And if I just to make it look a little bit more readable, what I will just say

73
02:53.360 --> 02:53.640
is pit

74
02:53.640 --> 02:54.640
three install rich.

75
02:54.640 --> 02:57.680
This is just a library to make things prettier to look at.

76
02:57.680 --> 03:01.880
And what I will say here is from rich import print as our prints.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

76
02:57.680 --> 03:01.880
And what I will say here is from rich import print as our prints.

77
03:01.880 --> 03:04.480
And as opposed to printing the result, I will our print results.

78
03:04.480 --> 03:06.000
Okay, let's try this again.

79
03:06.000 --> 03:07.800
So now this looks a little bit easier to look at.

80
03:07.800 --> 03:08.800
Okay.

81
03:08.800 --> 03:12.040
So what we can actually see here is the first element is actually a list

82
03:12.040 --> 03:12.800
because we see

83
03:12.800 --> 03:17.040
your square braces and then inside that list there is one object, a dictionary.

84
03:17.040 --> 03:21.030
And then we have access to your keys to pretty much if we call list index zero,

85
03:21.030 --> 03:21.480
this will

86
03:21.480 --> 03:23.120
strip away the outer list.

87
03:23.120 --> 03:26.160
So print results and then square brackets zero.

88
03:26.160 --> 03:27.160
Try it again.

89
03:27.160 --> 03:28.160
Arow up.

90
03:28.160 --> 03:29.160
Look at this right here.

91
03:29.160 --> 03:31.160
We're now getting back a dictionary for each of our devices.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

91
03:29.160 --> 03:31.160
We're now getting back a dictionary for each of our devices.

92
03:31.160 --> 03:34.400
So say for example, I want to grab the name key.

93
03:34.400 --> 03:37.000
What I can now do is easily programmatically access this.

94
03:37.000 --> 03:38.000
So check this out.

95
03:38.000 --> 03:39.000
Grab the name key.

96
03:39.000 --> 03:40.000
Arow up.

97
03:40.000 --> 03:41.000
Try again.

98
03:41.000 --> 03:44.760
Second, third and the fourth test community is coming through.

99
03:44.760 --> 03:48.300
Now just for posterity, let me just happen to change this on one of the devices

100
03:48.300 --> 03:48.600
.

101
03:48.600 --> 03:50.600
Let's need to go to device number three here.

102
03:50.600 --> 03:51.600
Let's open this up.

103
03:51.600 --> 03:54.680
Print enable mode show run section SNMP.

104
03:54.680 --> 04:00.660
Now if I just say configure terminal and I say no SNMP server community test
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

104
03:54.680 --> 04:00.660
Now if I just say configure terminal and I say no SNMP server community test

105
04:00.660 --> 04:01.600
community

106
04:01.600 --> 04:04.280
are all so basically I've removed it.

107
04:04.280 --> 04:07.600
And what I will now do is just simply creating new SNMP configuration on this

108
04:07.600 --> 04:08.240
particular

109
04:08.240 --> 04:09.240
device.

110
04:09.240 --> 04:11.240
Let's call this one random community.

111
04:11.240 --> 04:12.240
Okay.

112
04:12.240 --> 04:13.960
So it's not going to be the same as the others.

113
04:13.960 --> 04:15.960
So let's just try to run this.

114
04:15.960 --> 04:20.110
Here's device one device to device three is different and device four is still

115
04:20.110 --> 04:20.720
the same.

116
04:20.720 --> 04:24.400
So because we now have access to this data programmatically, we can ultimately

117
04:24.400 --> 04:25.480
use conditional

118
04:25.480 --> 04:28.280
logic to run tests against their network.

119
04:28.280 --> 04:32.470
So what I can do is as opposed to just printing this data, I can just say if
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

119
04:28.280 --> 04:32.470
So what I can do is as opposed to just printing this data, I can just say if

120
04:32.470 --> 04:33.520
this particular

121
04:33.520 --> 04:37.120
object that we're parsing out, which is ultimately the name key, if that equals

122
04:37.120 --> 04:37.800
the value

123
04:37.800 --> 04:44.120
of test community, what I can do is print out this device past the test for SN

124
04:44.120 --> 04:44.720
MP.

125
04:44.720 --> 04:49.980
However, if it doesn't have that value of print outs, this device has failed

126
04:49.980 --> 04:50.640
the test

127
04:50.640 --> 04:51.640
for SNMP.

128
04:51.640 --> 04:56.060
So now because I have this structured data, I can access very precise details

129
04:56.060 --> 04:57.120
programmatically

130
04:57.120 --> 04:59.800
and now run tests against the state of my network.

131
04:59.800 --> 05:01.120
So let's try this here.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

131
04:59.800 --> 05:01.120
So let's try this here.

132
05:01.120 --> 05:05.110
First device pass, second device passes, third device fails the test and the

133
05:05.110 --> 05:06.000
fourth device

134
05:06.000 --> 05:07.080
passes the test.

135
05:07.080 --> 05:10.480
So quite simply, I see, oh, device number three has a problem.

136
05:10.480 --> 05:11.480
What am I going to do?

137
05:11.480 --> 05:12.480
Well, go and fix it.

138
05:12.480 --> 05:16.170
Let's go and just say no for the random community and what I will do is I'll

139
05:16.170 --> 05:17.080
put the correct

140
05:17.080 --> 05:21.480
configuration on of test community to now it should be fixed.

141
05:21.480 --> 05:25.380
If I rerun my little test and to enter device one and two passes expected

142
05:25.380 --> 05:26.480
device three also

143
05:26.480 --> 05:29.200
passes now as well as device number four.

144
05:29.200 --> 05:32.920
So just imagine the possibilities now all of your show commands, you can access
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

144
05:29.200 --> 05:32.920
So just imagine the possibilities now all of your show commands, you can access

145
05:32.920 --> 05:33.280
the data

146
05:33.280 --> 05:37.540
programmatically and now use Python to write very particular logic to test the

147
05:37.540 --> 05:38.200
state of all

148
05:38.200 --> 05:41.000
of your devices no matter how many devices you have.

149
05:41.000 --> 05:45.460
Say for example, you've got 10 devices, 100 devices, 1000 devices, it does not

150
05:45.460 --> 05:46.000
matter.

151
05:46.000 --> 05:49.730
You can just sit back with your coffee, run your script and let Python find out

152
05:49.730 --> 05:50.120
if your

153
05:50.120 --> 05:52.480
network is actually correctly configured.
