WEBVTT

1
00:00.000 --> 00:00.500 align:middle line:84%


2
00:00.500 --> 00:02.790 align:middle line:90%
That last Nugget was jam
packed full of stuff.

3
00:02.790 --> 00:04.920 align:middle line:84%
We talked about HTTP methods.

4
00:04.920 --> 00:07.170 align:middle line:90%
We talked about
try-catch blocks.

5
00:07.170 --> 00:09.730 align:middle line:90%
We talked about
if-then statements.

6
00:09.730 --> 00:11.460 align:middle line:90%
These are things
called control flow,

7
00:11.460 --> 00:12.918 align:middle line:90%
and that's really,
really important

8
00:12.918 --> 00:15.300 align:middle line:90%
to understand so that
you can write clean code

9
00:15.300 --> 00:17.400 align:middle line:90%
when it comes to
doing Python scripts.

10
00:17.400 --> 00:20.310 align:middle line:90%
Now that we've logged in though
and we're holding that token

11
00:20.310 --> 00:23.370 align:middle line:90%
in a variable, we can create
our next request, which

12
00:23.370 --> 00:26.820 align:middle line:90%
is a get request to retrieve
the list of applications,

13
00:26.820 --> 00:28.530 align:middle line:90%
leveraging that
token that we just

14
00:28.530 --> 00:30.180 align:middle line:84%
got in the previous Nugget.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

14
00:28.530 --> 00:30.180 align:middle line:84%
got in the previous Nugget.

15
00:30.180 --> 00:32.369 align:middle line:90%
Let's jump back into
the code and take a look

16
00:32.369 --> 00:33.670 align:middle line:84%
at what's going on here.

17
00:33.670 --> 00:34.533 align:middle line:84%
Let's go.

18
00:34.533 --> 00:36.450 align:middle line:90%
So in that last Nugget,
we did a lot of stuff.

19
00:36.450 --> 00:37.770 align:middle line:84%
We got logged in.

20
00:37.770 --> 00:39.780 align:middle line:90%
We handled a try
and accept block.

21
00:39.780 --> 00:42.450 align:middle line:90%
We even had an if statement
to check to make sure

22
00:42.450 --> 00:43.800 align:middle line:84%
that the token was filled.

23
00:43.800 --> 00:46.590 align:middle line:90%
That was honestly, the hardest
part to this entire script,

24
00:46.590 --> 00:48.510 align:middle line:90%
and many scripts
that you'll work

25
00:48.510 --> 00:50.640 align:middle line:90%
with in a network
automation journey

26
00:50.640 --> 00:52.240 align:middle line:84%
is just getting logged in.

27
00:52.240 --> 00:54.810 align:middle line:90%
So if you understand that,
if you understood it,

28
00:54.810 --> 00:56.070 align:middle line:84%
you're off to a great start.

29
00:56.070 --> 00:57.660 align:middle line:84%
If you don't, don't worry.

30
00:57.660 --> 00:59.260 align:middle line:84%
You're not alone.

31
00:59.260 --> 01:01.710 align:middle line:90%
This is just part of
learning network automation.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

31
00:59.260 --> 01:01.710 align:middle line:90%
This is just part of
learning network automation.

32
01:01.710 --> 01:04.800 align:middle line:90%
Don't be afraid to watch
it again or go check

33
01:04.800 --> 01:06.780 align:middle line:90%
out some DevNet
associate content

34
01:06.780 --> 01:09.240 align:middle line:90%
to see how it works
with other platforms

35
01:09.240 --> 01:11.940 align:middle line:90%
too because that's a really,
really important thing

36
01:11.940 --> 01:14.305 align:middle line:90%
is understanding just
getting authenticated.

37
01:14.305 --> 01:15.930 align:middle line:90%
But now that we're
authenticated and we

38
01:15.930 --> 01:18.430 align:middle line:90%
see what we've gone through
here with a try accept and we're

39
01:18.430 --> 01:21.930 align:middle line:90%
storing our token finally
in the correct header,

40
01:21.930 --> 01:23.970 align:middle line:90%
let's scroll down
a little bit more

41
01:23.970 --> 01:28.140 align:middle line:90%
and use this new token to
get the list of applications

42
01:28.140 --> 01:29.490 align:middle line:84%
that we're trying to monitor.

43
01:29.490 --> 01:33.030 align:middle line:90%
So just like before
where we had a base URL,
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

43
01:29.490 --> 01:33.030 align:middle line:90%
So just like before
where we had a base URL,

