$(document).ready(function(){ function get_chef_attributes(hostname) { $.getJSON('node/'+hostname, function(attributes) { var roles = ''; $.each(attributes['automatic']['roles'], function() { roles += this + ' '; }); $('.chef_attributes').html( 'Node Name:
'+attributes['name']+'

' +'Public IP:
'+attributes['automatic']['ec2']['public_ipv4']+'

' +'Roles:
'+roles+'
' ); }); } ws = new WebSocket("ws://" + location.hostname + ":9000"); ws.onmessage = function(evt) { $("#messages").empty(); $("#popups_container").empty(); data = JSON.parse(evt.data); for(var msg in data) { var status = ''; if(data[msg]['status'] == 'CRITICAL') { status = "Critical"; } else { status = "Warning"; } var last_time_ok = new Date(data[msg]['last_time_ok'] * 1000); var last_check = new Date(data[msg]['last_check'] * 1000); $("#messages").append(''+data[msg]['host_name'] +''+data[msg]['plugin_output']+'
' +'
' +'
' +''+last_time_ok.toLocaleString() +''+last_check.toLocaleString()+''); var plugin_output = ''; if (data[msg]['long_plugin_output'] != '') { plugin_output = data[msg]['long_plugin_output']; } else { plugin_output = data[msg]['plugin_output']; } $("#popups_container").append(''); $("#link_"+msg).fancybox({ 'autoDimensions' : false, 'width' : 700, 'height' : 420, 'padding' : 5, 'title' : data[msg]['host_name'], 'transitionIn' : 'fade', 'transitionOut' : 'fade', 'onComplete' : function() { get_chef_attributes($("#fancybox-title-float-main").html()); }, 'onClosed' : function() { $('.chef_attributes').html('Querying Chef ...'); } }); }; }; });