1# -*- coding: utf-8 -*-
2'''
3Config defaults.
4'''
5from __future__ import absolute_import
6
7import os
8import tempfile
9import logging
10import napalm_logs.ext.six as six
11
12# config
13ROOT_DIR = '/'
14#CONFIG_FILE = os.path.join(ROOT_DIR, 'etc', 'napalm', 'logs')
15CONFIG_FILE = os.path.join('/usr/local', 'etc', 'napalm', 'logs')
16ADDRESS = '0.0.0.0'
17PORT = 514
18LISTENER = 'udp'
19LOGGER = None
20PUBLISHER = 'zmq'
21MAX_TCP_CLIENTS = 5
22PUBLISH_ADDRESS = '0.0.0.0'
23PUBLISH_PORT = 49017
24AUTH_ADDRESS = '0.0.0.0'
25AUTH_PORT = 49018
26AUTH_MAX_TRY = 5
27AUTH_TIMEOUT = 1
28SERIALIZER = 'msgpack'
29LOG_LEVEL = 'warning'
30LOG_FORMAT = '%(asctime)s,%(msecs)03.0f [%(name)-17s][%(levelname)-8s] %(message)s'
31LOG_FILE = os.path.join(ROOT_DIR, 'var', 'log', 'napalm', 'logs')
32LOG_FILE_CLI_OPTIONS = ('cli', 'screen')
33ZMQ_INTERNAL_HWM = 1000
34METRICS_ADDRESS = '0.0.0.0'
35METRICS_PORT = 9443
36METRICS_DIR = "/tmp/napalm_logs_metrics"
37BUFFER_EXPIRE_TIME = 5
38
39# Allowed names for the init files.
40OS_INIT_FILENAMES = (
41    '__init__',
42    'init',
43    'index'
44)
45# The name of the function to be invoked when extracting the parts from the
46#   raw syslog message.
47INIT_RUN_FUN = 'extract'
48# The name of the function to be invoked when the OpenConfig / IETF object
49#   is generated.
50CONFIG_RUN_FUN = 'emit'
51
52UNKNOWN_DEVICE_NAME = 'unknown'
53
54LISTENER_OPTS = {
55}
56
57LOGGER_OPTS = {
58    'send_raw': False,
59    'send_unknown': False
60}
61
62PUBLISHER_OPTS = {
63    'send_raw': False,
64    'send_unknown': False
65}
66
67LOGGING_LEVEL = {
68    'debug': logging.DEBUG,
69    'info': logging.INFO,
70    'warning': logging.WARNING,
71    'error': logging.ERROR,
72    'critical': logging.CRITICAL
73}
74
75VALID_CONFIG = {
76    'prefixes': [
77        {
78            'values': {
79                'tag': six.string_type
80            },
81            'line': six.string_type
82        }
83    ],
84    'messages': [
85        {
86            # 'error' should be unique and vendor agnostic.
87            # Currently we are using the JUNOS syslog message name as the canonical name.
88            # This may change if we are able to find a more well defined naming system.
89            'error': six.string_type,
90            'tag': six.string_type,
91            'values': dict,
92            'line': six.string_type,
93            'model': six.string_type,
94            'mapping': {
95                'variables': dict,
96                'static': dict
97            }
98        }
99    ]
100}
101
102# listener
103BUFFER_SIZE = 1024
104REUSE_PORT = False
105TIMEOUT = 60
106
107# device
108DEFAULT_DELIM = '//'
109
110# proc
111PROC_DEAD_FLAGS = ('T', 'X', 'Z')
112
113# zmq proxies
114TMP_DIR = tempfile.gettempdir()
115AUTH_IPC_URL = 'ipc://{}'.format(os.path.join(TMP_DIR, 'napalm-logs-auth'))
116# the auth proxy is not used yet, TODO
117LST_IPC_URL = 'ipc://{}'.format(os.path.join(TMP_DIR, 'napalm-logs-lst'))
118SRV_IPC_URL = 'ipc://{}'.format(os.path.join(TMP_DIR, 'napalm-logs-srv'))
119# the publisher IPC is used as proxy
120# the devices send the messages to the proxy
121# and the publisher subscribes to the proxy and
122# publishes them on the desired transport
123DEV_IPC_URL = 'ipc://{}'.format(os.path.join(TMP_DIR, 'napalm-logs-dev'))
124# the server publishes to a separate IPC per device
125PUB_PX_IPC_URL = 'ipc://{}'.format(os.path.join(TMP_DIR, 'napalm-logs-pub-px'))
126PUB_IPC_URL = 'ipc://{}'.format(os.path.join(TMP_DIR, 'napalm-logs-pub'))
127
128# auth
129AUTH_KEEP_ALIVE = b'KEEPALIVE'
130AUTH_KEEP_ALIVE_ACK = b'KEEPALIVEACK'
131AUTH_KEEP_ALIVE_INTERVAL = 10
132AUTH_MAX_CONN = 5
133AUTH_TIMEOUT = 5
134MAGIC_ACK = b'ACK'
135MAGIC_REQ = b'INIT'
136AUTH_CIPHER = 'ECDHE-RSA-AES256-GCM-SHA384'
137
138OPEN_CONFIG_NO_MODEL = 'NO_MODEL'
139