44
01:33.030 --> 01:35.970 align:middle line:90%
we're changing the
endpoint now though.

45
01:35.970 --> 01:39.480 align:middle line:90%
We're specifying a huge
endpoint right here

46
01:39.480 --> 01:41.922 align:middle line:90%
that goes all the
way down into objects

47
01:41.922 --> 01:43.005 align:middle line:84%
and then the applications.

48
01:43.005 --> 01:46.350 align:middle line:90%
I actually need to scroll
over so that you can see that.

49
01:46.350 --> 01:47.920 align:middle line:84%
There we go, applications.

50
01:47.920 --> 01:51.270 align:middle line:90%
So we're going into the
API endpoint, the Firepower

51
01:51.270 --> 01:53.817 align:middle line:90%
Management Center
Configuration section.

52
01:53.817 --> 01:55.650 align:middle line:90%
This is where we configure
what applications

53
01:55.650 --> 01:57.150 align:middle line:84%
that we need to monitor.

54
01:57.150 --> 02:00.420 align:middle line:90%
Version 1, then the
domain, then it's
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

54
01:57.150 --> 02:00.420 align:middle line:90%
Version 1, then the
domain, then it's

55
02:00.420 --> 02:03.060 align:middle line:90%
got this big ol'
GUID right here.

56
02:03.060 --> 02:05.280 align:middle line:90%
The trick to
finding this GUID is

57
02:05.280 --> 02:08.280 align:middle line:90%
to actually access Firepower
Management Center's

58
02:08.280 --> 02:10.050 align:middle line:84%
on-box documentation.

59
02:10.050 --> 02:11.760 align:middle line:90%
Firepower Management
Center makes

60
02:11.760 --> 02:14.580 align:middle line:90%
it easy to explore
the documentation, how

61
02:14.580 --> 02:16.560 align:middle line:84%
you can make an API call to it.

62
02:16.560 --> 02:19.380 align:middle line:90%
This is no different from what
we saw when we were exploring

63
02:19.380 --> 02:21.270 align:middle line:84%
the API and DNA Center.

64
02:21.270 --> 02:22.090 align:middle line:84%
Remember that?

65
02:22.090 --> 02:24.750 align:middle line:90%
In DNA Center, the
API documentation

66
02:24.750 --> 02:28.710 align:middle line:90%
was on DNA Center, and it
told you what kind of requests

67
02:28.710 --> 02:29.970 align:middle line:84%
you can make and use.

68
02:29.970 --> 02:32.790 align:middle line:90%
Firepower Management Center
does the exact same thing,
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

68
02:29.970 --> 02:32.790 align:middle line:90%
Firepower Management Center
does the exact same thing,

69
02:32.790 --> 02:36.030 align:middle line:90%
and we actually explore
that on-box documentation

70
02:36.030 --> 02:38.280 align:middle line:90%
as part of the DevNet
associate course.

71
02:38.280 --> 02:40.740 align:middle line:90%
One extra little pro tip
that I'll throw in there,

72
02:40.740 --> 02:44.050 align:middle line:90%
Cisco ASA products do
the exact same thing.

73
02:44.050 --> 02:46.320 align:middle line:90%
They have the REST
API documentation

74
02:46.320 --> 02:47.470 align:middle line:84%
built into the ASA.

75
02:47.470 --> 02:51.780 align:middle line:90%
And then we also cover how
to do just ASA automation

76
02:51.780 --> 02:53.820 align:middle line:90%
in the DevNet
associate course too.

77
02:53.820 --> 02:57.010 align:middle line:90%
So I grabbed this GUID
that you see here--

78
02:57.010 --> 02:58.710 align:middle line:90%
that's a big thing
called a GUID;

79
02:58.710 --> 03:00.600 align:middle line:84%
it's basically a unique ID--
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

79
02:58.710 --> 03:00.600 align:middle line:84%
it's basically a unique ID--

80
03:00.600 --> 03:03.270 align:middle line:90%
from the Firepower
Management Center box.

81
03:03.270 --> 03:07.210 align:middle line:90%
Then we can explore objects
like applications from there.

82
03:07.210 --> 03:10.050 align:middle line:90%
So I've got my base URL,
and I'm going to tack this

83
03:10.050 --> 03:11.173 align:middle line:84%
onto the end of it.

84
03:11.173 --> 03:12.840 align:middle line:90%
So let me clear the
screen a little bit.

85
03:12.840 --> 03:15.390 align:middle line:90%
We'll scroll back over so we
can see the rest of the code,

