Beispiel #1
0
    def _get_storage_info(self):
        data = get_cmd_data(['df', '-T'], as_lines=True)

        result = []

        # skip first line with heading
        for line in data[1:]:
            stinfo = {}

            # Expect 7 fields separated by multiple spaces.
            # /dev/sda1      ext4      28704676   5411692  21811820  20% /
            #m = re.match(
            #    r'([^ ]*)\s+([^ ]*)\s+([^ ]*)\s+([^ ]*)\s+([^ ]*)\s+([^ ]*)%\s+([^ ]*)',
            #    line)

            m = line.split()

            if m:
                stinfo = {
                    'device': m[0],
                    'type': m[1],
                    'size': int(m[2]),
                    'used': int(m[3]),
                    'free': int(m[4]),
                    'used_pct': float(m[3]) / float(m[2]) * 100,
                    'mount_point': m[6],
                }

                result.append(stinfo)

        return result
Beispiel #2
0
Datei: net.py Projekt: motlib/mon
    def get_dev_info(self, dev):
        '''Get network device info.
    
        :param dev: Network device name, e.g. eth0.
        :return: Dict with device info.'''

        devinfo = {'device': dev}

        # Example:
        # 2: ens160    inet 10.180.2.190/24 brd 10.180.2.255 scope global ens160 ...
        data = get_cmd_data(['ip', '-o', '-4', 'address', 'show', dev],
                            firstline=True)
        data = data.strip()

        m = re.search(r'inet ([.0-9]+)\/([0-9]+)', data)

        if m:
            devinfo['ipaddress'] = m.group(1)
            devinfo['netsize'] = int(m.group(2))

        # Example:
        # wlp3s0    inet6 fe80::6267:20ff:fe3c:14e8/64 scope link ...
        data = get_cmd_data(['ip', '-o', '-6', 'address', 'show', dev],
                            firstline=True)
        data = data.strip()

        m = re.search(r'inet6 ([0-9a-f:]+)\/([0-9]+)', data)

        if m:
            devinfo['ipv6address'] = m.group(1)
            devinfo['ipv6prefix'] = int(m.group(2))

        devinfo['hwaddress'] = get_file_data(
            "/sys/class/net/{dev}/address".format(dev=dev),
            firstline=True).strip()

        devinfo.update(self._get_dev_dataflow(dev))

        return devinfo
Beispiel #3
0
    def _get_station_info(self):
        # Example output:
        # 10:41:7f:da:d0:85
        # flags=[AUTH][ASSOC][AUTHORIZED][SHORT_PREAMBLE][WMM]
        # aid=2
        # capability=0x431
        # listen_interval=20
        # supported_rates=82 84 8b 96 24 30 48 6c 0c 12 18 60
        # timeout_next=NULLFUNC POLL
        # dot11RSNAStatsSTAAddress=10:41:7f:da:d0:85
        # dot11RSNAStatsVersion=1
        # dot11RSNAStatsSelectedPairwiseCipher=00-0f-ac-4
        # dot11RSNAStatsTKIPLocalMICFailures=0
        # dot11RSNAStatsTKIPRemoteMICFailures=0
        # hostapdWPAPTKState=11
        # hostapdWPAPTKGroupState=0
        # rx_packets=231
        # tx_packets=160
        # rx_bytes=29119
        # tx_bytes=118030
        # connected_time=5

        lines = get_cmd_data(['hostapd_cli', 'all_sta'], as_lines=True)

        addr = None
        sdata = None
        all_data = []
        for line in lines:
            m = self._sta_pattern_c.match(line)
            if m:
                sdata = {'address': m.group(0)}
                all_data.append(sdata)

            m = self._data_pattern_c.match(line)
            if sdata and m:
                sdata[m.group(1)] = m.group(2)

        # fix data type of some integer values
        int_keys = ('rx_packets', 'tx_packets', 'rx_bytes', 'tx_bytes',
                    'connected_time')

        for sta in all_data:
            try:
                for key in int_keys:
                    sta[key] = int(sta[key])
            except:
                pass

        return all_data
Beispiel #4
0
 def check(self):
     cmd = [
         # main dig command
         'dig',
         '+short',
         'chaos',
         'txt',
         '+tries=1',
         '+timeout=2',
         DNSMASQ_HOST,
         # dnsmasq statistics to query
         'cachesize.bind',
     ]
     data = get_cmd_data(cmd, as_lines=True)
     if len(data) != 1:
         raise Exception(
             "Dnsmasq does not provide statistics in the expected format. Output was: "
             + str(data))
Beispiel #5
0
Datei: cpu.py Projekt: motlib/mon
    def _get_lscpuinfo(self):
        output = get_cmd_data(['lscpu'], as_lines=True)

        # currently not active, as json support in lscpu is quite new
        #output = get_cmd_data(['lscpu', '--json'])
        #data = json.loads(output)

        # Convert json structure. in json, the field names have a trailing
        # ':'. This is removed here, too.
        #data = {i['field'][:-1]: i['data'] for i in data['lscpu']}

        data = {}
        for line in output:
            m = re.match(r'^([^:]+):\s+(.*)$', line)

            if m:
                data[m.group(1)] = m.group(2)

        return data
Beispiel #6
0
    def _get_values(self):
        cmd = [
            # main dig command
            'dig',
            '+short',
            'chaos',
            'txt',
            '+tries=1',
            '+timeout=2',
            DNSMASQ_HOST,
            # dnsmasq statistics to query
            'cachesize.bind',
            'insertions.bind',
            'evictions.bind',
            'misses.bind',
            'hits.bind',
            'auth.bind',
            # servers info does not yet get evaluated
            #'servers.bind'
        ]
        lines = get_cmd_data(cmd, as_lines=True)

        data = {
            'cachesize': int(lines[0].replace('"', '')),
            'insertions': int(lines[1].replace('"', '')),
            'evictions': int(lines[2].replace('"', '')),
            'misses': int(lines[3].replace('"', '')),
            'hits': int(lines[4].replace('"', '')),
            'auth': int(lines[5].replace('"', '')),
        }

        if data['hits'] + data['misses'] != 0:
            data['hitrate_pct'] = float(
                data['hits']) / (data['hits'] + data['misses']) * 100
        else:
            data['hitrate_pct'] = 0.0

        return data
Beispiel #7
0
 def check(self):
     # let's try to run hostapp_cli
     get_cmd_data(['hostapd_cli', 'all_sta'], as_lines=True)
Beispiel #8
0
Datei: net.py Projekt: motlib/mon
    def get_devices(self):
        cmd = ['ls', '-1', '/sys/class/net']

        devices = get_cmd_data(cmd, as_lines=True)

        return [d.strip() for d in devices if d.strip() != '']
Beispiel #9
0
 def _get_kernel(self):
     return get_cmd_data(
         cmd=['uname', '-r'],
         firstline=True,
         as_lines=False)
Beispiel #10
0
Datei: cpu.py Projekt: motlib/mon
 def check(self):
     get_cmd_data(['lscpu'])