Hello everyone I am currently trying to let my Table on my dashboard display an Array which should look like this.
Email - Array containing LotusServer and POP3-Server
Each of those containing different values like a host_name
, service_descriptions
, uptime duration
...
I need to send back a json output to the table, its working to display the POP3-Server and LotusServer on their own but, the idea is to have groups of hosts being displayed.
I am trying to push those Array's into a new Array called latest and send that back to the table but I don't seem to get the syntax right. Im quite new to ruby maybe someone can give me a hint or help me solve this problem?
Here's some code that might explain better where I'm stuck:
# get the url to download the status.cgi which contains the values
def request_status(url, user, pass, type)
case type
when "host"
url_part = "style=hostdetail"
when "service"
url_part = "host=all&hoststatustypes=3"
else
throw "status type '" + type + "' is not supported!"
end
uri = URI.parse(url + "?" + url_part + "&nostatusheader&jsonoutput&sorttype=1&sortoption=6")
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)
if (user and pass)
request.basic_auth(user, pass)
end
response = http.request(request)
return JSON.parse(response.body)["status"][type+"_status"]
end
# when service_description in status("usv") push the values into the usv Array
# after that push the usv Array into the latest Array <-- Problem
case status["service_description"]
when "usv"
usv.push({ cols: [
{ value: status['host_name'].to_json},
{ value: status['status'].to_json, class: 'icinga-status icinga-status-'+status['status'].downcase },
]})
usv.push({ cols: [
{ value: status['service_description'].to_json, class: 'icinga-servicename' },
{ value: status['duration'].gsub(/^0d\s+(0h\s+)?/, ''), class: 'icinga-duration' }
]})
latest.push({ cols:[
{ value: usv.to_json},
]})
when "Disk Space"
disk.push({ cols: [
{ value: status['host_name']},
{ value: status['status'], class: 'icinga-status icinga-status-'+status['status'].downcase },
]})
disk.push({ cols: [
{ value: status['service_description'], class: 'icinga-servicename' },
{ value: status['duration'].gsub(/^0d\s+(0h\s+)?/, ''), class: 'icinga-duration' }
]})
end
This is the output I get :
[{"cols":[{"value":"\"usv\""},{"value":"\OK"","class":"icinga-status icinga-status-ok"}]},{"cols":[{"value":"\"usv\"","class":"icinga-servicename"},{"value":"9h 47m 3s","class":"icinga-duration"}]}]
I got a Table widget. Displaying for example "E-Mail" then a check or a cross to see whether its down or up. Then the next entry Network same for that. Each of those Entries have different hosts in them for example for E-Mail POP3 Server and Lotus Server which all have different states Up/down, uptime, host_name and so on. So when one of those hosts has a problem it should display a cross in the list next to E-Mail if all states are ok it should be a check.
The question is how can I access the stuff in latest[usv]['host_name'] for example I am planning to display a list of the groups and check for any errors in the Up/down state and/or other problems for each group respectivly.
Thank you in advance Fabian