140b57b2bbf38cc61de4dfe856c2b4f1df916159
[god.git] / lib / god / conditions / disk_usage.rb
blob140b57b2bbf38cc61de4dfe856c2b4f1df916159
1 module God
2   module Conditions
3     
4     class DiskUsage < PollCondition
5       attr_accessor :above, :mount_point
6       
7       def initialize
8         super
9         self.above = nil
10         self.mount_point = nil
11       end
12       
13       def valid?
14         valid = true
15         valid &= complain("Attribute 'mount_point' must be specified", self) if self.mount_point.nil?
16         valid &= complain("Attribute 'above' must be specified", self) if self.above.nil?
17         valid
18       end
19       
20       def test
21         usage = `df | grep -i " #{self.mount_point}$" | awk '{print $5}' | sed 's/%//'`
22         usage.to_i > self.above
23       end
24     end
25     
26   end
27 end