-
Notifications
You must be signed in to change notification settings - Fork 0
/
redfish-collect
executable file
·57 lines (43 loc) · 1.25 KB
/
redfish-collect
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/ruby
############################
#
# Redshift Collector for Zabbix
#
# This script will be able to collect information previously discovered via LLD
#
# by [email protected] ## 07-08-2018
#
#
require 'net/https'
require 'uri'
require 'json'
USER =ARGV[0]
PASS =ARGV[1]
HOST =ARGV[2]
ITEMSURL=ARGV[3]
LOCALPATH="/etc/zabbix/externalscripts/redfish/"
if !USER || !PASS || !HOST || !ITEMSURL
puts "You must gimme something man!"
puts "Try: $./redfish-lld user pass host item/something/orelse"
exit 1
end
ITEMDEST = ITEMSURL.gsub("||","%7C%7C")
FILETMP = ITEMSURL.gsub("||","__")
ITEMFILE = FILETMP.gsub("%23","-")
base = URI.parse(["https://",HOST,ITEMDEST].join(''))
request = Net::HTTP::Get.new(base)
request.basic_auth(USER, PASS)
response = Net::HTTP.start(base.hostname, base.port, :timeout => 60, :use_ssl => base.scheme == "https", :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https|
https.request(request)
end
list = JSON.parse(response.body)
filename=ITEMFILE.split("/")[-1]
filename=[LOCALPATH,HOST,"-",filename,".json"].join('')
#puts JSON.pretty_generate(list)
if File.file?("#{filename}")
file = File.delete("#{filename}")
end
open("#{filename}","w") do |f|
f.write(JSON.pretty_generate(list))
end
puts filename