summaryrefslogtreecommitdiff
path: root/plugins/ping.py
blob: 2f0bb42bb078f9f222f90e5090dfd27f9b940330 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os
import random
import plugins


class PluginThread(plugins.PluginThreadCommon):
    def __init__(self, config):
        defaults = {'hosts': list(), 'title': 'PING', 'timeout': 150}
        super(PluginThread, self).__init__(config, defaults)
        self.format_status('n/a')

    def format_status(self, state):
        self.status['full_text'] = self.conf['title'] + ': ' + state
        if state == 'on':
            self.status['urgent'] = False
            self.hide = True
        else:
            self.status['urgent'] = True

    def main(self):
        random.shuffle(self.conf['hosts'])
        for host in self.conf['hosts']:
            fping = 'fping -qc1t' + str(self.conf['timeout'])\
                                        + ' ' + host + ' &>/dev/null'
            response = os.system(fping)
            if response == 0:
                self.format_status('on')
                break
            self.format_status('off')