-
Notifications
You must be signed in to change notification settings - Fork 1
/
junipersrx_connector.py
688 lines (485 loc) · 24.4 KB
/
junipersrx_connector.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
# File: junipersrx_connector.py
#
# Copyright (c) 2016-2024 Splunk Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied. See the License for the specific language governing permissions
# and limitations under the License.
#
#
import re
import phantom.app as phantom
import xmltodict
from jsonpath_rw import parse as jsparse
from ncclient import manager
from phantom.action_result import ActionResult
from phantom.base_connector import BaseConnector
from junipersrx_consts import *
class JuniperConnector(BaseConnector):
# The actions supported by this connector
ACTION_ID_BLOCK_APPLICATION = "block_application"
ACTION_ID_UNBLOCK_APPLICATION = "unblock_application"
ACTION_ID_BLOCK_IP = "block_ip"
ACTION_ID_UNBLOCK_IP = "unblock_ip"
ACTION_ID_LIST_APPS = "list_apps"
def __init__(self):
# Call the BaseConnectors init first
super(JuniperConnector, self).__init__()
self._conn = None
def _get_conn(self):
if self._conn is not None:
# conn already created for this call
return phantom.APP_SUCCESS
config = self.get_config()
port = str(config.get(phantom.APP_JSON_PORT, DEFAULT_PORT))
# Connectivity
self.save_progress(phantom.APP_PROG_CONNECTING_TO_ELLIPSES, config[phantom.APP_JSON_DEVICE])
username = config[phantom.APP_JSON_USERNAME]
password = config[phantom.APP_JSON_PASSWORD]
self.save_progress("Using port " + port + "...")
try:
conn = manager.connect(
host=config[phantom.APP_JSON_DEVICE],
port=port,
username=username,
password=password,
timeout=DEFAULT_TIMEOUT,
device_params={"name": "junos"},
hostkey_verify=False,
)
except Exception as e:
self.debug_print(JUNIPERSRX_ERR_DEVICE_CONNECTIVITY, e)
return self.set_status(phantom.APP_ERROR, JUNIPERSRX_ERR_DEVICE_CONNECTIVITY, e)
self._conn = conn
return phantom.APP_SUCCESS
def _test_connectivity(self, param):
status = self._get_conn()
if phantom.is_fail(status):
self.append_to_message(JUNIPERSRX_ERR_TEST_CONNECTIVITY_FAILED)
return self.get_status()
return self.set_status_save_progress(phantom.APP_SUCCESS, JUNIPERSRX_SUCC_TEST_CONNECTIVITY_PASSED)
def _get_application_set_apps(self, param, action_result):
apps = []
get_app_set = "show configuration applications application-set {app_set} | display xml".format(app_set=JUNIPERSRX_APP_SET)
try:
response = self._conn.command(command=get_app_set, format="xml")
except Exception as e:
self.debug_print("command Exception: {0}".format(str(e)))
return (action_result.set_status(phantom.APP_ERROR, JUNIPERSRX_ERR_COMMAND_EXEC, e), apps)
response_dict = None
try:
response_dict = xmltodict.parse(response.tostring)
except Exception as e:
self.debug_print("parse Exception: {0}".format(str(e)))
return (action_result.set_status(phantom.APP_ERROR, JUNIPERSRX_ERR_PARSE_RESPONSE, e), apps)
if not response_dict:
return (action_result.set_status(phantom.APP_ERROR, JUNIPERSRX_ERR_EMPTY_RESPONSE), apps)
apps = jsparse("rpc-reply.configuration.applications.application-set.application").find(response_dict)
if len(apps) == 0:
# Success because there is no apps
return (phantom.APP_SUCCESS, apps)
get_list = lambda x: x if type(x) is list else [x]
# there should be only one
apps = get_list(apps[0].value)
return (phantom.APP_SUCCESS, apps)
def _get_address_set_addresses(self, param, action_result):
addresses = []
get_address_set = "show configuration security address-book {addr_book} address-set {addr_set} | display xml".format(
addr_book=JUNIPERSRX_ADDRESS_BOOK, addr_set=JUNIPERSRX_ADDRESS_SET
)
try:
response = self._conn.command(command=get_address_set, format="xml")
except Exception as e:
self.debug_print("command Exception: {0}".format(str(e)))
return (action_result.set_status(phantom.APP_ERROR, JUNIPERSRX_ERR_COMMAND_EXEC, e), addresses)
response_dict = None
try:
response_dict = xmltodict.parse(response.tostring)
except Exception as e:
self.debug_print("parse Exception: {0}".format(str(e)))
return (action_result.set_status(phantom.APP_ERROR, JUNIPERSRX_ERR_PARSE_RESPONSE, e), addresses)
if not response_dict:
return (action_result.set_status(phantom.APP_ERROR, JUNIPERSRX_ERR_EMPTY_RESPONSE), addresses)
addresses = jsparse("rpc-reply.configuration.security.address-book.address-set.address").find(response_dict)
if len(addresses) == 0:
# Success because there is no addresses
return (phantom.APP_SUCCESS, addresses)
get_list = lambda x: x if type(x) is list else [x]
# there should be only one
addresses = get_list(addresses[0].value)
return (phantom.APP_SUCCESS, addresses)
def _get_first_allow_policy(self, param, action_result):
policy_name = None
from_zone = param[JUNIPERSRX_JSON_FROM_ZONE]
to_zone = param[JUNIPERSRX_JSON_TO_ZONE]
get_config_cmd = "show security policies from-zone {from_zone} to-zone {to_zone} | display xml".format(
from_zone=from_zone, to_zone=to_zone
)
try:
response = self._conn.command(command=get_config_cmd, format="xml")
except Exception as e:
self.debug_print("command Exception: {0}".format(str(e)))
return (action_result.set_status(phantom.APP_ERROR, JUNIPERSRX_ERR_COMMAND_EXEC, e), policy_name)
response_dict = None
try:
response_dict = xmltodict.parse(response.tostring)
except Exception as e:
self.debug_print("parse Exception: {0}".format(str(e)))
return (action_result.set_status(phantom.APP_ERROR, JUNIPERSRX_ERR_PARSE_RESPONSE, e), policy_name)
if not response_dict:
return (action_result.set_status(phantom.APP_ERROR, JUNIPERSRX_ERR_EMPTY_RESPONSE), policy_name)
policies = jsparse("rpc-reply.security-policies.security-context.policies").find(response_dict)
if len(policies) == 0:
return (action_result.set_status(phantom.APP_ERROR, JUNIPERSRX_ERR_NO_ALLOW_POLICY_ENTRIES_FOUND), policy_name)
get_list = lambda x: x if type(x) is list else [x]
# there should be only one
policies = get_list(policies[0].value)
lowest_seq_number = len(policies) + 1
for i, policy in enumerate(policies):
self.debug_print("Policy[{0}]:".format(i), policy)
seq_no = policy["policy-information"]["policy-sequence-number"]
action = policy["policy-information"]["policy-action"]["action-type"]
self.debug_print("Lowest Seq No: {2}, Seq No: {0}, Action: {1}".format(seq_no, action, lowest_seq_number))
if action != "permit":
self.debug_print("{0} != permit, continue".format(action))
# ignore
continue
if int(seq_no) >= int(lowest_seq_number):
self.debug_print("{0} >= {1}, continue".format(seq_no, lowest_seq_number))
continue
lowest_seq_number = seq_no
policy_name = policy["policy-information"]["policy-name"]
self.debug_print("Got a lower permit, now Lowest Seq #: {0} of Name: {1}".format(lowest_seq_number, policy_name))
if policy_name is None:
return (action_result.set_status(phantom.APP_ERROR, JUNIPERSRX_ERR_NO_ALLOW_POLICY_ENTRIES_FOUND), policy_name)
return (phantom.APP_SUCCESS, policy_name)
def _unblock_application(self, param):
status = self._get_conn()
if phantom.is_fail(status):
return self.get_status()
action_result = self.add_action_result(ActionResult(dict(param)))
block_app = param[JUNIPERSRX_JSON_APPLICATION]
from_zone = param[JUNIPERSRX_JSON_FROM_ZONE]
to_zone = param[JUNIPERSRX_JSON_TO_ZONE]
self.debug_print("Locking the Running config")
self._conn.lock()
self.debug_print("Locked")
config_cmd = []
# First get all the applications from the application set
status, apps = self._get_application_set_apps(param, action_result)
if phantom.is_fail(status):
return action_result.get_status()
app_name = None
for app in apps:
# check if any of them match the one that we are trying to remove
if app["name"] == block_app:
app_name = app["name"]
break
if app_name is None:
# Not an error condition
return action_result.set_status(phantom.APP_SUCCESS, JUNIPERSRX_SUCC_APP_NOT_FOUND)
# Check if the policy needs to be changed
remove_policy = True if len(apps) == 1 else False
# remove the app from the app-set
app_set_line = "delete applications application-set {app_set_name} application {app_name}".format(
app_set_name=JUNIPERSRX_APP_SET, app_name=app_name
)
config_cmd.append(app_set_line)
# remove the policy if needed
if remove_policy:
policy_line = "delete security policies from-zone {from_zone} to-zone {to_zone} policy {policy_name}".format(
from_zone=from_zone, to_zone=to_zone, policy_name=JUNIPERSRX_APP_POLICY
)
config_cmd.append(policy_line)
self.send_progress(JUNIPERSRX_MSG_REMOVING_POLICY)
# Commit the config
status = self._apply_config(config_cmd, action_result)
if phantom.is_fail(status):
return action_result.get_status()
return action_result.set_status(phantom.APP_SUCCESS, "Successfully unblock application")
def _block_application(self, param):
status = self._get_conn()
if phantom.is_fail(status):
return self.get_status()
action_result = self.add_action_result(ActionResult(dict(param)))
block_app = param[JUNIPERSRX_JSON_APPLICATION]
from_zone = param[JUNIPERSRX_JSON_FROM_ZONE]
to_zone = param[JUNIPERSRX_JSON_TO_ZONE]
self.debug_print("Locking the Running config")
self._conn.lock()
self.debug_print("Locked")
config_cmd = []
# First Add the application to the application set
app_set = "set applications application-set {app_set} application {block_app}".format(app_set=JUNIPERSRX_APP_SET, block_app=block_app)
config_cmd.append(app_set)
# create policy
policy_line = "set security policies from-zone {from_zone} to-zone {to_zone} policy {policy_name} match source-address any ".format(
from_zone=from_zone, to_zone=to_zone, policy_name=JUNIPERSRX_APP_POLICY
)
policy_line += "destination-address any application {app_set}".format(app_set=JUNIPERSRX_APP_SET)
config_cmd.append(policy_line)
# Set the actions for the policy
policy_line = "set security policies from-zone {from_zone} to-zone {to_zone} policy {policy_name} then reject".format(
from_zone=from_zone, to_zone=to_zone, policy_name=JUNIPERSRX_APP_POLICY
)
config_cmd.append(policy_line)
policy_line = "set security policies from-zone {from_zone} to-zone {to_zone} policy {policy_name} then log session-init".format(
from_zone=from_zone, to_zone=to_zone, policy_name=JUNIPERSRX_APP_POLICY
)
config_cmd.append(policy_line)
self.send_progress(JUNIPERSRX_MSG_ADDING_POLICY)
status, permit_rule = self._get_first_allow_policy(param, action_result)
self.debug_print("Got first rule: {0}, status: {1}".format(permit_rule, status))
if phantom.is_fail(status):
return action_result.get_status()
insert_line = "insert security policies from-zone {from_zone} to-zone {to_zone} policy {policy_name} before policy {permit_rule}".format(
from_zone=from_zone, to_zone=to_zone, policy_name=JUNIPERSRX_APP_POLICY, permit_rule=permit_rule
)
config_cmd.append(insert_line)
# Commit the config
ret_val = self._apply_config(config_cmd, action_result)
if phantom.is_fail(ret_val):
return action_result.get_status()
return action_result.set_status(phantom.APP_SUCCESS, "Successfully blocked application")
def _get_addr_name(self, ip):
# Remove the slash in the ip if present
rem_slash = lambda x: re.sub(r"(.*)/(.*)", r"\1-\2", x)
name = "{0}".format(rem_slash(ip))
return name
def _add_address(self, block_ip, config_cmd, action_result):
type = None
name = None
container_id = self.get_container_id()
description = "Last updated by container {0}".format(container_id)
name = self._get_addr_name(block_ip)
value = block_ip
# Try to figure out the type of ip
if block_ip.find("-") != -1:
type = "range-address"
value = block_ip.replace("-", " to ")
elif phantom.is_hostname(block_ip):
type = "dns-name"
else:
type = " "
address_book_line = 'set security address-book {addr_book_name} address {addr_name} description "{description}" {type} {value}'.format(
addr_book_name=JUNIPERSRX_ADDRESS_BOOK, addr_name=name, description=description, type=type, value=value
)
config_cmd.append(address_book_line)
address_set_line = "set security address-book {addr_book_name} address-set {addr_set_name} address {addr_name}".format(
addr_book_name=JUNIPERSRX_ADDRESS_BOOK, addr_set_name=JUNIPERSRX_ADDRESS_SET, addr_name=name
)
config_cmd.append(address_set_line)
return (phantom.APP_SUCCESS, name)
def _unblock_ip(self, param):
status = self._get_conn()
if phantom.is_fail(status):
return self.get_status()
action_result = self.add_action_result(ActionResult(dict(param)))
block_ip = param[JUNIPERSRX_JSON_IP]
from_zone = param[JUNIPERSRX_JSON_FROM_ZONE]
to_zone = param[JUNIPERSRX_JSON_TO_ZONE]
self.debug_print("Locking the Running config")
self._conn.lock()
self.debug_print("Locked")
config_cmd = []
# First get all the addresses from the address set
status, addresses = self._get_address_set_addresses(param, action_result)
if phantom.is_fail(status):
return action_result.get_status()
addr_name = None
for address in addresses:
# check if any of them match the one that we are trying to remove
if address["name"] == self._get_addr_name(block_ip):
addr_name = address["name"]
break
if addr_name is None:
# Not an error condition
return action_result.set_status(phantom.APP_SUCCESS, JUNIPERSRX_SUCC_ADDRESS_NOT_FOUND)
# Check if the policy needs to be changed
remove_policy = True if len(addresses) == 1 else False
# remove the address from the address-set
address_set_line = "delete security address-book {addr_book_name} address-set {addr_set_name} address {addr_name}".format(
addr_book_name=JUNIPERSRX_ADDRESS_BOOK, addr_set_name=JUNIPERSRX_ADDRESS_SET, addr_name=addr_name
)
config_cmd.append(address_set_line)
# remove the address from the address book
address_book_line = "delete security address-book {addr_book_name} address {addr_name}".format(
addr_book_name=JUNIPERSRX_ADDRESS_BOOK, addr_name=addr_name
)
config_cmd.append(address_book_line)
# remove the policy if needed
if remove_policy:
policy_line = "delete security policies from-zone {from_zone} to-zone {to_zone} policy {policy_name}".format(
from_zone=from_zone, to_zone=to_zone, policy_name=JUNIPERSRX_ADDRESS_POLICY
)
config_cmd.append(policy_line)
self.send_progress(JUNIPERSRX_MSG_REMOVING_POLICY)
# Commit the config
status = self._apply_config(config_cmd, action_result)
if phantom.is_fail(status):
return action_result.get_status()
return action_result.set_status(phantom.APP_SUCCESS, "Successfully unblocked ip")
def _apply_config(self, config_cmd, action_result):
self.debug_print("config_cmd: ", config_cmd)
try:
self._conn.load_configuration(action="set", config=config_cmd)
except Exception as e:
self.debug_print("load_configuration Exception: {0}".format(str(e)))
return action_result.set_status(phantom.APP_ERROR, JUNIPERSRX_ERR_CONFIG_LOAD_FAILED, e)
try:
self._conn.validate()
except Exception as e:
self.debug_print("validate Exception: {0}".format(str(e)))
return action_result.set_status(phantom.APP_ERROR, JUNIPERSRX_ERR_CONFIG_VALIDATION_FAILED, e)
# Now Commit the config
try:
self._conn.commit()
except Exception as e:
self.debug_print("commit Exception: {0}".format(str(e)))
return action_result.set_status(phantom.APP_ERROR, JUNIPERSRX_ERR_CONFIG_COMMIT_FAILED, e)
return phantom.APP_SUCCESS
def _block_ip(self, param):
status = self._get_conn()
if phantom.is_fail(status):
return self.get_status()
action_result = self.add_action_result(ActionResult(dict(param)))
block_ip = param[JUNIPERSRX_JSON_IP]
from_zone = param[JUNIPERSRX_JSON_FROM_ZONE]
to_zone = param[JUNIPERSRX_JSON_TO_ZONE]
self.debug_print("Locking the Running config")
self._conn.lock()
self.debug_print("Locked")
config_cmd = []
# First Add the ip to the address group
status = self._add_address(block_ip, config_cmd, action_result)
if phantom.is_fail(status):
return action_result.get_status()
# get the address book and it's attached zones, we can't add zones to an address book without checking
# for them first else it spits an error.
# create policy
policy_line = "set security policies from-zone {from_zone} to-zone {to_zone} policy {policy_name} match source-address any ".format(
from_zone=from_zone, to_zone=to_zone, policy_name=JUNIPERSRX_ADDRESS_POLICY
)
policy_line += "destination-address {addr_set} application any".format(addr_set=JUNIPERSRX_ADDRESS_SET)
config_cmd.append(policy_line)
# Set the actions for the policy
policy_line = "set security policies from-zone {from_zone} to-zone {to_zone} policy {policy_name} then reject".format(
from_zone=from_zone, to_zone=to_zone, policy_name=JUNIPERSRX_ADDRESS_POLICY
)
config_cmd.append(policy_line)
policy_line = "set security policies from-zone {from_zone} to-zone {to_zone} policy {policy_name} then log session-init".format(
from_zone=from_zone, to_zone=to_zone, policy_name=JUNIPERSRX_ADDRESS_POLICY
)
config_cmd.append(policy_line)
self.send_progress(JUNIPERSRX_MSG_ADDING_POLICY)
status, permit_rule = self._get_first_allow_policy(param, action_result)
self.debug_print("Got first rule: {0}, status: {1}".format(permit_rule, status))
if phantom.is_fail(status):
return action_result.get_status()
insert_line = "insert security policies from-zone {from_zone} to-zone {to_zone} policy {policy_name} before policy {permit_rule}".format(
from_zone=from_zone, to_zone=to_zone, policy_name=JUNIPERSRX_ADDRESS_POLICY, permit_rule=permit_rule
)
config_cmd.append(insert_line)
# Commit the config
ret_val = self._apply_config(config_cmd, action_result)
if phantom.is_fail(ret_val):
return action_result.get_status()
return action_result.set_status(phantom.APP_SUCCESS, "Successfully blocked ip")
def _list_apps(self, param):
status = self._get_conn()
if phantom.is_fail(status):
return self.get_status()
action_result = self.add_action_result(ActionResult(dict(param)))
apps = []
get_app_set = "show configuration groups junos-defaults applications | display xml"
try:
response = self._conn.command(command=get_app_set, format="xml")
except Exception as e:
self.debug_print("command Exception: {0}".format(str(e)))
return (action_result.set_status(phantom.APP_ERROR, JUNIPERSRX_ERR_COMMAND_EXEC, e), apps)
response_dict = None
try:
response_dict = xmltodict.parse(response.tostring)
except Exception as e:
self.debug_print("parse Exception: {0}".format(str(e)))
return (action_result.set_status(phantom.APP_ERROR, JUNIPERSRX_ERR_PARSE_RESPONSE, e), apps)
if not response_dict:
return (action_result.set_status(phantom.APP_ERROR, JUNIPERSRX_ERR_EMPTY_RESPONSE), apps)
get_list = lambda x: x if type(x) is list else [x]
# app_sets = jsparse('rpc-reply.configuration.groups.applications.application-set').find(response_dict)
total_apps = 0
# if len(app_sets) > 0:
# # there should be only one
# apps = get_list(app_sets[0].value)
# total_apps += len(apps)
# for app in apps:
# action_result.add_data({'name': app['name'], 'type': 'set'})
apps = jsparse("rpc-reply.configuration.groups.applications.application").find(response_dict)
if len(apps) > 0:
# there should be only one
apps = get_list(apps[0].value)
total_apps += len(apps)
for app in apps:
action_result.add_data({"name": app["name"], "type": "app"})
action_result.set_summary({JUNIPERSRX_JSON_TOTAL_APPLICATIONS: total_apps})
return action_result.set_status(phantom.APP_SUCCESS, "Successfully recived application list")
def _close_session(self):
if self._conn is not None:
try:
self._conn.unlock()
except:
pass
if self._conn.connected:
self._conn.close_session()
return phantom.APP_SUCCESS
def finalize(self):
return self._close_session()
def handle_exception(self, exception):
return self._close_session()
def validate_parameters(self, param):
"""This app will do it's own parameter validation"""
return phantom.APP_SUCCESS
def handle_action(self, param):
result = None
action = self.get_action_identifier()
self._param = param
if action == phantom.ACTION_ID_TEST_ASSET_CONNECTIVITY:
result = self._test_connectivity(param)
elif action == self.ACTION_ID_BLOCK_APPLICATION:
result = self._block_application(param)
elif action == self.ACTION_ID_UNBLOCK_APPLICATION:
result = self._unblock_application(param)
elif action == self.ACTION_ID_BLOCK_IP:
result = self._block_ip(param)
elif action == self.ACTION_ID_UNBLOCK_IP:
result = self._unblock_ip(param)
elif action == self.ACTION_ID_LIST_APPS:
result = self._list_apps(param)
return result
if __name__ == "__main__":
import sys
try:
import simplejson as json
except:
pass
import pudb
pudb.set_trace()
if len(sys.argv) < 2:
print("No test json specified as input")
sys.exit(0)
with open(sys.argv[1]) as f:
in_json = f.read()
in_json = json.loads(in_json)
print(json.dumps(in_json, indent=" " * 4))
connector = JuniperConnector()
connector.print_progress_message = True
ret_val = connector._handle_action(json.dumps(in_json), None)
print(ret_val)
sys.exit(0)