def checkwireless(): profiler = LocalProfilerFactory.getProfiler() data = profiler.profile(set(['rete'])) for device in data.findall('rete/NetworkDevice'): logger.debug(ET.tostring(device)) status = device.find('Status').text if (status == 'Enabled'): type = device.find('Type').text if (type == 'Wireless'): raise sysmonitorexception.WARNWLAN return True
def getResProperty(tag, res): data = ET.ElementTree() try: profiler = LocalProfilerFactory.getProfiler() data = profiler.profile(set([res])) except Exception as e: logger.error('Non sono riuscito a trovare lo stato del computer con profiler: %s.' % e) raise sysmonitorexception.FAILPROF except RisorsaException as e: logger.error ("Problema nel tentativo di istanziare la risorsa: %s" % e) raise sysmonitorexception.FAILPROF except LocalProfilerException as e: logger.error ("Problema nel tentativo di istanziare il profiler: %s" % e) raise sysmonitorexception.FAILPROF wtf = res + '/' + tag return data.findall(wtf)
def main(): result=ET.ElementTree() try: profiler=LocalProfilerFactory.getProfiler() result=profiler.profile() print mytostring(result) # alldevtype=result.findall('rete/NetworkDevice/Type') # for elem in alldevtype: # print elem.text print "Finito" except NotImplementedError as e: print e except KeyError: print "sistema operativo non supportato" except LocalProfilerException as e: print ("Problema nel tentativo di istanziare il profiler: %s" % e)
def getstatus(res): logger.debug('Recupero stato della risorsa %s' % res) data = ET.ElementTree() try: profiler = LocalProfilerFactory.getProfiler() data = profiler.profile(set([res])) except FactoryException as e: logger.error ("Problema nel tentativo di istanziare la classe: %s" % e) raise sysmonitorexception.FAILPROF except RisorsaException as e: logger.error ("Problema nel tentativo di istanziare la risorsa %s: %s" % (str(res), e)) raise sysmonitorexception.FAILPROF except LocalProfilerException as e: logger.error ("Problema nel tentativo di istanziare il profiler: %s" % e) raise sysmonitorexception.FAILPROF except Exception as e: logger.error('Non sono riuscito a trovare lo stato del computer con SystemProfiler: %s.' % e) raise sysmonitorexception.FAILPROF return _getvalues(data, tag_results, res)
def getMac(): ''' restituisce indirizzo MAC del computer ''' tag = tag_activeNic.split('.'); res = tag[0] nestedtag = tag[1].split('/') tagdev = nestedtag[0] tagprop = nestedtag[1] tag = tag_mac.split('.'); nestedtag = tag[1].split('/') tagmac = nestedtag[1] data = ET.ElementTree() try: profiler = LocalProfilerFactory.getProfiler() data = profiler.profile(set([res])) except Exception as e: logger.error('Non sono riuscito a trovare lo stato del computer con profiler: %s.' % e) raise sysmonitorexception.FAILPROF except RisorsaException as e: logger.error ("Problema nel tentativo di istanziare la risorsa: %s" % e) raise sysmonitorexception.FAILPROF except LocalProfilerException as e: logger.error ("Problema nel tentativo di istanziare il profiler: %s" % e) raise sysmonitorexception.FAILPROF tree = ET.ElementTree(data) whattolook = res + '/' + tagdev listdev = data.findall(whattolook) for dev in listdev: tree._setroot(dev) devxml = tree.getroot() val = devxml.find(tagprop) if val.text == 'True': macelem = devxml.find(tagmac) return macelem.text return None