source: hwdetector/trunk/fuentes/hwdetector.install/hwdetector/modules/llxsystemtest.py @ 6420

Last change on this file since 6420 was 6420, checked in by mabarracus, 2 years ago

Fix type checks with unicode vars

File size: 2.0 KB
Line 
1#!/usr/bin/env python
2import hwdetector.Detector as Detector
3import hwdetector.utils.log as log
4
5log.debug("File "+__name__+" loaded")
6
7class LlxSystemTest(Detector):
8    _NEEDS=['LLIUREX_RELEASE','SYSTEMCTL_INFO','DPKG_INFO','APACHE_INFO','EPOPTES_INFO','DNSMASQ_INFO','SQUID_INFO','PROCESS_INFO','VARLOG_INFO','HELPER_SEARCH_PROCESS']
9    _PROVIDES=['LLXSYSTEM_TEST']
10
11    def make_result(self,*args,**kwargs):
12        ret=''
13        if not ('result' in kwargs and 'msg' in kwargs):
14            return
15        if isinstance(kwargs['result'],list):
16            result=kwargs['result']
17        else:
18            result=[str(kwargs['result'])]
19
20        for x in result:
21            ret+='{}> {}: {}\n'.format(self.__class__.__name__,x,kwargs['msg'])
22        return ret
23
24    def run(self,*args,**kwargs):
25
26        release=str(kwargs['LLIUREX_RELEASE'])
27        status=True
28        msg=[]
29
30        systemctl=kwargs['SYSTEMCTL_INFO']
31        needed_services={}
32        needed_services_common=[{'n4d':['n4d-server']}]
33
34        map(needed_services.update,needed_services_common)
35
36        if 'server' in release.lower():
37            map(needed_services.update,[{'apache2':['apache2']},{'epoptes':['epoptes','socat']},{'dnsmasq':['dnsmasq']},{'slapd':['slapd']}])
38
39        res_ok=[]
40        res_nok=[]
41        ps=kwargs['PROCESS_INFO']
42        for need in needed_services:
43            if need in systemctl['BYUNIT'] and systemctl['BYUNIT'][need][0]['SUB'] == 'running':
44                res_ok.append('Service {}'.format(need))
45                plist=self.search_process(needed_services[need])
46                for x in plist:
47                    res_ok.append('{} Process matching \'{}\''.format(len(plist[x]),x))
48            else:
49                res_nok.append('Service {}'.format(need))
50                status=False
51
52
53        msg.append(self.make_result(result=res_ok,msg='Ok! Running'))
54        msg.append(self.make_result(result=res_nok,msg='Nok! Down'))
55
56        msg=''.join(msg)
57        output={'LLXSYSTEM_TEST':{'status':status,'msg':msg}}
58        return output
Note: See TracBrowser for help on using the repository browser.