From aa24b19b312bd93ccd7fe07c14be2675cf1d9432 Mon Sep 17 00:00:00 2001 From: Jan Mach <jan.mach@cesnet.cz> Date: Fri, 27 Apr 2018 21:08:30 +0200 Subject: [PATCH] Made ordnung in cronjob files in configuration directory. * All cronjob files were moved into separate subdirectory within main Mentat`s configuration directory. * Naming convention for cronjob files was changed from 'cron_module' to 'module.cron'. * Made appropriate changes in other relevant modules. (Redmine issue: #3387) --- .../fetch-geoipdb.sh.cron} | 9 ++++-- conf/cron/fetch-negistry.sh.cron | 14 +++++++++ .../mentat-backup.py.cron} | 9 ++++-- .../mentat-cleanup.py.cron} | 9 ++++-- conf/cron/mentat-precache.py.cron | 14 +++++++++ conf/cron/mentat-reporter.py.cron | 14 +++++++++ conf/cron/mentat-statistician.py.cron | 14 +++++++++ conf/cron/mentat-watchdog.py.cron | 15 +++++++++ conf/cron_fetch-negistry-sh | 11 ------- conf/cron_mentat-precache-py | 11 ------- conf/cron_mentat-reporter-py | 11 ------- conf/cron_mentat-statistician-py | 11 ------- conf/cron_mentat-watchdog-py | 12 ------- conf/mentat-controller.py.conf | 10 +++--- lib/mentat/system.py | 27 ++++++++-------- lib/mentat/test_system.py | 31 +++++++++++++------ 16 files changed, 129 insertions(+), 93 deletions(-) rename conf/{cron_fetch-geoipdb-sh => cron/fetch-geoipdb.sh.cron} (50%) create mode 100644 conf/cron/fetch-negistry.sh.cron rename conf/{cron_mentat-backup-py => cron/mentat-backup.py.cron} (54%) rename conf/{cron_mentat-cleanup-py => cron/mentat-cleanup.py.cron} (53%) create mode 100644 conf/cron/mentat-precache.py.cron create mode 100644 conf/cron/mentat-reporter.py.cron create mode 100644 conf/cron/mentat-statistician.py.cron create mode 100644 conf/cron/mentat-watchdog.py.cron delete mode 100644 conf/cron_fetch-negistry-sh delete mode 100644 conf/cron_mentat-precache-py delete mode 100644 conf/cron_mentat-reporter-py delete mode 100644 conf/cron_mentat-statistician-py delete mode 100644 conf/cron_mentat-watchdog-py diff --git a/conf/cron_fetch-geoipdb-sh b/conf/cron/fetch-geoipdb.sh.cron similarity index 50% rename from conf/cron_fetch-geoipdb-sh rename to conf/cron/fetch-geoipdb.sh.cron index 80421f0e2..bd34133f0 100644 --- a/conf/cron_fetch-geoipdb-sh +++ b/conf/cron/fetch-geoipdb.sh.cron @@ -1,7 +1,10 @@ # -# Name: cron_fetch-geoipdb-sh -# Description: Fetch the latest version of Maxmind GeoIP databases -# Installation: ln -s /etc/mentat/cron_fetch-geoipdb-sh /etc/cron.d/fetch-geoipdb +# NAME: +# fetch-geoipdb.sh.cron +# DESCRIPTION: +# Fetch the latest version of Maxmind GeoIP databases +# MANUAL INSTALLATION: +# ln -s /etc/mentat/cron/fetch-geoipdb.sh.cron /etc/cron.d/fetch-geoipdb.sh.cron # # Copyright (C) since 2011 CESNET, z.s.p.o # Use of this source is governed by the MIT license, see LICENSE file. diff --git a/conf/cron/fetch-negistry.sh.cron b/conf/cron/fetch-negistry.sh.cron new file mode 100644 index 000000000..34235c8fc --- /dev/null +++ b/conf/cron/fetch-negistry.sh.cron @@ -0,0 +1,14 @@ +# +# NAME: +# fetch-negistry.sh.cron +# DESCRIPTION: +# Fetch the latest version of CESNET`s Negistry whois database. +# MANUAL INSTALLATION: +# ln -s /etc/mentat/cron/fetch-negistry.sh.cron /etc/cron.d/fetch-negistry.sh.cron +# +# Copyright (C) since 2011 CESNET, z.s.p.o +# Use of this source is governed by the MIT license, see LICENSE file. +# + +# Run every day at 1am +0 1 * * * root /etc/mentat/scripts/fetch-negistry.sh --quiet diff --git a/conf/cron_mentat-backup-py b/conf/cron/mentat-backup.py.cron similarity index 54% rename from conf/cron_mentat-backup-py rename to conf/cron/mentat-backup.py.cron index d867b02c1..6a716c68d 100644 --- a/conf/cron_mentat-backup-py +++ b/conf/cron/mentat-backup.py.cron @@ -1,7 +1,10 @@ # -# Name: cron_mentat-backup-py -# Description: Perform backup of Mentat system -# Installation: ln -s /etc/mentat/cron_mentat-backup-py /etc/cron.d/mentat-backup-py +# NAME: +# mentat-backup.py.cron +# DESCRIPTION: +# Perform backup of Mentat system +# MANUAL INSTALLATION: +# ln -s /etc/mentat/cron/mentat-backup.py.cron /etc/cron.d/mentat-backup.py.cron # # Copyright (C) since 2011 CESNET, z.s.p.o # Use of this source is governed by the MIT license, see LICENSE file. diff --git a/conf/cron_mentat-cleanup-py b/conf/cron/mentat-cleanup.py.cron similarity index 53% rename from conf/cron_mentat-cleanup-py rename to conf/cron/mentat-cleanup.py.cron index f83afda31..fbba4074f 100644 --- a/conf/cron_mentat-cleanup-py +++ b/conf/cron/mentat-cleanup.py.cron @@ -1,7 +1,10 @@ # -# Name: cron_mentat-cleanup-py -# Description: Perform cleanup of Mentat system -# Installation: ln -s /etc/mentat/cron_mentat-cleanup-py /etc/cron.d/mentat-cleanup-py +# NAME: +# mentat-cleanup.py.cron +# DESCRIPTION: +# Perform cleanup of Mentat system +# MANUAL INSTALLATION: +# ln -s /etc/mentat/cron/mentat-cleanup.py.cron /etc/cron.d/mentat-cleanup.py.cron # # Copyright (C) since 2011 CESNET, z.s.p.o # Use of this source is governed by the MIT license, see LICENSE file. diff --git a/conf/cron/mentat-precache.py.cron b/conf/cron/mentat-precache.py.cron new file mode 100644 index 000000000..800aa7325 --- /dev/null +++ b/conf/cron/mentat-precache.py.cron @@ -0,0 +1,14 @@ +# +# NAME: +# mentat-precache.py.cron +# DESCRIPTION: +# Perform pre-caching of various data for Mentat system +# MANUAL INSTALLATION: +# ln -s /etc/mentat/cron/mentat-precache.py.cron /etc/cron.d/mentat-precache.py.cron +# +# Copyright (C) since 2011 CESNET, z.s.p.o +# Use of this source is governed by the MIT license, see LICENSE file. +# + +# Run once in every 10 minutes +*/10 * * * * mentat /usr/bin/python3 /usr/local/bin/mentat-precache.py --regular diff --git a/conf/cron/mentat-reporter.py.cron b/conf/cron/mentat-reporter.py.cron new file mode 100644 index 000000000..58a8f6bc9 --- /dev/null +++ b/conf/cron/mentat-reporter.py.cron @@ -0,0 +1,14 @@ +# +# NAME: +# mentat-reporter.py.cron +# DESCRIPTION: +# Run Mentat's event reporting postprocessing component +# MANUAL INSTALLATION: +# ln -s /etc/mentat/cron/mentat-reporter.py.cron /etc/cron.d/mentat-reporter.py.cron +# +# Copyright (C) since 2011 CESNET, z.s.p.o +# Use of this source is governed by the MIT license, see LICENSE file. +# + +# Run once in every ten minutes +*/10 * * * * mentat /usr/bin/python3 /usr/local/bin/mentat-reporter.py --regular diff --git a/conf/cron/mentat-statistician.py.cron b/conf/cron/mentat-statistician.py.cron new file mode 100644 index 000000000..5b998a234 --- /dev/null +++ b/conf/cron/mentat-statistician.py.cron @@ -0,0 +1,14 @@ +# +# NAME: +# mentat-statistician.py.cron +# DESCRIPTION: +# Run Mentat's statistical postprocessing component +# MANUAL INSTALLATION: +# ln -s /etc/mentat/cron/mentat-statistician.py.cron /etc/cron.d/mentat-statistician.py.cron +# +# Copyright (C) since 2011 CESNET, z.s.p.o +# Use of this source is governed by the MIT license, see LICENSE file. +# + +# Run once in every five minutes +*/5 * * * * mentat /usr/bin/python3 /usr/local/bin/mentat-statistician.py --regular diff --git a/conf/cron/mentat-watchdog.py.cron b/conf/cron/mentat-watchdog.py.cron new file mode 100644 index 000000000..50789ef37 --- /dev/null +++ b/conf/cron/mentat-watchdog.py.cron @@ -0,0 +1,15 @@ +# +# NAME: +# mentat-watchdog.py.cron +# DESCRIPTION: +# Check database of Mentat system for various anomalies +# MANUAL INSTALLATION: +# ln -s /etc/mentat/cron/mentat-watchdog.py.cron /etc/cron.d/mentat-watchdog.py.cron +# +# Copyright (C) since 2011 CESNET, z.s.p.o +# Use of this source is governed by the MIT license, see LICENSE file. +# + +# Run once in every hour +55 * * * * root /usr/bin/python3 /usr/local/bin/mentat-dbmngr.py --command=watchdog --regular + diff --git a/conf/cron_fetch-negistry-sh b/conf/cron_fetch-negistry-sh deleted file mode 100644 index 59d8981a5..000000000 --- a/conf/cron_fetch-negistry-sh +++ /dev/null @@ -1,11 +0,0 @@ -# -# Name: cron_fetch-negistry-sh -# Description: Fetch the latest version of CESNET`s Negistry whois database. -# Installation: ln -s /etc/mentat/cron_fetch-negistry-sh /etc/cron.d/fetch-negistry -# -# Copyright (C) since 2011 CESNET, z.s.p.o -# Use of this source is governed by the MIT license, see LICENSE file. -# - -# Run every day at 1am -0 1 * * * root /etc/mentat/scripts/fetch-negistry.sh --quiet diff --git a/conf/cron_mentat-precache-py b/conf/cron_mentat-precache-py deleted file mode 100644 index daf632ab7..000000000 --- a/conf/cron_mentat-precache-py +++ /dev/null @@ -1,11 +0,0 @@ -# -# Name: cron_mentat-precache-py -# Description: Perform pre-caching of various data for Mentat system -# Installation: ln -s /etc/mentat/cron_mentat-precache-py /etc/cron.d/mentat-precache-py -# -# Copyright (C) since 2011 CESNET, z.s.p.o -# Use of this source is governed by the MIT license, see LICENSE file. -# - -# Run every 10 minutes -*/10 * * * * mentat /usr/bin/python3 /usr/local/bin/mentat-precache.py --regular diff --git a/conf/cron_mentat-reporter-py b/conf/cron_mentat-reporter-py deleted file mode 100644 index 29318f7c1..000000000 --- a/conf/cron_mentat-reporter-py +++ /dev/null @@ -1,11 +0,0 @@ -# -# Name: cron_mentat-reporter-py -# Description: Run Mentat's reporting postprocessing component -# Installation: ln -s /etc/mentat/cron_mentat-reporter-py /etc/cron.d/mentat-reporter-py -# -# Copyright (C) since 2011 CESNET, z.s.p.o -# Use of this source is governed by the MIT license, see LICENSE file. -# - -# Run every ten minutes -*/10 * * * * mentat /usr/bin/python3 /usr/local/bin/mentat-reporter.py --regular diff --git a/conf/cron_mentat-statistician-py b/conf/cron_mentat-statistician-py deleted file mode 100644 index 66c8a3626..000000000 --- a/conf/cron_mentat-statistician-py +++ /dev/null @@ -1,11 +0,0 @@ -# -# Name: cron_mentat-statistician-py -# Description: Run Mentat's statistical postprocessing component -# Installation: ln -s /etc/mentat/cron_mentat-statistician-py /etc/cron.d/mentat-statistician-py -# -# Copyright (C) since 2011 CESNET, z.s.p.o -# Use of this source is governed by the MIT license, see LICENSE file. -# - -# Run every five minutes -*/5 * * * * mentat /usr/bin/python3 /usr/local/bin/mentat-statistician.py --regular diff --git a/conf/cron_mentat-watchdog-py b/conf/cron_mentat-watchdog-py deleted file mode 100644 index 02bc65033..000000000 --- a/conf/cron_mentat-watchdog-py +++ /dev/null @@ -1,12 +0,0 @@ -# -# Name: cron_mentat-watchdog-py -# Description: Check database of Mentat system for anomalies -# Installation: ln -s /etc/mentat/cron_mentat-watchdog-py /etc/cron.d/mentat-watchdog-py -# -# Copyright (C) since 2011 CESNET, z.s.p.o -# Use of this source is governed by the MIT license, see LICENSE file. -# - -# Run every hour -55 * * * * root /usr/bin/python3 /usr/local/bin/mentat-dbmngr.py --command=watchdog --regular - diff --git a/conf/mentat-controller.py.conf b/conf/mentat-controller.py.conf index abf87ddf2..04658d27d 100644 --- a/conf/mentat-controller.py.conf +++ b/conf/mentat-controller.py.conf @@ -90,10 +90,10 @@ # TODO: Following feature is not yet fully iplemented # "cronjobs": [ - { "name": "fetch-geoipdb-sh" }, - { "name": "mentat-cleanup-py" }, - { "name": "mentat-precache-py" }, - { "name": "mentat-statistician-py" }, - { "name": "mentat-watchdog-py" } + { "name": "fetch-geoipdb.sh" }, + { "name": "mentat-cleanup.py" }, + { "name": "mentat-precache.py" }, + { "name": "mentat-statistician.py" }, + { "name": "mentat-watchdog.py" } ] } diff --git a/lib/mentat/system.py b/lib/mentat/system.py index 47c375746..d4fd97834 100644 --- a/lib/mentat/system.py +++ b/lib/mentat/system.py @@ -24,7 +24,6 @@ import collections import subprocess import pyzenkit.jsonconf -import mentat # @@ -88,7 +87,7 @@ REGEXP_MENTAT_PS = re.compile(r'\s*(\d+)\s+([^\s]+)\s+([^\s]*(?:python3?))\s """Regular expression for selecting Mentat related processes.""" REGEXP_MENTAT_PIDF = re.compile(r'(.+?)(?:\.(\d+))?\.pid$') """Regular expression for selecting Mentat related PID files.""" -REGEXP_MENTAT_CRONF = re.compile(r'cron_(.+)$') +REGEXP_MENTAT_CRONF = re.compile(r'(.+)\.cron$') """Regular expression for selecting Mentat related log files.""" REGEXP_MENTAT_LOGF = re.compile(r'(.+)\.log$') """Regular expression for selecting Mentat related log files.""" @@ -374,11 +373,11 @@ def analyze_cron_file(cron_file, cron_file_path, cron_links): { 'atime': datetime.datetime(2018, 1, 21, 9, 13, 48, 34648), - 'file': 'cron_mentat-statistician-py', + 'file': 'mentat-statistician.py.cron', 'link': None, 'mtime': datetime.datetime(2017, 7, 19, 10, 25, 30), - 'name': 'mentat-statistician-py', - 'path': '/etc/mentat/cron_mentat-statistician-py', + 'name': 'mentat-statistician.py', + 'path': '/etc/mentat/cron/mentat-statistician.py.cron', 'size': 429 } @@ -413,19 +412,19 @@ def analyze_cron_files(cfg_dir_path, cron_dir_path): Example of returned structure:: { - 'mentat-precache-py': {'atime': datetime.datetime(2018, 1, 21, 9, 13, 45), - 'file': 'cron_mentat-precache-py', + 'mentat-precache.py': {'atime': datetime.datetime(2018, 1, 21, 9, 13, 45), + 'file': 'mentat-precache.py.cron', 'link': None, 'mtime': datetime.datetime(2017, 9, 1, 11, 10, 17), - 'name': 'mentat-precache-py', - 'path': '/etc/mentat/cron_mentat-precache-py', + 'name': 'mentat-precache.py', + 'path': '/etc/mentat/cron/mentat-precache.py.cron', 'size': 417}, - 'mentat-statistician-py': {'atime': datetime.datetime(2018, 1, 21, 9, 13, 48, 34648), - 'file': 'cron_mentat-statistician-py', + 'mentat-statistician.py': {'atime': datetime.datetime(2018, 1, 21, 9, 13, 48, 34648), + 'file': 'mentat-statistician.py.cron', 'link': None, 'mtime': datetime.datetime(2017, 7, 19, 10, 25, 30), - 'name': 'mentat-statistician-py', - 'path': '/etc/mentat/cron_mentat-statistician-py', + 'name': 'mentat-statistician.py.cron', + 'path': '/etc/mentat/cron/mentat-statistician.py.cron', 'size': 429} } @@ -803,7 +802,7 @@ def system_status(modules, cronjobs, cfg_dir_path, cron_dir_path, log_dir_path, status['processes'] = analyze_process_list_ps() status['pid_files'] = analyze_pid_files(run_dir_path) status['log_files'] = analyze_log_files(log_dir_path) - status['cron_files'] = analyze_cron_files(cfg_dir_path, cron_dir_path) + status['cron_files'] = analyze_cron_files(os.path.join(cfg_dir_path, 'cron'), cron_dir_path) status['resultm'] = None status['resultc'] = None status['result'] = None diff --git a/lib/mentat/test_system.py b/lib/mentat/test_system.py index 5de974004..1c02f228b 100644 --- a/lib/mentat/test_system.py +++ b/lib/mentat/test_system.py @@ -144,7 +144,7 @@ class TestMentatStorage(unittest.TestCase): if self.verbose: print("Single PID file:") - #pprint(mentat.system.analyze_pid_file('mentat-storage.py.pid', '/var/mentat/run/mentat-storage.py.pid')) + pprint(mentat.system.analyze_pid_file('mentat-storage.py.pid', '/var/mentat/run/mentat-storage.py.pid')) def test_04_analyze_pid_files(self): """ @@ -154,7 +154,7 @@ class TestMentatStorage(unittest.TestCase): if self.verbose: print("All PID files:") - #pprint(mentat.system.analyze_pid_files('/var/mentat/run')) + pprint(mentat.system.analyze_pid_files('/var/mentat/run')) def test_05_analyze_cron_file(self): """ @@ -164,7 +164,7 @@ class TestMentatStorage(unittest.TestCase): if self.verbose: print("Single cron file:") - #pprint(mentat.system.analyze_cron_file('cron_mentat-statistician-py', '/etc/mentat/cron_mentat-statistician-py', {})) + pprint(mentat.system.analyze_cron_file('mentat-statistician.py.cron', '/etc/mentat/cron/mentat-statistician.py.cron', {})) def test_06_analyze_cron_files(self): """ @@ -174,7 +174,7 @@ class TestMentatStorage(unittest.TestCase): if self.verbose: print("All cron files:") - #pprint(mentat.system.analyze_cron_files('/etc/mentat', '/etc/cron.d')) + pprint(mentat.system.analyze_cron_files('/etc/mentat/cron', '/etc/cron.d')) def test_07_analyze_log_file(self): """ @@ -184,7 +184,7 @@ class TestMentatStorage(unittest.TestCase): if self.verbose: print("Single log file:") - #pprint(mentat.system.analyze_log_file('mentat-storage.py.log', '/var/mentat/log/mentat-storage.py.log')) + pprint(mentat.system.analyze_log_file('mentat-storage.py.log', '/var/mentat/log/mentat-storage.py.log')) def test_08_analyze_log_files(self): """ @@ -194,7 +194,7 @@ class TestMentatStorage(unittest.TestCase): if self.verbose: print("All log files:") - #pprint(mentat.system.analyze_log_files('/var/mentat/log')) + pprint(mentat.system.analyze_log_files('/var/mentat/log')) def test_09_analyze_runlog_file(self): """ @@ -220,7 +220,7 @@ class TestMentatStorage(unittest.TestCase): """ Perform the basic Mentat system tests. """ - self.maxDiff = None + self.maxDiff = None # pylint: disable=locally-disabled,invalid-name modules = mentat.system.make_module_list([ { "exec": "mentat-storage.py", "args": [] }, @@ -235,8 +235,21 @@ class TestMentatStorage(unittest.TestCase): { "name": "mentat-watchdog-py" } ]) - print("System status:") - #pprint(mentat.system.system_status(modules, cronjobs, '/etc/mentat', '/etc/cron.d', '/var/mentat/log', '/var/mentat/run')) + if self.verbose: + print("System status:") + pprint(mentat.system.system_status(modules, cronjobs, '/etc/mentat', '/etc/cron.d', '/var/mentat/log', '/var/mentat/run')) + + #self.assertTrue( + # mentat.system.system_status( + # modules, + # cronjobs, + # '/etc/mentat', + # '/etc/cron.d', + # '/var/mentat/log', + # '/var/mentat/run' + # ) + #) + #------------------------------------------------------------------------------- -- GitLab