86
03:15.390 --> 03:18.750 align:middle line:90%
and you can see immediately
now we have a try

87
03:18.750 --> 03:20.500 align:middle line:84%
and accept block again.

88
03:20.500 --> 03:22.560 align:middle line:90%
Just like before,
it's going to try

89
03:22.560 --> 03:25.380 align:middle line:90%
to perform all of the
code that's indented here

90
03:25.380 --> 03:27.570 align:middle line:90%
unless there is
an error, then it

91
03:27.570 --> 03:30.540 align:middle line:90%
will do what's in the
indented exception section.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

91
03:27.570 --> 03:30.540 align:middle line:90%
will do what's in the
indented exception section.

92
03:30.540 --> 03:33.330 align:middle line:90%
But now, see we've also
thrown in a finally.

93
03:33.330 --> 03:36.510 align:middle line:90%
The finally says, run
this code no matter

94
03:36.510 --> 03:39.180 align:middle line:90%
what, whether the
try is successful

95
03:39.180 --> 03:41.700 align:middle line:90%
or the accept is
successful, do whatever

96
03:41.700 --> 03:43.320 align:middle line:84%
the finally says to do.

97
03:43.320 --> 03:45.870 align:middle line:90%
And recall again
our HTTP methods.

98
03:45.870 --> 03:49.390 align:middle line:90%
The post request was all
about creating moo data.

99
03:49.390 --> 03:51.660 align:middle line:90%
It's all about sending
in our login information

100
03:51.660 --> 03:53.970 align:middle line:90%
and making the server
perform some action.

101
03:53.970 --> 03:55.380 align:middle line:84%
But now we're not doing that.

102
03:55.380 --> 03:59.260 align:middle line:90%
We're just trying to get
a list of applications,

103
03:59.260 --> 04:01.890 align:middle line:90%
and that's what the
get request does.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

103
03:59.260 --> 04:01.890 align:middle line:90%
and that's what the
get request does.

104
04:01.890 --> 04:04.860 align:middle line:90%
We're using the request
library one more time.

105
04:04.860 --> 04:06.960 align:middle line:84%
We're performing a get request.

106
04:06.960 --> 04:10.410 align:middle line:90%
We have our base URL,
but now the apps URL

107
04:10.410 --> 04:13.900 align:middle line:90%
is targeting what's right
in here, our applications.

108
04:13.900 --> 04:15.930 align:middle line:90%
Now this is where it
gets a little different.

109
04:15.930 --> 04:19.470 align:middle line:90%
When we were logging in, if
I scroll up for a second,

110
04:19.470 --> 04:23.190 align:middle line:90%
you see we specified our
URL and then authentication,

111
04:23.190 --> 04:25.810 align:middle line:90%
we were using a
username and password.

112
04:25.810 --> 04:27.920 align:middle line:90%
We're not doing that
anymore down here.

113
04:27.920 --> 04:30.420 align:middle line:90%
Here, we've already
gotten logged in,
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

113
04:27.920 --> 04:30.420 align:middle line:90%
Here, we've already
gotten logged in,

114
04:30.420 --> 04:33.550 align:middle line:90%
and we added our
token to our headers.

115
04:33.550 --> 04:36.540 align:middle line:90%
So all I have to do here
is specify my headers.

116
04:36.540 --> 04:40.530 align:middle line:90%
That way when it goes to this
URL, it'll send in the token

117
04:40.530 --> 04:43.360 align:middle line:90%
that we've already received,
which basically says,

118
04:43.360 --> 04:45.000 align:middle line:84%
look, I'm already authenticated.

119
04:45.000 --> 04:47.040 align:middle line:84%
Don't worry about me that much.

120
04:47.040 --> 04:48.840 align:middle line:90%
The verify equals
false is here again

121
04:48.840 --> 04:51.210 align:middle line:90%
because we're still working
with the same endpoint,

122
04:51.210 --> 04:53.550 align:middle line:90%
and it's still using a
self-signed certificate.

123
04:53.550 --> 04:55.500 align:middle line:90%
But this is where
this little thing gets

124
04:55.500 --> 04:57.060 align:middle line:84%
kind of interesting and neat.

125
04:57.060 --> 05:00.360 align:middle line:90%
Remember at the top of the
code, we had import JSON.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

125
04:57.060 --> 05:00.360 align:middle line:90%
Remember at the top of the
code, we had import JSON.

