Class: Qnotifier::Plugin
- Inherits:
-
Object
- Object
- Qnotifier::Plugin
- Defined in:
- lib/plugin.rb
Instance Attribute Summary collapse
-
#alert_count ⇒ Object
Returns the value of attribute alert_count.
-
#alerts ⇒ Object
Returns the value of attribute alerts.
-
#class_name ⇒ Object
Returns the value of attribute class_name.
-
#config ⇒ Object
Returns the value of attribute config.
-
#defaults ⇒ Object
Returns the value of attribute defaults.
-
#reports ⇒ Object
Returns the value of attribute reports.
-
#stats ⇒ Object
Returns the value of attribute stats.
Instance Method Summary collapse
-
#add_alert(name, message, severity) ⇒ Object
Add the alert to the outbound queue.
-
#alert(name, message, severity = 3) ⇒ Object
Alert is an alert to the adminstrators that something requires looking at Severity should usually be 3.
-
#delete(key) ⇒ Object
Delete the value.
-
#get(key) ⇒ Object
Retrieve this value.
-
#log ⇒ Object
Log something to console Log levels: log.info, log.warn, log.error, log.fatal, log.unknown.
-
#main ⇒ Object
You’ll need to override this in your subclass.
-
#put(key, value) ⇒ Object
Store this value for later retrieval.
-
#report(key, value) ⇒ Object
Report is an ongoing data point for graphing and realtime reporting for this server.
-
#reset_alert(name, message) ⇒ Object
Alert is no longer needed as the value has crossed back over the threshold value.
-
#run ⇒ Object
The run method, do not override.
-
#stat(key, value) ⇒ Object
Stat is a one time statistic about this server, it doesn’t get tracked and graphed.
Instance Attribute Details
#alert_count ⇒ Object
Returns the value of attribute alert_count.
14 15 16 |
# File 'lib/plugin.rb', line 14 def alert_count @alert_count end |
#alerts ⇒ Object
Returns the value of attribute alerts.
11 12 13 |
# File 'lib/plugin.rb', line 11 def alerts @alerts end |
#class_name ⇒ Object
Returns the value of attribute class_name.
15 16 17 |
# File 'lib/plugin.rb', line 15 def class_name @class_name end |
#config ⇒ Object
Returns the value of attribute config.
13 14 15 |
# File 'lib/plugin.rb', line 13 def config @config end |
#defaults ⇒ Object
Returns the value of attribute defaults.
9 10 11 |
# File 'lib/plugin.rb', line 9 def defaults @defaults end |
#reports ⇒ Object
Returns the value of attribute reports.
10 11 12 |
# File 'lib/plugin.rb', line 10 def reports @reports end |
#stats ⇒ Object
Returns the value of attribute stats.
12 13 14 |
# File 'lib/plugin.rb', line 12 def stats @stats end |
Instance Method Details
#add_alert(name, message, severity) ⇒ Object
Add the alert to the outbound queue
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/plugin.rb', line 68 def add_alert(name, , severity) @alerts = {@class_name => []} unless @alerts @alert_count += 1 if severity == 1 # emergency log.fatal elsif severity == 2 # critical log.error elsif severity == 3 # alert log.error elsif severity == 4 # error log.error elsif severity == 5 # warn log.warn elsif severity == 6 # clear log.info end data = [name, , severity] @alerts[@class_name].push(data) Qnotifier::Storage.put("AlertTime_#{@class_name}-#{name}", Time.now) end |
#alert(name, message, severity = 3) ⇒ Object
Alert is an alert to the adminstrators that something requires looking at Severity should usually be 3
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/plugin.rb', line 53 def alert(name, , severity = 3) # Only send the alert if we haven't already if Qnotifier::Storage.get("AlertTime_#{@class_name}-#{name}") # Check to see if we need to resend the alert if @config["resend_alerts"] and Qnotifier::Storage.get("AlertTime_#{@class_name}-#{name}") < Time.now - @config["resend_alert_time"] add_alert(name, , severity) else Qnotifier.log.debug("Already sent alert: #{} (resends every #{@config["resend_alert_time"]}s)") end else add_alert(name, , severity) end end |
#delete(key) ⇒ Object
Delete the value
124 125 126 |
# File 'lib/plugin.rb', line 124 def delete(key) Qnotifier::Storage.delete(key) end |
#get(key) ⇒ Object
Retrieve this value
119 120 121 |
# File 'lib/plugin.rb', line 119 def get(key) Qnotifier::Storage.get(key) end |
#log ⇒ Object
Log something to console Log levels: log.info, log.warn, log.error, log.fatal, log.unknown
47 48 49 |
# File 'lib/plugin.rb', line 47 def log return Qnotifier.log end |
#main ⇒ Object
You’ll need to override this in your subclass
41 42 43 |
# File 'lib/plugin.rb', line 41 def main Qnotifier.log.error("You must implement the main method in the plugin: #{self.class.name}") end |
#put(key, value) ⇒ Object
Store this value for later retrieval
114 115 116 |
# File 'lib/plugin.rb', line 114 def put(key, value) Qnotifier::Storage.put(key, value) end |
#report(key, value) ⇒ Object
Report is an ongoing data point for graphing and realtime reporting for this server
102 103 104 105 |
# File 'lib/plugin.rb', line 102 def report(key, value) @reports = {@class_name => []} unless @reports @reports[@class_name].push([key, value]) end |
#reset_alert(name, message) ⇒ Object
Alert is no longer needed as the value has crossed back over the threshold value
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/plugin.rb', line 90 def reset_alert(name, ) if Qnotifier::Storage.get("AlertTime_#{@class_name}-#{name}") Qnotifier.log.error "Resetting alert" @alerts = {@class_name => []} unless @alerts log.warn Qnotifier::Storage.delete("AlertTime_#{@class_name}-#{name}") data = [name, , 6] # Clear @alerts[@class_name].push(data) end end |
#run ⇒ Object
The run method, do not override
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/plugin.rb', line 18 def run @class_name = self.class.to_s.split("::").last @alert_count = 0 @alerts = nil @reports = nil @stats = nil # Read the options from the global config and mix them in to the defaults for this plugin if @config[@class_name] @options = @defaults.update(@config[@class_name]) else @options = @defaults end # Only run this plugin if it's enabled return unless @options["enabled"] puts "Plugin #{@class_name} running" if $qnotifier_debug main end |
#stat(key, value) ⇒ Object
Stat is a one time statistic about this server, it doesn’t get tracked and graphed
108 109 110 111 |
# File 'lib/plugin.rb', line 108 def stat(key, value) @stats = {@class_name => {}} unless @stats @stats[@class_name].merge!(key => value.to_s) end |