ducted 2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- docs/conf.py +261 -0
- duct/__init__.py +13 -0
- duct/__main__.py +66 -0
- duct/aggregators.py +33 -0
- duct/configuration.py +177 -0
- duct/ihateprotobuf/__init__.py +0 -0
- duct/ihateprotobuf/proto_pb2.py +34 -0
- duct/interfaces.py +21 -0
- duct/logs/__init__.py +0 -0
- duct/logs/follower.py +113 -0
- duct/logs/parsers.py +170 -0
- duct/objects.py +338 -0
- duct/outputs/__init__.py +0 -0
- duct/outputs/bosun.py +68 -0
- duct/outputs/elasticsearch.py +112 -0
- duct/outputs/logger.py +40 -0
- duct/outputs/null.py +14 -0
- duct/outputs/opentsdb.py +117 -0
- duct/outputs/prometheus.py +79 -0
- duct/outputs/riemann.py +164 -0
- duct/protocol/__init__.py +0 -0
- duct/protocol/elasticsearch.py +83 -0
- duct/protocol/icmp.py +187 -0
- duct/protocol/imap4.py +11 -0
- duct/protocol/opentsdb.py +35 -0
- duct/protocol/riemann.py +220 -0
- duct/protocol/sflow/__init__.py +0 -0
- duct/protocol/sflow/protocol/__init__.py +12 -0
- duct/protocol/sflow/protocol/counters.py +295 -0
- duct/protocol/sflow/protocol/flows.py +433 -0
- duct/protocol/sflow/protocol/protocol.py +112 -0
- duct/protocol/sflow/protocol/utils.py +41 -0
- duct/protocol/sflow/protocol/xdr.py +57 -0
- duct/protocol/sflow/server.py +63 -0
- duct/protocol/ssh.py +98 -0
- duct/service.py +305 -0
- duct/sources/__init__.py +48 -0
- duct/sources/apache.py +75 -0
- duct/sources/database/__init__.py +0 -0
- duct/sources/database/elasticsearch.py +103 -0
- duct/sources/database/memcache.py +106 -0
- duct/sources/database/postgresql.py +121 -0
- duct/sources/docker.py +121 -0
- duct/sources/generator.py +58 -0
- duct/sources/haproxy.py +109 -0
- duct/sources/linux/__init__.py +0 -0
- duct/sources/linux/basic.py +459 -0
- duct/sources/linux/ipsec.py +72 -0
- duct/sources/linux/process.py +153 -0
- duct/sources/linux/sensors.py +244 -0
- duct/sources/mail.py +11 -0
- duct/sources/media/__init__.py +0 -0
- duct/sources/media/libav.py +65 -0
- duct/sources/munin.py +143 -0
- duct/sources/network.py +129 -0
- duct/sources/nginx.py +277 -0
- duct/sources/postfix.py +71 -0
- duct/sources/python/__init__.py +0 -0
- duct/sources/python/uwsgi.py +81 -0
- duct/sources/rabbitmq.py +146 -0
- duct/sources/redis.py +63 -0
- duct/sources/riak.py +51 -0
- duct/sources/riemann.py +90 -0
- duct/sources/sensors/__init__.py +0 -0
- duct/sources/sensors/environment.py +112 -0
- duct/sources/sflow.py +187 -0
- duct/sources/snmp.py +190 -0
- duct/sources/unbound.py +60 -0
- duct/tests/__init__.py +0 -0
- duct/tests/globs.py +771 -0
- duct/tests/test_duct.py +105 -0
- duct/tests/test_logs.py +86 -0
- duct/tests/test_outputs.py +59 -0
- duct/tests/test_service.py +231 -0
- duct/tests/test_sflow.py +13 -0
- duct/tests/test_sources.py +568 -0
- duct/tests/test_ssh.py +71 -0
- duct/tests/test_utils.py +28 -0
- duct/utils.py +260 -0
- ducted-2.0.dist-info/METADATA +33 -0
- ducted-2.0.dist-info/RECORD +85 -0
- ducted-2.0.dist-info/WHEEL +5 -0
- ducted-2.0.dist-info/entry_points.txt +2 -0
- ducted-2.0.dist-info/licenses/LICENSE +21 -0
- ducted-2.0.dist-info/top_level.txt +2 -0
docs/conf.py
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
#
|
|
3
|
+
# Duct documentation build configuration file, created by
|
|
4
|
+
# sphinx-quickstart on Fri Oct 17 21:58:31 2014.
|
|
5
|
+
#
|
|
6
|
+
# This file is execfile()d with the current directory set to its
|
|
7
|
+
# containing dir.
|
|
8
|
+
#
|
|
9
|
+
# Note that not all possible configuration values are present in this
|
|
10
|
+
# autogenerated file.
|
|
11
|
+
#
|
|
12
|
+
# All configuration values have a default; values that are commented out
|
|
13
|
+
# serve to show the default.
|
|
14
|
+
|
|
15
|
+
import sys
|
|
16
|
+
import os
|
|
17
|
+
|
|
18
|
+
# If extensions (or modules to document with autodoc) are in another directory,
|
|
19
|
+
# add these directories to sys.path here. If the directory is relative to the
|
|
20
|
+
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
|
21
|
+
sys.path.insert(0, os.path.abspath('../'))
|
|
22
|
+
|
|
23
|
+
# -- General configuration ------------------------------------------------
|
|
24
|
+
|
|
25
|
+
# If your documentation needs a minimal Sphinx version, state it here.
|
|
26
|
+
#needs_sphinx = '1.0'
|
|
27
|
+
|
|
28
|
+
# Add any Sphinx extension module names here, as strings. They can be
|
|
29
|
+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
|
30
|
+
# ones.
|
|
31
|
+
extensions = [
|
|
32
|
+
'sphinx.ext.autodoc',
|
|
33
|
+
'sphinx.ext.viewcode',
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
# Add any paths that contain templates here, relative to this directory.
|
|
37
|
+
templates_path = ['_templates']
|
|
38
|
+
|
|
39
|
+
# The suffix of source filenames.
|
|
40
|
+
source_suffix = '.rst'
|
|
41
|
+
|
|
42
|
+
# The encoding of source files.
|
|
43
|
+
#source_encoding = 'utf-8-sig'
|
|
44
|
+
|
|
45
|
+
# The master toctree document.
|
|
46
|
+
master_doc = 'index'
|
|
47
|
+
|
|
48
|
+
# General information about the project.
|
|
49
|
+
project = u'Duct'
|
|
50
|
+
copyright = u'2024, Colin Alston'
|
|
51
|
+
|
|
52
|
+
# The version info for the project you're documenting, acts as replacement for
|
|
53
|
+
# |version| and |release|, also used in various other places throughout the
|
|
54
|
+
# built documents.
|
|
55
|
+
#
|
|
56
|
+
# The short X.Y version.
|
|
57
|
+
version = '2.0'
|
|
58
|
+
# The full version, including alpha/beta/rc tags.
|
|
59
|
+
release = '2.0'
|
|
60
|
+
|
|
61
|
+
# The language for content autogenerated by Sphinx. Refer to documentation
|
|
62
|
+
# for a list of supported languages.
|
|
63
|
+
#language = None
|
|
64
|
+
|
|
65
|
+
# There are two options for replacing |today|: either, you set today to some
|
|
66
|
+
# non-false value, then it is used:
|
|
67
|
+
#today = ''
|
|
68
|
+
# Else, today_fmt is used as the format for a strftime call.
|
|
69
|
+
#today_fmt = '%B %d, %Y'
|
|
70
|
+
|
|
71
|
+
# List of patterns, relative to source directory, that match files and
|
|
72
|
+
# directories to ignore when looking for source files.
|
|
73
|
+
exclude_patterns = ['_build']
|
|
74
|
+
|
|
75
|
+
# The reST default role (used for this markup: `text`) to use for all
|
|
76
|
+
# documents.
|
|
77
|
+
#default_role = None
|
|
78
|
+
|
|
79
|
+
# If true, '()' will be appended to :func: etc. cross-reference text.
|
|
80
|
+
#add_function_parentheses = True
|
|
81
|
+
|
|
82
|
+
# If true, the current module name will be prepended to all description
|
|
83
|
+
# unit titles (such as .. function::).
|
|
84
|
+
#add_module_names = True
|
|
85
|
+
|
|
86
|
+
# If true, sectionauthor and moduleauthor directives will be shown in the
|
|
87
|
+
# output. They are ignored by default.
|
|
88
|
+
#show_authors = False
|
|
89
|
+
|
|
90
|
+
# The name of the Pygments (syntax highlighting) style to use.
|
|
91
|
+
pygments_style = 'sphinx'
|
|
92
|
+
|
|
93
|
+
# A list of ignored prefixes for module index sorting.
|
|
94
|
+
#modindex_common_prefix = []
|
|
95
|
+
|
|
96
|
+
# If true, keep warnings as "system message" paragraphs in the built documents.
|
|
97
|
+
#keep_warnings = False
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
# -- Options for HTML output ----------------------------------------------
|
|
101
|
+
|
|
102
|
+
# The theme to use for HTML and HTML Help pages. See the documentation for
|
|
103
|
+
# a list of builtin themes.
|
|
104
|
+
html_theme = 'alabaster'
|
|
105
|
+
|
|
106
|
+
# Theme options are theme-specific and customize the look and feel of a theme
|
|
107
|
+
# further. For a list of options available for each theme, see the
|
|
108
|
+
# documentation.
|
|
109
|
+
#html_theme_options = {}
|
|
110
|
+
|
|
111
|
+
# Add any paths that contain custom themes here, relative to this directory.
|
|
112
|
+
#html_theme_path = []
|
|
113
|
+
|
|
114
|
+
# The name for this set of Sphinx documents. If None, it defaults to
|
|
115
|
+
# "<project> v<release> documentation".
|
|
116
|
+
#html_title = None
|
|
117
|
+
|
|
118
|
+
# A shorter title for the navigation bar. Default is the same as html_title.
|
|
119
|
+
#html_short_title = None
|
|
120
|
+
|
|
121
|
+
# The name of an image file (relative to this directory) to place at the top
|
|
122
|
+
# of the sidebar.
|
|
123
|
+
#html_logo = None
|
|
124
|
+
|
|
125
|
+
# The name of an image file (within the static path) to use as favicon of the
|
|
126
|
+
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
|
|
127
|
+
# pixels large.
|
|
128
|
+
#html_favicon = None
|
|
129
|
+
|
|
130
|
+
# Add any paths that contain custom static files (such as style sheets) here,
|
|
131
|
+
# relative to this directory. They are copied after the builtin static files,
|
|
132
|
+
# so a file named "default.css" will overwrite the builtin "default.css".
|
|
133
|
+
html_static_path = ['_static']
|
|
134
|
+
|
|
135
|
+
# Add any extra paths that contain custom files (such as robots.txt or
|
|
136
|
+
# .htaccess) here, relative to this directory. These files are copied
|
|
137
|
+
# directly to the root of the documentation.
|
|
138
|
+
#html_extra_path = []
|
|
139
|
+
|
|
140
|
+
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
|
|
141
|
+
# using the given strftime format.
|
|
142
|
+
#html_last_updated_fmt = '%b %d, %Y'
|
|
143
|
+
|
|
144
|
+
# If true, SmartyPants will be used to convert quotes and dashes to
|
|
145
|
+
# typographically correct entities.
|
|
146
|
+
#html_use_smartypants = True
|
|
147
|
+
|
|
148
|
+
# Custom sidebar templates, maps document names to template names.
|
|
149
|
+
#html_sidebars = {}
|
|
150
|
+
|
|
151
|
+
# Additional templates that should be rendered to pages, maps page names to
|
|
152
|
+
# template names.
|
|
153
|
+
#html_additional_pages = {}
|
|
154
|
+
|
|
155
|
+
# If false, no module index is generated.
|
|
156
|
+
#html_domain_indices = True
|
|
157
|
+
|
|
158
|
+
# If false, no index is generated.
|
|
159
|
+
#html_use_index = True
|
|
160
|
+
|
|
161
|
+
# If true, the index is split into individual pages for each letter.
|
|
162
|
+
#html_split_index = False
|
|
163
|
+
|
|
164
|
+
# If true, links to the reST sources are added to the pages.
|
|
165
|
+
#html_show_sourcelink = True
|
|
166
|
+
|
|
167
|
+
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
|
|
168
|
+
#html_show_sphinx = True
|
|
169
|
+
|
|
170
|
+
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
|
|
171
|
+
#html_show_copyright = True
|
|
172
|
+
|
|
173
|
+
# If true, an OpenSearch description file will be output, and all pages will
|
|
174
|
+
# contain a <link> tag referring to it. The value of this option must be the
|
|
175
|
+
# base URL from which the finished HTML is served.
|
|
176
|
+
#html_use_opensearch = ''
|
|
177
|
+
|
|
178
|
+
# This is the file name suffix for HTML files (e.g. ".xhtml").
|
|
179
|
+
#html_file_suffix = None
|
|
180
|
+
|
|
181
|
+
# Output file base name for HTML help builder.
|
|
182
|
+
htmlhelp_basename = 'Ductdoc'
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
# -- Options for LaTeX output ---------------------------------------------
|
|
186
|
+
|
|
187
|
+
latex_elements = {
|
|
188
|
+
# The paper size ('letterpaper' or 'a4paper').
|
|
189
|
+
#'papersize': 'letterpaper',
|
|
190
|
+
|
|
191
|
+
# The font size ('10pt', '11pt' or '12pt').
|
|
192
|
+
#'pointsize': '10pt',
|
|
193
|
+
|
|
194
|
+
# Additional stuff for the LaTeX preamble.
|
|
195
|
+
#'preamble': '',
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
# Grouping the document tree into LaTeX files. List of tuples
|
|
199
|
+
# (source start file, target name, title,
|
|
200
|
+
# author, documentclass [howto, manual, or own class]).
|
|
201
|
+
latex_documents = [
|
|
202
|
+
('index', 'Duct.tex', u'Duct Documentation',
|
|
203
|
+
u'Colin Alston', 'manual'),
|
|
204
|
+
]
|
|
205
|
+
|
|
206
|
+
# The name of an image file (relative to this directory) to place at the top of
|
|
207
|
+
# the title page.
|
|
208
|
+
#latex_logo = None
|
|
209
|
+
|
|
210
|
+
# For "manual" documents, if this is true, then toplevel headings are parts,
|
|
211
|
+
# not chapters.
|
|
212
|
+
#latex_use_parts = False
|
|
213
|
+
|
|
214
|
+
# If true, show page references after internal links.
|
|
215
|
+
#latex_show_pagerefs = False
|
|
216
|
+
|
|
217
|
+
# If true, show URL addresses after external links.
|
|
218
|
+
#latex_show_urls = False
|
|
219
|
+
|
|
220
|
+
# Documents to append as an appendix to all manuals.
|
|
221
|
+
#latex_appendices = []
|
|
222
|
+
|
|
223
|
+
# If false, no module index is generated.
|
|
224
|
+
#latex_domain_indices = True
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
# -- Options for manual page output ---------------------------------------
|
|
228
|
+
|
|
229
|
+
# One entry per manual page. List of tuples
|
|
230
|
+
# (source start file, name, description, authors, manual section).
|
|
231
|
+
man_pages = [
|
|
232
|
+
('index', 'duct', u'Duct Documentation',
|
|
233
|
+
[u'Colin Alston'], 1)
|
|
234
|
+
]
|
|
235
|
+
|
|
236
|
+
# If true, show URL addresses after external links.
|
|
237
|
+
#man_show_urls = False
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
# -- Options for Texinfo output -------------------------------------------
|
|
241
|
+
|
|
242
|
+
# Grouping the document tree into Texinfo files. List of tuples
|
|
243
|
+
# (source start file, target name, title, author,
|
|
244
|
+
# dir menu entry, description, category)
|
|
245
|
+
texinfo_documents = [
|
|
246
|
+
('index', 'Duct', u'Duct Documentation',
|
|
247
|
+
u'Colin Alston', 'Duct', 'One line description of project.',
|
|
248
|
+
'Miscellaneous'),
|
|
249
|
+
]
|
|
250
|
+
|
|
251
|
+
# Documents to append as an appendix to all manuals.
|
|
252
|
+
#texinfo_appendices = []
|
|
253
|
+
|
|
254
|
+
# If false, no module index is generated.
|
|
255
|
+
#texinfo_domain_indices = True
|
|
256
|
+
|
|
257
|
+
# How to display URL addresses: 'footnote', 'no', or 'inline'.
|
|
258
|
+
#texinfo_show_urls = 'footnote'
|
|
259
|
+
|
|
260
|
+
# If true, do not generate a @detailmenu in the "Top" node's menu.
|
|
261
|
+
#texinfo_no_detailmenu = False
|
duct/__init__.py
ADDED
duct/__main__.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Duct — asyncio entry point
|
|
3
|
+
|
|
4
|
+
Usage:
|
|
5
|
+
ductd -c duct.yml
|
|
6
|
+
python -m duct -c duct.yml
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import argparse
|
|
10
|
+
import asyncio
|
|
11
|
+
import logging
|
|
12
|
+
import signal
|
|
13
|
+
|
|
14
|
+
from duct.configuration import ConfigFile
|
|
15
|
+
from duct.service import DuctService
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def main():
|
|
19
|
+
"""Entry point for the duct daemon."""
|
|
20
|
+
parser = argparse.ArgumentParser(
|
|
21
|
+
description='Duct — A monitoring agent and event processor'
|
|
22
|
+
)
|
|
23
|
+
parser.add_argument(
|
|
24
|
+
'-c', '--config',
|
|
25
|
+
default='duct.yml',
|
|
26
|
+
help='Configuration file (default: duct.yml)',
|
|
27
|
+
)
|
|
28
|
+
parser.add_argument(
|
|
29
|
+
'-v', '--verbose',
|
|
30
|
+
action='store_true',
|
|
31
|
+
help='Enable verbose/debug logging',
|
|
32
|
+
)
|
|
33
|
+
args = parser.parse_args()
|
|
34
|
+
|
|
35
|
+
log_level = logging.DEBUG if args.verbose else logging.INFO
|
|
36
|
+
logging.basicConfig(
|
|
37
|
+
level=log_level,
|
|
38
|
+
format='%(asctime)s %(name)s %(levelname)s %(message)s',
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
asyncio.run(_run(args.config))
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
async def _run(config_path):
|
|
45
|
+
config = ConfigFile(config_path)
|
|
46
|
+
svc = DuctService(config)
|
|
47
|
+
|
|
48
|
+
loop = asyncio.get_running_loop()
|
|
49
|
+
|
|
50
|
+
stop_event = asyncio.Event()
|
|
51
|
+
|
|
52
|
+
def _handle_signal():
|
|
53
|
+
stop_event.set()
|
|
54
|
+
|
|
55
|
+
for sig in (signal.SIGINT, signal.SIGTERM):
|
|
56
|
+
loop.add_signal_handler(sig, _handle_signal)
|
|
57
|
+
|
|
58
|
+
await svc.startService()
|
|
59
|
+
|
|
60
|
+
await stop_event.wait()
|
|
61
|
+
|
|
62
|
+
await svc.stopService()
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
if __name__ == '__main__':
|
|
66
|
+
main()
|
duct/aggregators.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: aggregators
|
|
3
|
+
:synopsis: Aggregation functions
|
|
4
|
+
|
|
5
|
+
.. moduleauthor:: Colin Alston <colin@imcol.in>
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def Counter32(al, br, delta):
|
|
10
|
+
"""32bit counter aggregator with wrapping
|
|
11
|
+
"""
|
|
12
|
+
if br < al:
|
|
13
|
+
ch = 4294967295 - al
|
|
14
|
+
return (ch + br) / float(delta)
|
|
15
|
+
|
|
16
|
+
return (br - al) / float(delta)
|
|
17
|
+
|
|
18
|
+
def Counter64(al, br, delta):
|
|
19
|
+
"""64bit counter aggregator with wrapping
|
|
20
|
+
"""
|
|
21
|
+
if br < al:
|
|
22
|
+
ch = 18446744073709551615 - al
|
|
23
|
+
return (ch + br) / float(delta)
|
|
24
|
+
|
|
25
|
+
return (br - al) / float(delta)
|
|
26
|
+
|
|
27
|
+
def Counter(al, br, delta):
|
|
28
|
+
"""Counter derivative
|
|
29
|
+
"""
|
|
30
|
+
if br < al:
|
|
31
|
+
return None
|
|
32
|
+
|
|
33
|
+
return (br - al) / float(delta)
|
duct/configuration.py
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: configuration
|
|
3
|
+
:synopsis: Configuration file parser
|
|
4
|
+
|
|
5
|
+
.. moduleauthor:: Colin Alston <colin@imcol.in>
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import os
|
|
9
|
+
import itertools
|
|
10
|
+
import copy
|
|
11
|
+
import logging
|
|
12
|
+
|
|
13
|
+
import yaml
|
|
14
|
+
|
|
15
|
+
log = logging.getLogger(__name__)
|
|
16
|
+
|
|
17
|
+
class ConfigurationError(Exception):
|
|
18
|
+
"""General exception class for Duct configuration issues
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
class ConfigFile(object):
|
|
22
|
+
"""Duct configuration file parser and accessor
|
|
23
|
+
"""
|
|
24
|
+
def __init__(self, path):
|
|
25
|
+
if os.path.exists(path):
|
|
26
|
+
with open(path, 'rt', encoding='utf-8') as conf:
|
|
27
|
+
self.raw_config = yaml.load(conf, Loader=yaml.SafeLoader)
|
|
28
|
+
|
|
29
|
+
if not self.raw_config:
|
|
30
|
+
self.raw_config = {}
|
|
31
|
+
log.warning("Warning: No configuration content")
|
|
32
|
+
else:
|
|
33
|
+
raise ConfigurationError(f"Configuration file '{path}' not found")
|
|
34
|
+
|
|
35
|
+
self.known_items = {
|
|
36
|
+
'sources': list,
|
|
37
|
+
'outputs': list,
|
|
38
|
+
'interval': (float, int,),
|
|
39
|
+
'ttl': (float, int,),
|
|
40
|
+
'blueprint': list,
|
|
41
|
+
'ssh_key': str,
|
|
42
|
+
'ssh_user': str,
|
|
43
|
+
'toolbox': dict
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
self._parse_config()
|
|
47
|
+
|
|
48
|
+
def _validate_type(self, item, vtype):
|
|
49
|
+
if not isinstance(vtype, tuple):
|
|
50
|
+
vtype = (vtype, )
|
|
51
|
+
|
|
52
|
+
parse = False
|
|
53
|
+
for vt in vtype:
|
|
54
|
+
try:
|
|
55
|
+
assert isinstance(self.raw_config.get(item, vt()), vtype)
|
|
56
|
+
parse = True
|
|
57
|
+
except AssertionError:
|
|
58
|
+
pass
|
|
59
|
+
|
|
60
|
+
if not parse:
|
|
61
|
+
raise ConfigurationError(
|
|
62
|
+
f"{item} must be one of type {repr(vtype)}")
|
|
63
|
+
|
|
64
|
+
def _validate_config(self):
|
|
65
|
+
for key, val in self.known_items.items():
|
|
66
|
+
self._validate_type(key, val)
|
|
67
|
+
|
|
68
|
+
def _parse_config(self):
|
|
69
|
+
self._merge_includes()
|
|
70
|
+
|
|
71
|
+
self._validate_config()
|
|
72
|
+
|
|
73
|
+
self._build_blueprints()
|
|
74
|
+
|
|
75
|
+
def _merge_includes(self):
|
|
76
|
+
def both(i1, i2, t):
|
|
77
|
+
return isinstance(i1, t) and isinstance(i2, t)
|
|
78
|
+
|
|
79
|
+
paths = self.raw_config.get('include_path', [])
|
|
80
|
+
if not isinstance(paths, list):
|
|
81
|
+
paths = [paths]
|
|
82
|
+
|
|
83
|
+
paths2 = self.raw_config.get('include', [])
|
|
84
|
+
if not isinstance(paths2, list):
|
|
85
|
+
paths2 = [paths2]
|
|
86
|
+
|
|
87
|
+
paths.extend(paths2)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
for ipath in paths:
|
|
91
|
+
if os.path.exists(ipath):
|
|
92
|
+
files = [os.path.join(ipath, fi) for fi in os.listdir(ipath)
|
|
93
|
+
if fi.endswith('.yml') or fi.endswith('.yaml')]
|
|
94
|
+
|
|
95
|
+
for conf_file in files:
|
|
96
|
+
with open(conf_file, 'rt', encoding='utf-8') as yaml_path:
|
|
97
|
+
conf = yaml.load(yaml_path, Loader=yaml.SafeLoader)
|
|
98
|
+
for key, val in conf.items():
|
|
99
|
+
if key in self.raw_config:
|
|
100
|
+
if both(val, self.raw_config[key], dict):
|
|
101
|
+
# Merge dicts
|
|
102
|
+
for k2, v2 in val.items():
|
|
103
|
+
self.raw_config[key][k2] = v2
|
|
104
|
+
|
|
105
|
+
elif both(val, self.raw_config[key], list):
|
|
106
|
+
# Extend lists
|
|
107
|
+
self.raw_config[key].extend(val)
|
|
108
|
+
else:
|
|
109
|
+
# Overwrite
|
|
110
|
+
self.raw_config[key] = val
|
|
111
|
+
else:
|
|
112
|
+
self.raw_config[key] = val
|
|
113
|
+
log.warning('Loadded additional configuration from %s',
|
|
114
|
+
conf_file)
|
|
115
|
+
else:
|
|
116
|
+
log.warning('Config Error: include_path %s does not exist',
|
|
117
|
+
ipath)
|
|
118
|
+
|
|
119
|
+
def _build_blueprints(self):
|
|
120
|
+
# Turn toolboxes into a dict
|
|
121
|
+
toolboxes = self.raw_config.get('toolbox', {})
|
|
122
|
+
blueprints = self.raw_config.get('blueprint', [])
|
|
123
|
+
|
|
124
|
+
if blueprints:
|
|
125
|
+
# Make sure raw config stubs exist if we have any blueprints
|
|
126
|
+
if 'sources' not in self.raw_config:
|
|
127
|
+
self.raw_config['sources'] = []
|
|
128
|
+
|
|
129
|
+
for blueprint in blueprints:
|
|
130
|
+
tbs = blueprint['toolbox']
|
|
131
|
+
# Listify it so we can inherit multiple toolboxes
|
|
132
|
+
if not isinstance(toolboxes, list):
|
|
133
|
+
tbs = [tbs]
|
|
134
|
+
|
|
135
|
+
tbs = [toolboxes[tool] for tool in tbs]
|
|
136
|
+
|
|
137
|
+
# Compute a dot product of all the config settings vectors
|
|
138
|
+
inversions = []
|
|
139
|
+
for key, val in blueprint.get('sets', {}).items():
|
|
140
|
+
inversions.append([(key, jay) for jay in val])
|
|
141
|
+
|
|
142
|
+
for options in itertools.product(*inversions):
|
|
143
|
+
for toolbox in tbs:
|
|
144
|
+
for source in toolbox.get('sources', []):
|
|
145
|
+
# Make a copy of the source dict
|
|
146
|
+
mysource = copy.copy(source)
|
|
147
|
+
|
|
148
|
+
# Merge toolbox defaults
|
|
149
|
+
for key, val in toolbox.get('defaults', {}).items():
|
|
150
|
+
mysource[key] = val
|
|
151
|
+
|
|
152
|
+
# Merge blueprint defaults
|
|
153
|
+
for key, val in blueprint.get('defaults', {}).items():
|
|
154
|
+
mysource[key] = val
|
|
155
|
+
|
|
156
|
+
# Merge set permutation
|
|
157
|
+
for key, val in options:
|
|
158
|
+
mysource[key] = val
|
|
159
|
+
|
|
160
|
+
# Bolt it into our real config file
|
|
161
|
+
self.raw_config['sources'].append(mysource)
|
|
162
|
+
|
|
163
|
+
# Free a tiny bit of memory
|
|
164
|
+
if 'toolbox' in self.raw_config:
|
|
165
|
+
del self.raw_config['toolbox']
|
|
166
|
+
|
|
167
|
+
if 'blueprint' in self.raw_config:
|
|
168
|
+
del self.raw_config['blueprint']
|
|
169
|
+
|
|
170
|
+
def get(self, item, default=None):
|
|
171
|
+
"""Returns `item` from configuration if it exists, otherwise returns
|
|
172
|
+
`default`
|
|
173
|
+
"""
|
|
174
|
+
return self.raw_config.get(item, default)
|
|
175
|
+
|
|
176
|
+
def __getitem__(self, item):
|
|
177
|
+
return self.raw_config[item]
|
|
File without changes
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
|
3
|
+
# source: proto.proto
|
|
4
|
+
"""Generated protocol buffer code."""
|
|
5
|
+
from google.protobuf.internal import builder as _builder
|
|
6
|
+
from google.protobuf import descriptor as _descriptor
|
|
7
|
+
from google.protobuf import descriptor_pool as _descriptor_pool
|
|
8
|
+
from google.protobuf import symbol_database as _symbol_database
|
|
9
|
+
# @@protoc_insertion_point(imports)
|
|
10
|
+
|
|
11
|
+
_sym_db = _symbol_database.Default()
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0bproto.proto\"\x81\x01\n\x05State\x12\x0c\n\x04time\x18\x01 \x01(\x03\x12\r\n\x05state\x18\x02 \x01(\t\x12\x0f\n\x07service\x18\x03 \x01(\t\x12\x0c\n\x04host\x18\x04 \x01(\t\x12\x13\n\x0b\x64\x65scription\x18\x05 \x01(\t\x12\x0c\n\x04once\x18\x06 \x01(\x08\x12\x0c\n\x04tags\x18\x07 \x03(\t\x12\x0b\n\x03ttl\x18\x08 \x01(\x02\"\xce\x01\n\x05\x45vent\x12\x0c\n\x04time\x18\x01 \x01(\x03\x12\r\n\x05state\x18\x02 \x01(\t\x12\x0f\n\x07service\x18\x03 \x01(\t\x12\x0c\n\x04host\x18\x04 \x01(\t\x12\x13\n\x0b\x64\x65scription\x18\x05 \x01(\t\x12\x0c\n\x04tags\x18\x07 \x03(\t\x12\x0b\n\x03ttl\x18\x08 \x01(\x02\x12\x1e\n\nattributes\x18\t \x03(\x0b\x32\n.Attribute\x12\x15\n\rmetric_sint64\x18\r \x01(\x12\x12\x10\n\x08metric_d\x18\x0e \x01(\x01\x12\x10\n\x08metric_f\x18\x0f \x01(\x02\"\x17\n\x05Query\x12\x0e\n\x06string\x18\x01 \x01(\t\"g\n\x03Msg\x12\n\n\x02ok\x18\x02 \x01(\x08\x12\r\n\x05\x65rror\x18\x03 \x01(\t\x12\x16\n\x06states\x18\x04 \x03(\x0b\x32\x06.State\x12\x15\n\x05query\x18\x05 \x01(\x0b\x32\x06.Query\x12\x16\n\x06\x65vents\x18\x06 \x03(\x0b\x32\x06.Event\"\'\n\tAttribute\x12\x0b\n\x03key\x18\x01 \x02(\t\x12\r\n\x05value\x18\x02 \x01(\tB\x1a\n\x11\x63om.aphyr.riemannB\x05Proto')
|
|
17
|
+
|
|
18
|
+
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals())
|
|
19
|
+
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'proto_pb2', globals())
|
|
20
|
+
if _descriptor._USE_C_DESCRIPTORS == False:
|
|
21
|
+
|
|
22
|
+
DESCRIPTOR._options = None
|
|
23
|
+
DESCRIPTOR._serialized_options = b'\n\021com.aphyr.riemannB\005Proto'
|
|
24
|
+
_STATE._serialized_start=16
|
|
25
|
+
_STATE._serialized_end=145
|
|
26
|
+
_EVENT._serialized_start=148
|
|
27
|
+
_EVENT._serialized_end=354
|
|
28
|
+
_QUERY._serialized_start=356
|
|
29
|
+
_QUERY._serialized_end=379
|
|
30
|
+
_MSG._serialized_start=381
|
|
31
|
+
_MSG._serialized_end=484
|
|
32
|
+
_ATTRIBUTE._serialized_start=486
|
|
33
|
+
_ATTRIBUTE._serialized_end=525
|
|
34
|
+
# @@protoc_insertion_point(module_scope)
|
duct/interfaces.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: interfaces
|
|
3
|
+
:synopsis: Generic interfaces
|
|
4
|
+
|
|
5
|
+
.. moduleauthor:: Colin Alston <colin@imcol.in>
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from zope.interface import Interface
|
|
9
|
+
|
|
10
|
+
# pylint: disable=E0239,W0221
|
|
11
|
+
class IDuctProtocol(Interface):
|
|
12
|
+
"""Interface for Duct client protocols"""
|
|
13
|
+
|
|
14
|
+
def sendEvent(self, event):
|
|
15
|
+
"""Sends an event to this client"""
|
|
16
|
+
|
|
17
|
+
class IDuctSource(Interface):
|
|
18
|
+
"""Interface for Duct metric sources"""
|
|
19
|
+
|
|
20
|
+
def get(self):
|
|
21
|
+
"""Return this source data"""
|
duct/logs/__init__.py
ADDED
|
File without changes
|