forked from vladimirs-git/fortigate-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitor.py
73 lines (64 loc) · 1.68 KB
/
monitor.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
"""Monitor examples.
- Get directory of monitor options (schema)
- Get all ipv4 routes
- Get static ipv4 routes
- Get route to interested ip address
"""
import logging
from pprint import pprint
from fortigate_api import Fortigate
logging.getLogger().setLevel(logging.DEBUG)
HOST = "host"
USERNAME = "username"
PASSWORD = "password"
fgt = Fortigate(host=HOST, username=USERNAME, password=PASSWORD)
# Get directory of monitor options (schema)
directory = fgt.directory("api/v2/monitor")
pprint(directory)
# [{"access_group": "sysgrp.cfg",
# "action": "select",
# "name": "health",
# "path": "firewall",
# "request": {"http_method": "GET"},
# "response": {"type": "array"},
# "summary": "List configured load balance server health monitors.",
# "supported": True},
# ...
# Get all ipv4 routes
routes = fgt.get(url="api/v2/monitor/router/ipv4")
pprint(routes)
# [{"distance": 20,
# "gateway": "10.0.0.1",
# "install_date": 1681965487,
# "interface": "tunnel1",
# "ip_mask": "10.0.0.0/8",
# "ip_version": 4,
# "is_tunnel_route": True,
# "metric": 100,
# "priority": 1,
# "tunnel_parent": "tunnel1",
# "type": "bgp",
# "vrf": 0},
# ...
# ]
# Get static ipv4 routes
routes = fgt.get(url="api/v2/monitor/router/ipv4?type=static")
pprint(routes)
# [{"distance": 10,
# "gateway": "10.0.1.1",
# "interface": "wan1",
# "ip_mask": "0.0.0.0/0",
# "ip_version": 4,
# "metric": 0,
# "priority": 1,
# "type": "static",
# "vrf": 0},
# ...
# ]
# Get route to interested ip address
routes = fgt.get(url="api/v2/monitor/router/lookup?destination=10.1.1.1")
pprint(routes)
# {"gateway": "10.0.0.1",
# "interface": "tunnel1",
# "network": "10.0.0.0/10",
# "success": True}