diff options
author | Christian Franke <nobody@nowhere.ws> | 2012-01-11 09:49:53 +0100 |
---|---|---|
committer | Christian Franke <nobody@nowhere.ws> | 2012-01-11 09:49:53 +0100 |
commit | 9a94e0095a51981cc668ac0269667a307c45923c (patch) | |
tree | 76a92a43a24b0a7b376912e310353677c746c074 /sublab_project/sublab_monitor/tasks.py | |
parent | fff2edd3a10a7f9585d4a734740420256246b9b5 (diff) |
add network_monitor
Diffstat (limited to 'sublab_project/sublab_monitor/tasks.py')
-rw-r--r-- | sublab_project/sublab_monitor/tasks.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/sublab_project/sublab_monitor/tasks.py b/sublab_project/sublab_monitor/tasks.py new file mode 100644 index 0000000..33dcad6 --- /dev/null +++ b/sublab_project/sublab_monitor/tasks.py @@ -0,0 +1,46 @@ +"""Celery tasks. +""" +from datetime import timedelta +from celery.task import PeriodicTask +import subprocess + +import sublab_monitor + +class NetworkStatus(PeriodicTask): + """Periodic task for getting sublab network status + """ + hosts = { + 'taifun': '172.22.83.5', + 'trieste': '172.22.80.4', + 'nautilus': '172.22.80.7', + } + run_every = timedelta(minutes=4) + ignore_result = True + + def __init__(self, *args, **kwargs): + PeriodicTask.__init__(self, *args, **kwargs) + + + @staticmethod + def host_alive(host): + rc = subprocess.call(['ping', '-c', '2', '-W', '1', host]) + + if rc == 0: + return True + else: + return False + + def run(self, **kwargs): + """Ping all the hosts. + """ + self.logger = self.get_logger(**kwargs) + + results = {} + for host, target in self.hosts.items(): + results[host] = self.host_alive(target) + + storage = sublab_monitor.Storage('network_status') + for host, status in results.items(): + storage.set(host, status) + + return repr(results) |