-
-
Notifications
You must be signed in to change notification settings - Fork 568
/
fastnetmon_a10_v0.3.py
executable file
·87 lines (62 loc) · 2.45 KB
/
fastnetmon_a10_v0.3.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
#!/usr/bin/python
#
# Eric Chou ([email protected])
#
import sys
from sys import stdin
import optparse
import logging, json
from a10 import axapi_auth, axapi_action
from json_configs.logoff import logoff_path
from json_configs.write_memory import write_mem_path
from json_configs.ddos_dst_zone import ddos_dst_zone_path, ddos_dst_zone
LOG_FILE = "/var/log/fastnetmon-notify.log"
logger = logging.getLogger("DaemonLog")
logger.setLevel(logging.INFO)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
handler = logging.FileHandler(LOG_FILE)
handler.setFormatter(formatter)
logger.addHandler(handler)
client_ip_as_string=sys.argv[1]
data_direction=sys.argv[2]
pps_as_string=int(sys.argv[3])
action=sys.argv[4]
logger.info(" - " . join(sys.argv))
# A10 Mitigator Information
mitigator_ip = "192.168.199.150"
zone_name = client_ip_as_string + "_zone"
ip_addr = client_ip_as_string
mitigator_base_url, signature = axapi_auth(mitigator_ip, "admin", "a10")
if action == "unban":
try:
r = axapi_action(mitigator_base_url+ddos_dst_zone_path+zone_name, method="DELETE", signature=signature)
except Exception as e:
logger.info("Zone not removed in unban, may not exist. Result: " + str(e))
# Commit config
axapi_action(mitigator_base_url+write_mem_path, signature=signature)
# Logoff
axapi_action(mitigator_base_url+logoff_path, signature=signature)
sys.exit(0)
elif action == "ban":
r = axapi_action(mitigator_base_url+ddos_dst_zone_path, method='GET', signature=signature)
try:
if zone_name in [i['zone-name'] for i in json.loads(r)['zone-list']]:
r = axapi_action(mitigator_base_url+ddos_dst_zone_path+zone_name, method="DELETE", signature=signature)
logger.info(str(r))
except Exception as e:
logger.info("No Zone detected or something went wrong. Erorr: " + str(e))
# A10 Mitigation On Ramp
zone_name = client_ip_as_string + "_zone"
ip_addr = client_ip_as_string
returned_body = ddos_dst_zone(zone_name, ip_addr)
try:
r = axapi_action(mitigator_base_url+ddos_dst_zone_path, signature=signature, payload=returned_body)
except Exception as e:
logger.info("zone not created: " + str(e))
# Commit changes
axapi_action(mitigator_base_url+write_mem_path, signature=signature)
# Log off
axapi_action(mitigator_base_url+logoff_path, signature=signature)
sys.exit(0)
else:
sys.exit(0)