126
05:00.360 --> 05:03.870 align:middle line:90%
When we performed the
get request to REST API,

127
05:03.870 --> 05:06.420 align:middle line:90%
the default behavior
is to send back

128
05:06.420 --> 05:08.970 align:middle line:90%
a payload, all of
these applications

129
05:08.970 --> 05:11.010 align:middle line:90%
that are going to
be written in JSON.

130
05:11.010 --> 05:13.650 align:middle line:90%
From Python's
perspective, JSON is

131
05:13.650 --> 05:17.560 align:middle line:90%
nothing more than just
a giant block of text.

132
05:17.560 --> 05:20.610 align:middle line:90%
So when we perform this
little method right here

133
05:20.610 --> 05:22.350 align:middle line:90%
on the end of it,
this is saying,

134
05:22.350 --> 05:25.770 align:middle line:90%
convert all of that
JSON text into what's

135
05:25.770 --> 05:28.560 align:middle line:84%
called a Python dictionary.

136
05:28.560 --> 05:30.330 align:middle line:90%
That way later down
the road, we can
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

136
05:28.560 --> 05:30.330 align:middle line:90%
That way later down
the road, we can

137
05:30.330 --> 05:33.630 align:middle line:90%
perform programmatic
actions in Python

138
05:33.630 --> 05:36.150 align:middle line:90%
against all of the
data that comes back.

139
05:36.150 --> 05:38.070 align:middle line:90%
So once all of
this is done, we've

140
05:38.070 --> 05:42.840 align:middle line:90%
done the get request to this
URL, specifying our token

141
05:42.840 --> 05:45.900 align:middle line:90%
and converted it from
JSON into Python,

142
05:45.900 --> 05:50.100 align:middle line:90%
it stores all of that Python
data in a variable called

143
05:50.100 --> 05:51.470 align:middle line:84%
apps_response.

144
05:51.470 --> 05:53.220 align:middle line:90%
So any time after
that, we can now

145
05:53.220 --> 05:56.010 align:middle line:90%
work with the apps
response variable and all

146
05:56.010 --> 05:57.960 align:middle line:90%
of the data inside
of it to look at what

147
05:57.960 --> 05:59.610 align:middle line:84%
application info came back.

148
05:59.610 --> 06:01.800 align:middle line:90%
And from there, the
world is our oyster.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

148
05:59.610 --> 06:01.800 align:middle line:90%
And from there, the
world is our oyster.

149
06:01.800 --> 06:04.080 align:middle line:90%
We could send text
message alerts off.

150
06:04.080 --> 06:06.420 align:middle line:90%
We could print it
out to a text file.

151
06:06.420 --> 06:09.150 align:middle line:90%
We could validate that
the data is correct

152
06:09.150 --> 06:10.930 align:middle line:84%
and it's what we expected.

153
06:10.930 --> 06:12.870 align:middle line:90%
And if it's not, we
could send requests

154
06:12.870 --> 06:15.520 align:middle line:90%
back in to change the
data if we wanted to.

155
06:15.520 --> 06:18.030 align:middle line:90%
But all I've done
here online 39 is

156
06:18.030 --> 06:20.730 align:middle line:90%
I've simply taken that
apps response variable

157
06:20.730 --> 06:22.990 align:middle line:90%
and printed it out in
a nice, pretty format.

158
06:22.990 --> 06:25.200 align:middle line:90%
That's what all this
code is really doing here

159
06:25.200 --> 06:27.150 align:middle line:90%
is it just prints it
out to the terminal

160
06:27.150 --> 06:28.530 align:middle line:84%
and in nice, pretty format.

161
06:28.530 --> 06:31.080 align:middle line:90%
Now, of course, we have
our exception clause here.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

161
06:28.530 --> 06:31.080 align:middle line:90%
Now, of course, we have
our exception clause here.

162
06:31.080 --> 06:33.960 align:middle line:90%
In case anything goes wrong,
it prints the error out.

163
06:33.960 --> 06:37.830 align:middle line:90%
And finally, as a last
act, if the apps response

164
06:37.830 --> 06:40.680 align:middle line:90%
does contain data, that's
what we're saying here,

165
06:40.680 --> 06:43.570 align:middle line:90%
just go ahead and
close out the code.

166
06:43.570 --> 06:46.200 align:middle line:90%
So this is quite a journey that
we've been on, don't you think?

167
06:46.200 --> 06:48.540 align:middle line:90%
If we recap the whole
thing right now,

168
06:48.540 --> 06:50.550 align:middle line:90%
what we can see is at
the very beginning,

