Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
flucas1 committed Jul 21, 2024
1 parent 4e6d16f commit 4e6b3a2
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions check_grubentry
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def exitnagios(status,message):

#-------------------------------------------------------------------------------

def dogrubentrycall(expected):
def dogrubentrycall(expectedpos):
try:
lines = []
handle = open("/boot/grub/grub.cfg", "r")
Expand All @@ -60,9 +60,11 @@ def dogrubentrycall(expected):
allcandidates.append(doublequotes[0])
validcandidates = []
for item in allcandidates:
if item.startswith("Debian GNU/Linux, with Linux "):
if item.startswith("Debian GNU/Linux"):
validcandidates.append(item)
infomsg(validcandidates)
expectedstring = validcandidates[expectedpos]
infomsg("expected -> "+expectedstring)

cmdline = ["/usr/bin/uname","--kernel-release"]
completedproc = subprocess.run(cmdline,capture_output=True)
Expand All @@ -72,14 +74,13 @@ def dogrubentrycall(expected):
version = ""
if exitcode == 0:
version = output.strip()
currententry = "Debian GNU/Linux, with Linux "+version
infomsg(currententry)
runningending = ", with Linux "+version
infomsg("running -> "+runningending)

foundindex = validcandidates.index(currententry)
if foundindex==expected:
exitnagios("OK","running grub entry '"+currententry+"'")
if expectedstring.endswith(runningending):
exitnagios("OK","grub entry '"+str(expectedpos)+" - "+expectedstring+"' matches the running version '"+version+"'")
else:
exitnagios("WARNING","running grub entry '"+currententry+"' but it was expected '"+validcandidates[expected]+"'")
exitnagios("WARNING","running grub entry with version '"+version+"' but it was expected '"+expectedstring+"'")
except Exception as e:
exitnagios("CRITICAL","internal issue - "+str(e))

Expand Down

0 comments on commit 4e6b3a2

Please sign in to comment.