philippechataignon/smrt

Add ability to decode raw data results into meaningful key:value

Opened this issue · 1 comments

At the moment commands like "smrt stats" return a bunch of numbers without any idea what they mean.

(16384, 'stats', (1, 1, 5, 67622004, 0, 166630038, 0))
(16384, 'stats', (2, 1, 0, 14874531, 0, 9129785, 0))
(16384, 'stats', (3, 1, 0, 1073404, 0, 19668, 0))
(16384, 'stats', (4, 1, 6, 8108486, 0, 4382321, 0))
(16384, 'stats', (5, 1, 6, 170911760, 0, 76011246, 1))

It would be nice if there was a version/variant that attempted to decode these into a semantic response. This response in the upstream repo points to a bunch of useful data in PHP? pklaus#4

Example code:

    def interpret_result(result):
        lookup = {
            'Status': {
                0: 'Enabled',
                1: 'Disabled',
            },
            'Link Status': {
                0: 'Link Down',
                1: 'AUTO',
                2: 'MH10',
                3: 'MF10',
                4: 'MH100',
                5: '100Full',
                6: '1000Full',
            }
        }
        info = {
            'stats': ('Port', 'Status', 'Link Status', 'TxGoodPkt', 'TxBadPkt', 'RxGoodPkt', 'RxBadPkt')
        }
        result_type = result[1]
        if result_type in info:
            return {k: lookup[k].get(v, v) if k in lookup else v for k, v in zip(info[result_type], result[2])}
        return result

returns

{'Port': 1, 'Status': 'Disabled', 'Link Status': '100Full', 'TxGoodPkt': 68387282, 'TxBadPkt': 0, 'RxGoodPkt': 168683893, 'RxBadPkt': 0}
{'Port': 2, 'Status': 'Enabled', 'Link Status': 'Link Down', 'TxGoodPkt': 14874531, 'TxBadPkt': 0, 'RxGoodPkt': 9129785, 'RxBadPkt': 0}
{'Port': 3, 'Status': 'Disabled', 'Link Status': 'Link Down', 'TxGoodPkt': 1073404, 'TxBadPkt': 0, 'RxGoodPkt': 19668, 'RxBadPkt': 0}
{'Port': 4, 'Status': 'Disabled', 'Link Status': '1000Full', 'TxGoodPkt': 8168637, 'TxBadPkt': 0, 'RxGoodPkt': 4422702, 'RxBadPkt': 0}
{'Port': 5, 'Status': 'Disabled', 'Link Status': '1000Full', 'TxGoodPkt': 173008395, 'TxBadPkt': 0, 'RxGoodPkt': 76816504, 'RxBadPkt': 1}