retire da-backup checks
[mirror/dsa-nagios.git] / dsa-nagios-checks / checks / dsa-check-filesystems
1 #!/usr/bin/ruby
2
3 require 'filesystem'
4
5 ignorefs = ["NFS", "nfs", "nfs4", "nfsd", "afs", "binfmt_misc", "proc", "smbfs",
6             "autofs", "iso9660", "ncpfs", "coda", "devpts", "ftpfs", "devfs",
7             "mfs", "shfs", "sysfs", "cifs", "lustre_lite", "tmpfs", "usbfs",
8             "udf", "fusectl", "fuse.snapshotfs", "rpc_pipefs"]
9 mountpoints = {}
10
11 FileSystem.mounts.each do |m|
12         if ((not ignorefs.include?(m.fstype)) && (m.options !~ /bind/))
13                 mountpoints[m.device] = { 'type' => m.fstype, 'mount' => m.mount }
14         end
15 end
16
17 def check_ext3(dev, mnt)
18         output=%x{tune2fs -l #{dev}}
19         if output =~ /FS Error count:\s*(\d+)/ and $1.to_i > 0
20                 return "#{dev} (#{mnt}) has #{$1} errors"
21         end
22 end
23
24 output = []
25 mountpoints.keys.each do |m|
26         temp = ''
27         begin
28                 if mountpoints[m]['type'] =~ /ext/
29                         temp = check_ext3(m, mountpoints[m]['mount'])
30                 end
31         rescue Exception => e
32         end
33         if temp && (temp.length > 0)
34                 output << temp
35         end
36 end
37
38 if output.length > 0
39         puts output.join("\n")
40         exit 1
41 end
42 puts "OK: All filesystems ok."
43 exit 0