Skip to content

Azure's vm_agent() function has poorly written if-else blocks resulting in KeyError #64

@oguzhan-prplbx

Description

@oguzhan-prplbx

When I run the cs-suite for Azure I get this following error:

File "/home/ubuntu/cs-suite/modules/azureaudit.py", line 1181, in vm_agent
    log_data["data"] = log_data.pop("value")
KeyError: 'value'

I checked the code, and I found this:

azure_audit.py:1170
        if check == '':
            j_res['type'] = 'WARNING'
            j_res['value'] = 'The VM %s does not have virtual agent enabled' %(name)
        else:
            list = check.split()
            if list[1] == "Succeeded" and list[0] != "":
                j_res['type'] = 'PASS'
                j_res['value'] = 'The VM %s does have virtual agent enabled' % (name)
        data.append(j_res)
        log_data = dict()
        log_data = j_res
        log_data["data"] = log_data.pop("value")

This is problematic because if condition inside else has no else condition to default to.

I had to add the following else block to bypass this problem.

azure_audit.py:1170
        if check == '':
            j_res['type'] = 'WARNING'
            j_res['value'] = 'The VM %s does not have virtual agent enabled' %(name)
        else:
            list = check.split()
            if list[1] == "Succeeded" and list[0] != "":
                j_res['type'] = 'PASS'
                j_res['value'] = 'The VM %s does have virtual agent enabled' % (name)
            # change made starts here:
            else:
                j_res['type'] = 'WARNING'
                j_res['value'] = 'The VM %s does not have virtual agent enabled' %(name)
            # change made ends here
        data.append(j_res)
        log_data = dict()
        log_data = j_res
        log_data["data"] = log_data.pop("value")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions