I cannot help you on the programming part - others might though - but if you only want to get the job done, this plugin from our exchange handles YUM/DNF based systems.
If this is merely a training exercise, I am sure someone can give you pointers.
if line[0].isdigit(): # this checks for a number
if line[0].find('Bugfix'): # if it is a number it can not contain a string
.....
if ("Enhancement" in line[0] != True): # can also not contain a string
.....
if "Security" in line[0]: # and again can not contain a string
....
I only see the digit back ā¦ not the entire line - which i would expect.
It is as if the content of line[0] is replaced with the outcome of the evaluation.
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.
@thl-cmk In reply to your postā¦ for a part you are correct as to the input. ( the client bash script was included in the original post)
However due to the nature of updates i cannot tell in advance if a category is present in the output.
So in this the status would need to reflect OK when there are no numbers present in the output ( the output of the client-script will just read "āNo updates foundā
So my way of handling this is to report (return) state.OK immediately, not evaluating further logic.
IF however the evaluation does return true on having a number, then further evaluation is needed as to how many, and what type of update is available.
So in your example i cannot tell if line contains either āBugfix, Enhancement, Securityā or even how many lines my output has.
Therefore i am searching for a way to loop over all presented to the server, and in the end have a cumulative state and multiple line summary.
For your insight as to the summary i am looking for as example when multiple categories of updates are available:
def check_linux_dnf(section):
update_found=False # init update_found marker
for line in section: # loop over the lines
if line[0].isdigit: # check if number (update found)
update_found=True # set marker
# check for the update type and output the result
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")
# if no update found, outpout a summary
if not update_found:
yield Result(state=State.OK, summary="No DNF Updates found.")