I'm creating a job in Ruby which takes info from a mysql database and sends it to a html page to create a widget. The thing is, I can't get the data to be displayed when I take it out of a mysql database, however when I type the input in manually and send that to the html page...it works!
require 'Mysql2'
SCHEDULER.every '10s', :first_in => 0 do |job|
$application, $details, $timestamp = 0
table = Array.new
client = Mysql2::Client.new(:host => "localhost", :username => "****", :password => "****", :database => "Sample_Database")
#Gets statistics for latest input
sstc = client.query("SELECT * FROM Probably_Serious_Alerts")
sstc.each do |row|
$row = "{ cols: [ {value: '" + row["time_stamp"].to_s + "'}, {value: '"+ row["application"].to_s + "'}, {value: '" + row["details"].to_s + "'}]}"
table.push($row)
end
rows = "rows = ["
for row in table
rows = rows + row + ","
end
rows = rows[0...-1]
rows = rows + ']'
hrows = [
{ cols: [ {value: 'Time'}, {value: 'Monitoring System'}, {value: 'Event'}]}
]
sleep(1)
#rows = [
# { cols: [ {value: '2016-09-19 14:39:30 +0100'}, {value: 'Solarwinds'}, {value: 'First Solarwinds Error'}]},
# { cols: [ {value: '2016-09-19 15:24:17 +0100'}, {value: 'Nagios'}, {value: 'First Nagios'}]}]
puts rows
send_event('my-table', { hrows: hrows, rows: rows } )
end
The commented code is the code which is printed to the terminal when I run it. This is also what I send to the HTML page and works on the widget. Any ideas? Is something async?