Class: HQ::CheckDrill::Script

Inherits:
Tools::CheckScript
  • Object
show all
Defined in:
lib/hq/check-drill/script.rb

Instance Method Summary collapse

Constructor Details

#initializeScript

Returns a new instance of Script.



11
12
13
14
# File 'lib/hq/check-drill/script.rb', line 11

def initialize
	super
	@name = "Drill"
end

Instance Method Details

#perform_checksObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/hq/check-drill/script.rb', line 44

def perform_checks

	now = Time.now.utc

	@drill_elems.each do
		|drill_elem|

		next unless drill_elem.find("match").all? {
			|match_elem|

			current = now.strftime match_elem["template"]
			regex = Regexp.new "^(?:#{match_elem["regex"]})$"

			current =~ regex

		}

		critical drill_elem["message"]

		return

	end

	message "no drills just now"

end

#prepareObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/hq/check-drill/script.rb', line 31

def prepare

	config_doc =
		XML::Document.file @opts[:config]

	@config_elem =
		config_doc.root

	@drill_elems =
		config_doc.find("drill").to_a

end

#process_argsObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/hq/check-drill/script.rb', line 16

def process_args

	@opts, @args =
		Tools::Getopt.process args, [

			{ :name => :config,
				:required => true },

		]

	@args.empty? \
		or raise "Extra args on command line"

end