Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CONFV2:: NEW CONF FORMAT, CONF VALIDATION, TESTS #139

Merged
merged 1 commit into from
Dec 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions manager/Administration.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
"""This file is part of Vulture 3.

Vulture 3 is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Vulture 3 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Vulture 3. If not, see http://www.gnu.org/licenses/.
"""
__author__ = "Hugo SOSZYNSKI"
__credits__ = []
__license__ = "GPLv3"
Expand Down
15 changes: 0 additions & 15 deletions manager/HeartBeat.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
"""This file is part of Vulture 3.

Vulture 3 is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Vulture 3 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Vulture 3. If not, see http://www.gnu.org/licenses/.
"""
__author__ = "Hugo SOSZYNSKI"
__credits__ = []
__license__ = "GPLv3"
Expand Down
15 changes: 0 additions & 15 deletions manager/JsonSocket.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
"""This file is part of Vulture 3.

Vulture 3 is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Vulture 3 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Vulture 3. If not, see http://www.gnu.org/licenses/.
"""
__author__ = "Hugo SOSZYNSKI"
__credits__ = []
__license__ = "GPLv3"
Expand Down
150 changes: 10 additions & 140 deletions manager/Services.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
"""This file is part of Vulture 3.

Vulture 3 is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Vulture 3 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Vulture 3. If not, see http://www.gnu.org/licenses/.
"""
__author__ = "Hugo SOSZYNSKI"
__credits__ = []
__license__ = "GPLv3"
Expand All @@ -34,6 +19,8 @@
from HeartBeat import HeartBeat
from time import sleep
import psutil
from config import load_conf, ConfParseError
from config import filters as conf_filters

logger = logging.getLogger()

Expand All @@ -43,16 +30,14 @@ class Services:
Manage services execution, monitoring and configuration.
"""

def __init__(self, config_file):
def __init__(self, filters):
"""
Constructor, load configuration pointed by config_file.

:param config_file: Path to the filters configuration file.
"""
self._config_file = config_file
self._filters = {}
self._filters = deepcopy(filters)
self._lock = Lock()
self.load_conf()

def start_all(self):
"""
Expand Down Expand Up @@ -351,12 +336,11 @@ def update(self, names):
"""
logger.debug("Update: Trying to open config file")
try:
with open(self._config_file, 'r') as f:
logger.debug("Update: Loading config")
filters = json.load(f)
except Exception as e:
logger.error("Unable to load conf on update: {0}".format(e))
return [{"filter": "all", "error": "Unable to load conf on update: {0}".format(e)}]
#Reload conf, global variable 'conf_filters' will be updated
load_conf()
except ConfParseError:
logger.error("Update: wrong configuration format, unable to update")
return 1

logger.info("Update: Configuration loaded")

Expand All @@ -365,7 +349,7 @@ def update(self, names):
new = {}
for n in names:
try:
new[n] = filters[n]
new[n] = conf_filters[n]
except KeyError:
try:
self.stop_one(self._filters[n], no_lock=True)
Expand All @@ -384,57 +368,16 @@ def update(self, names):
name=n, extension=new[n]['extension']
)

new[n]['output'] = new[n]['output']
new[n]['name'] = n

if not new[n]['next_filter']:
new[n]['next_filter_unix_socket'] = 'no'
else:
new[n]['next_filter_unix_socket'] = '/var/sockets/darwin/{next_filter}.sock'.format(
next_filter=new[n]['next_filter']
)

new[n]['socket'] = '/var/sockets/darwin/{name}{extension}.sock'.format(
name=n, extension=new[n]['extension']
)

new[n]['socket_link'] = '/var/sockets/darwin/{name}.sock'.format(name=n)

new[n]['monitoring'] = '/var/sockets/darwin/{name}_mon{extension}.sock'.format(
name=n, extension=new[n]['extension']
)

if "config_file" not in new[n]:
logger.warning("Field 'config_file' not found for {}: setting default.".format(n))
new[n]['config_file'] = '/home/darwin/conf/{name}.conf'.format(name=n)

if 'cache_size' not in new[n]:
new[n]['cache_size'] = 0

logger.info('No cache size provided. Setting it to {cache_size}'.format(
cache_size=new[n]['cache_size']
))

if 'output' not in new[n]:
new[n]['output'] = 'NONE'
logger.info('No output type provided. Setting it to {output}'.format(output=new[n]['output']))

if 'nb_thread' not in new[n]:
new[n]['nb_thread'] = 5

logger.info('No number of threads provided. Setting it to {nb_thread}'.format(
nb_thread=new[n]['nb_thread']
))

if 'threshold' not in new[n]:
new[n]['threshold'] = 101

logger.info('No threshold provided. Setting it to the filter\'s default threshold')

for n, c in new.items():
c['status'] = psutil.STATUS_WAKING
cmd = self._build_cmd(c)
logger.info("Starting updated filter")
p = Popen(cmd)
try:
p.wait(timeout=1)
Expand Down Expand Up @@ -486,79 +429,6 @@ def update(self, names):

return errors

def load_conf(self):
"""
Load the configuration.
"""

with self._lock:
logger.debug("Trying to open config file")
try:
with open(self._config_file, 'r') as f:
logger.debug("Loading config")
self._filters = json.load(f)
except Exception as e:
logger.critical("Unable to load initial conf: {0}".format(e))
raise e

logger.info("Configuration loaded")

for f, c in self._filters.items():
if 'next_filter' not in c:
c['next_filter'] = ''

logger.debug('No next filter provided')

try:
c['name'] = f
c['status'] = psutil.STATUS_WAKING
c['extension'] = '.1'
c['pid_file'] = '/var/run/darwin/{filter}{extension}.pid'.format(filter=f, extension=c['extension'])

if not c['next_filter']:
c['next_filter_unix_socket'] = 'no'
else:
c['next_filter_unix_socket'] = '/var/sockets/darwin/{next_filter}.sock'.format(
next_filter=c['next_filter']
)

c['socket'] = '/var/sockets/darwin/{filter}{extension}.sock'.format(filter=f, extension=c['extension'])
c['socket_link'] = '/var/sockets/darwin/{filter}.sock'.format(filter=f)

c['monitoring'] = '/var/sockets/darwin/{filter}_mon{extension}.sock'.format(
filter=f, extension=c['extension']
)

if 'config_file' not in c:
logger.warning('Field "config_file" not found for {filter}: setting default'.format(filter=f))
c['config_file'] = '/home/vlt-sys/darwin/conf/{filter}.conf'.format(filter=f)

if 'cache_size' not in c:
c['cache_size'] = 0

logger.info('No cache size provided. Setting it to {cache_size}'.format(
cache_size=c['cache_size']
))

if 'output' not in c:
c['output'] = 'NONE'
logger.info('No output type provided. Setting it to {output}'.format(output=c['output']))

if 'nb_thread' not in c:
c['nb_thread'] = 5

logger.info('No number of threads provided. Setting it to {nb_thread}'.format(
nb_thread=c['nb_thread']
))
except KeyError as e:
logger.critical("Missing parameter: {}".format(e))
raise e

if 'threshold' not in c:
c['threshold'] = 101

logger.info('No threshold provided. Setting it to the filter\'s default threshold')

def print_conf(self):
"""
Pretty Print the configuration.
Expand Down
Loading