This repository has been archived by the owner on Mar 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.py
executable file
·86 lines (71 loc) · 2.31 KB
/
main.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
#!/usr/bin/env python3
import argparse
import logging
import socket
import sys
import yaml
import falcon
from handler import metricHandler
from wsgiref import simple_server
def falcon_app(config, logger, port=9200, addr="0.0.0.0"):
logger.info(f"Starting Arista eAPI exporter on Port {addr}:{port}")
api = falcon.App()
api.add_route("/arista", metricHandler(config=config))
try:
httpd = simple_server.make_server(addr, port, api)
except Exception as e:
logger.error(f"Couldn't start Server: {e}")
return 1
try:
httpd.serve_forever()
except KeyboardInterrupt:
httpd.server_close()
logger.info("Stopping Arista eAPI Prometheus Server")
def main():
# command line options
parser = argparse.ArgumentParser()
parser.add_argument(
"-c",
"--config",
help="Specify config yaml file",
metavar="FILE",
required=False,
default="config.yml",
)
args = parser.parse_args()
# get the config
try:
with open(args.config, "r") as stream:
config = yaml.safe_load(stream)
except FileNotFoundError:
logging.error(f"File not found: {args.config}")
return 1
if "listen_addr" not in config:
config["listen_addr"] = "0.0.0.0"
if "disable_certificate_validation" not in config:
config["disable_certificate_validation"] = False
if config["disable_certificate_validation"] is not True:
logging.error(
(
"Certificate validation is not supported by pyeapi"
"library. Please specify "
"disable_certificate_validation: true in your "
"configuration file. Upstream issue: "
"https://github.com/arista-eosplus/pyeapi/issues/174"
)
)
return 1
# enable logging
logger = logging.getLogger()
if config["loglevel"]:
logger.setLevel(logging.getLevelName(config["loglevel"].upper()))
else:
logger.setLevel("INFO")
format = (
"%(asctime)-15s %(process)d %(levelname)s "
"%(filename)s:%(lineno)d %(message)s"
)
logging.basicConfig(stream=sys.stdout, format=format)
falcon_app(config, logger, port=config["listen_port"], addr=config["listen_addr"])
if __name__ == "__main__":
main()