Trying to get logic honor if-statements to control output

asumming from your output, the check section sould look like this

[
 ['5', 'Security', 'notice(s)'], 
 ['1', 'Bugfix', 'notice(s)'], 
 ['8', 'Enhancement', 'notice(s)'], 
 ['3', 'other', 'notice(s)']
]

if this is correct, there is no real need to first check for a digit at the start of the line, you can easyly check if line[1] contains the string you are looking for, and if so yield your check state with line[0] as the value.

def check_linux_dnf(section):
    for line in section:
        if line[1] == 'Bugfix':
            yield Result(state=State.WARN, summary=line[0] + " Bugfix Updates")
        elif line[1] == "Enhancement":
            yield Result(state=State.WARN, summary=line[0] + " Enhancement Updates")
        elif line[0] == "Security":
            yield Result(state=State.CRIT, summary=line[0] + " Security Updates")
        return
    yield Result(state=State.OK, summary="No DNF Updates found.")

if you still want to check if line[0] is a digit you can do this like so:

def check_linux_dnf(section):
    for line in section:
        if line[0].isdigit:
            if line[1] == 'Bugfix':
                yield Result(state=State.WARN, summary=line[0] + " Bugfix Updates")
            elif line[1] == "Enhancement":
                yield Result(state=State.WARN, summary=line[0] + " Enhancement Updates")
            elif line[1] == "Security":
                yield Result(state=State.CRIT, summary=line[0] + " Security Updates")
            return
    yield Result(state=State.OK, summary="No DNF Updates found.")

btw. have a look at the Writing your own check plug-ins. There you will also find some basic steps on how to debug your checks.

1 Like