169
06:50.550 --> 06:53.830 align:middle line:90%
we imported the three libraries
that we wanted to work with.

170
06:53.830 --> 06:57.120 align:middle line:90%
We've got JSON data, we've
got the operating system

171
06:57.120 --> 06:59.250 align:middle line:90%
in case we need to
exit out of this code,

172
06:59.250 --> 07:00.870 align:middle line:90%
in case there's
an error, and then
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

172
06:59.250 --> 07:00.870 align:middle line:90%
in case there's
an error, and then

173
07:00.870 --> 07:05.070 align:middle line:90%
we have the request library
for performing those HTTP posts

174
07:05.070 --> 07:06.120 align:middle line:84%
and get requests.

175
07:06.120 --> 07:09.210 align:middle line:90%
The post is what's going to be
creating data, or in our case,

176
07:09.210 --> 07:11.520 align:middle line:90%
sending in our user
name and password,

177
07:11.520 --> 07:13.890 align:middle line:90%
and the get request is
what retrieves data.

178
07:13.890 --> 07:15.600 align:middle line:90%
Then we set up some
variables that we

179
07:15.600 --> 07:18.450 align:middle line:90%
store our username
and password as well

180
07:18.450 --> 07:21.120 align:middle line:90%
as the URLs in the headers
that we want to work with.

181
07:21.120 --> 07:25.830 align:middle line:90%
We move into the login block
of code where we try to log in.

182
07:25.830 --> 07:28.740 align:middle line:90%
We send in a post request
containing our user name

183
07:28.740 --> 07:29.670 align:middle line:84%
and password.

184
07:29.670 --> 07:33.180 align:middle line:90%
We store the data that comes
back in a giant variable,
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

184
07:29.670 --> 07:33.180 align:middle line:90%
We store the data that comes
back in a giant variable,

185
07:33.180 --> 07:35.220 align:middle line:90%
and then we whittle it
down one step at a time.

186
07:35.220 --> 07:36.660 align:middle line:84%
We get just the headers.

187
07:36.660 --> 07:38.880 align:middle line:90%
Then from the headers,
we get just the token,

188
07:38.880 --> 07:41.250 align:middle line:90%
and then we add the
token to our own header

189
07:41.250 --> 07:43.440 align:middle line:90%
that we can use in
the later request.

190
07:43.440 --> 07:46.930 align:middle line:90%
Then, as we scroll down more,
we build our next variable,

191
07:46.930 --> 07:49.200 align:middle line:90%
which is going to be
the endpoint that holds

192
07:49.200 --> 07:51.030 align:middle line:84%
all of the application data.

193
07:51.030 --> 07:55.350 align:middle line:90%
We send in a get request to
get data from those application

194
07:55.350 --> 07:58.800 align:middle line:90%
endpoints, and we specified
our token in the headers

195
07:58.800 --> 08:00.210 align:middle line:84%
that we provide there.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

195
07:58.800 --> 08:00.210 align:middle line:84%
that we provide there.

196
08:00.210 --> 08:03.960 align:middle line:90%
We parse the data that comes
back out from JSON into Python,

197
08:03.960 --> 08:06.090 align:middle line:90%
and then we can do whatever
we want to with it,

198
08:06.090 --> 08:08.160 align:middle line:90%
and then we cleanly
exit the code.

199
08:08.160 --> 08:11.010 align:middle line:90%
That's how we interpret
a basic Python script.

200
08:11.010 --> 08:13.920 align:middle line:90%
Go back through this as
many times as you need,

201
08:13.920 --> 08:17.520 align:middle line:90%
and try to read it to yourself
in as plain as English

202
08:17.520 --> 08:18.390 align:middle line:84%
as possible.

203
08:18.390 --> 08:24.860 align:middle line:90%
Things like try to get data
from this URL using this token.

204
08:24.860 --> 08:29.310 align:middle line:90%
If there is an exception, throw
this error or print this error.

205
08:29.310 --> 08:31.770 align:middle line:84%
Finally, exit the code cleanly.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

205
08:29.310 --> 08:31.770 align:middle line:84%
Finally, exit the code cleanly.

206
08:31.770 --> 08:34.650 align:middle line:90%
That's really the purpose
and the intent of Python.

207
08:34.650 --> 08:36.510 align:middle line:90%
So I hope this has been
informative for you,

208
08:36.510 --> 08:39.229 align:middle line:90%
and I'd like to thank
you for viewing.
