Created
January 5, 2015 15:07
-
-
Save bahamut45/a71a060575f48dbba5f7 to your computer and use it in GitHub Desktop.
tg-downtime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'rubygems' | |
require 'cgi' | |
require 'csv' | |
require 'json' | |
require 'pp' | |
# colors | |
BOLD = "\e[1;39m" | |
RESET = "\e[0m" | |
class String | |
def strip_tags | |
self.gsub( %r{</?[^>]+?>}, '' ) | |
end | |
end | |
server = "192.168.26.72" | |
port = "6557" | |
query = %{"GET hosts | |
Filter: host_scheduled_downtime_depth = 1 | |
Columns: host_name address downtimes_with_info | |
ColumnHeaders: on"} | |
downtime=`echo #{query} | nc #{server} #{port}` | |
adowntime = downtime.gsub(";",",") | |
body = adowntime.strip_tags | |
CSV::Converters[:blank_to_nil] = lambda do |field| | |
field && field.empty? ? nil : field | |
end | |
csv = CSV.new(body,:headers => true, :header_converters => :symbol, :converters => [:all, :blank_to_nil]) | |
downtime_format = csv.to_a.map {|row| row.to_hash } | |
server = "#{BOLD}Serveur#{RESET}".ljust(30) | |
address = "#{BOLD}Ip#{RESET}".ljust(20) | |
owner = "#{BOLD}Utilisateur#{RESET}".ljust(30) | |
comment = "#{BOLD}Raison#{RESET}".ljust(20) | |
#puts "#{server}\t #{address}\t #{owner}\t #{comment}" | |
downtime_format.each do |item| | |
host = item[:name].ljust(20) | |
ip = item[:address].ljust(20) | |
split_down = item[:downtimes_with_info].split("|") | |
user = split_down[1].ljust(20) | |
reason = split_down[2].ljust(20) | |
if ( host !~ /(col)/i ) | |
puts "#{host} #{ip} #{user} #{reason}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment