im trying to adapt a script on monitoring if the clamav-freshclam service has fetched the current databases from the mirror and iva ran into a problem.
As you probably know the freshclam command usually just works manually after a “killall freshclam”. And therefor i get the output in Icinga
The service looks like that
def freshclamStatus():
freshclam_stdout = subprocess.Popen([‘freshclam’, ‘status’], stdout=subprocess.PIPE)
freshclam_out = {}
freshclam_out[‘service’] = {}
freshclam_out[‘perfd’] = {}
freshclam_msg = ‘Database failed to update.’
freshclam_status = 2
# Counts if all 3 Databases are reported as up-to-date
freshclam_counter = 0
for line in io.TextIOWrapper(freshclam_stdout.stdout, encoding='UTF-8'):
if 'up-to-date' in line.split('-> '):
freshclam_counter = freshclam_counter + 1
if freshclam_counter == 3:
freshclam_status = 0
if freshclam_status == 0:
freshclam_msg = 'ClamAV-Freshclam Databases are up-to-date.'
freshclam_out['service']['name'] = 'ClamAV-Freshclam:'
freshclam_out['service']['state'] = freshclam_status
freshclam_out['service']['msg'] = freshclam_msg
freshclam_out['perfd']['leap_status'] = {}
freshclam_out['perfd']['leap_status']['value'] = freshclam_status
freshclam_out['perfd']['leap_status']['max'] = 2
freshclam_out['perfd']['leap_status']['crit'] = 2
return freshclam_out
Im not that much of a coder, programmer or similar, so please have mercy by your answers which i appreciate a lot anyway.
Oh and don’t over complicate it, it’s fine for a first minimal working prototype, to just return the right of the 4 exit codes (0 = OK, 1 = warn, 2 = crit, 3 = unknown)!
Programming is a iterative process and after a proof of concept a lot of versions are needed to reach the finished product but often a lot of versions in between are still usable if not feature complete. Also most projects never advance from the status of a minimal working prototype
freshclam_stdout = subprocess.Popen([‘freshclam’, ‘status’], stdout=subprocess.PIPE)
for line in io.TextIOWrapper(freshclam_stdout.stdout, encoding=‘UTF-8’):
because it wanna start a “freshclam” in the command line, which isnt possible since its already up and running and i do not wanna kill the clamav-freshclam.service everytime i execute the script. I kinda need a change of the the subprocess, so that it reads in the current output of “systemctl status clamav-freshclam.service” and not tries to start another freshclam service.
I cut all the stuff about error states and how to report thtat stuff to icinga and the head information, because its not relevant to my problem. U might argue its more sth for a python forum, which is true, but in there ppl have the thing to ask the “why you need this anyway” question which is very annoying.