obnam_check

obnam Check

Obnam 1.0/1 gibt passenden Output für Nagios aus. Mit meinem Patch wird direkt Output für check_mk generiert und ein Local-Check kann sich auf folgende Zeilen beschränken:

#!/bin/sh
 
/usr/bin/obnam check_mk-last-backup-age 2>/dev/null ||
echo "2 obnam_backup - CRITICAL - System Error"

Patch gegen Obnam 1.0:

--- show_plugin.py.orig  2012-08-24 11:20:13.634743159 +0200
+++ show_plugin.py	2012-08-30 13:20:01.406287189 +0200
@@ -42,6 +42,8 @@
         self.app.add_subcommand('ls', self.ls, arg_synopsis='[GENERATION]...')
         self.app.add_subcommand('nagios-last-backup-age', 
                                 self.nagios_last_backup_age)
+        self.app.add_subcommand('check_mk-last-backup-age', 
+                                self.check_mk_last_backup_age)
 
 
         self.app.settings.string(['warn-age'],
@@ -120,6 +122,34 @@
         print "OK: backup is recent.  last backup was %s."%(
             self.format_time(most_recent))
 
+    def check_mk_last_backup_age(self, args):
+        '''Check if the most recent generation is recent enough.'''
+        self.open_repository()
+        most_recent = None
+
+        warn_age = self._convert_time(self.app.settings['warn-age'])
+        critical_age = self._convert_time(self.app.settings['critical-age'])
+
+        for gen in self.repo.list_generations():
+            start, end = self.repo.get_generation_times(gen)
+            if most_recent is None or start > most_recent: most_recent = start
+        self.repo.fs.close()
+
+        now = self.app.time()
+        if (now - most_recent > critical_age):
+            print "2 obnam_backup - CRITICAL - backup is to old. Last backup was %s. (levels %s/%s)"%(
+                self.format_time(most_recent),self.app.settings['warn-age'],
+                self.app.settings['critical-age'])
+            sys.exit(0)
+        elif (now - most_recent > warn_age):
+            print "1 obnam_backup - WARNING - backup is to old. Last backup was %s. (levels %s/%s)"%(
+                self.format_time(most_recent),self.app.settings['warn-age'],
+                self.app.settings['critical-age'])
+            sys.exit(0)
+        print "0 obnam_backup - OK - backup is recent. Last backup was %s. (levels %s/%s)"%(
+            self.format_time(most_recent),self.app.settings['warn-age'],
+            self.app.settings['critical-age'])
+
     def genids(self, args):
         '''List generation ids for client.'''
         self.open_repository()

  • obnam_check.txt
  • Zuletzt geändert: 2017/03/17 11:37
  • (Externe Bearbeitung)