~aasg/nixexprs

ref: 880638840c289a9d561d636725e68b924bc4726c nixexprs/modules/services/networking/monitoring/bird-lg-config.py -rw-r--r-- 1.4 KiB
88063884 — Aluísio Augusto Silva Gonçalves bird-lg: Fix import in config loader script 3 months ago
                                                                                
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
# Put everything inside a function to avoid polluting the script's
# global namespace.
def _config_loader_main():
    """ Loads bird-lg and gunicorn config files. """
    import os

    def log_to_syslog():
        """ Configures the logging module to log everything to syslog. """
        from logging.config import dictConfig
        import socket

        dictConfig(
            {
                "version": 1,
                "formatters": {"msgonly": {"format": "%(message)s"}},
                "handlers": {
                    "syslog": {
                        "class": "logging.handlers.SysLogHandler",
                        "formatter": "msgonly",
                        "address": "/dev/log",
                        "socktype": socket.SOCK_DGRAM,
                    }
                },
                "root": {"handlers": ["syslog"]},
            }
        )

    def load_config_files():
        """ Loads JSON config files specified in the BIRD_LG_CONFIG_FILES environment variable. """
        import json

        for filename in os.environ["BIRD_LG_CONFIG_FILES"].split(os.pathsep):
            with open(filename, "r") as file:
                config = json.load(file)
                globals().update(config)

    if os.environ.get("BIRD_LG_SYSLOG"):
        log_to_syslog()
    if os.environ.get("BIRD_LG_CONFIG_FILES"):
        load_config_files()


_config_loader_main()
del _config_loader_main