Class: Riemann::Babbler::Plugin::Iptables
- Inherits:
-
Riemann::Babbler::Plugin
- Object
- Riemann::Babbler::Plugin
- Riemann::Babbler::Plugin::Iptables
- Defined in:
- lib/riemann/babbler/plugins/iptables.rb
Constant Summary
Constants included from Riemann::Babbler::Plugins::Helpers
Riemann::Babbler::Plugins::Helpers::RIEMANN_RESERVED_FIELDS
Constants included from Errors
Errors::CONNECTION_PROBLEM, Errors::INIT_CONNECT, Errors::RESOLV_RIEMANN_SERVER, Errors::USER_CALL_SHUTDOWN
Instance Attribute Summary
Attributes inherited from Riemann::Babbler::Plugin
#errors, #plugin, #plugin_name, #riemann
Instance Method Summary collapse
Methods inherited from Riemann::Babbler::Plugin
#get_state, inherited, #initialize, #not_minimize_sent_event, #plugin_error!, #plugin_no_error!, registered_plugins, #report, #report_with_diff, #run!, #set_default, #set_last_event, #tick
Methods included from Riemann::Babbler::Plugins::Helpers
#event_from_hash, #event_from_json, #rest_get, #shell, #unixnow
Methods included from Options
included, #merge_config, #name_to_underscore, #opts, #opts_reset!, #underscore_to_name
Methods included from Logging
#get_logger_speaker, included, #log, #set_logger_speaker
Constructor Details
This class inherits a constructor from Riemann::Babbler::Plugin
Instance Method Details
#collect ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/riemann/babbler/plugins/iptables.rb', line 17 def collect current_rules = shell('iptables-save').split("\n").map do |x| x[0] == "#" ? nil : delete_counters(x) # delete counters and comments end.compact.join("\n") saved_rules = File.read(plugin.rules_file).split("\n").map do |x| x[0] == "#" ? nil : delete_counters(x) # delete counters and comments end.compact.join("\n") status = current_rules == saved_rules ? 'ok' : 'critical' { :service => "#{plugin.service} #{plugin.rules_file}", :state => status, # status 'ok' will be minimized :description => "#{plugin.service} rules different between file: #{plugin.rules_file} and iptables-save" } end |
#delete_counters(str) ⇒ Object
13 14 15 |
# File 'lib/riemann/babbler/plugins/iptables.rb', line 13 def delete_counters(str) str.gsub(/\[\d+\:\d+\]/, '').strip end |
#init ⇒ Object
3 4 5 6 7 |
# File 'lib/riemann/babbler/plugins/iptables.rb', line 3 def init plugin.set_default(:service, 'iptables') plugin.set_default(:rules_file, '/etc/network/iptables') plugin.set_default(:interval, 60) end |
#run_plugin ⇒ Object
9 10 11 |
# File 'lib/riemann/babbler/plugins/iptables.rb', line 9 def run_plugin File.exists? plugin.rules_file end |