Sending information to a widget in Dashing
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?
mysql ruby asynchronous widget dashing
add a comment |
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?
mysql ruby asynchronous widget dashing
1
how are you "sending" it to the html page? Can you post that code?
– DiegoSalazar
Sep 19 '16 at 18:05
also what does your .erb file look like?
– Ryan Litwiller
Sep 30 '16 at 1:47
add a comment |
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?
mysql ruby asynchronous widget dashing
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?
mysql ruby asynchronous widget dashing
mysql ruby asynchronous widget dashing
asked Sep 19 '16 at 15:18
Dan SavageDan Savage
909
909
1
how are you "sending" it to the html page? Can you post that code?
– DiegoSalazar
Sep 19 '16 at 18:05
also what does your .erb file look like?
– Ryan Litwiller
Sep 30 '16 at 1:47
add a comment |
1
how are you "sending" it to the html page? Can you post that code?
– DiegoSalazar
Sep 19 '16 at 18:05
also what does your .erb file look like?
– Ryan Litwiller
Sep 30 '16 at 1:47
1
1
how are you "sending" it to the html page? Can you post that code?
– DiegoSalazar
Sep 19 '16 at 18:05
how are you "sending" it to the html page? Can you post that code?
– DiegoSalazar
Sep 19 '16 at 18:05
also what does your .erb file look like?
– Ryan Litwiller
Sep 30 '16 at 1:47
also what does your .erb file look like?
– Ryan Litwiller
Sep 30 '16 at 1:47
add a comment |
1 Answer
1
active
oldest
votes
I know it's a bit late but since I stumbled upon this question on Stackoverflow when Googling for the same issue I had when trying to push data to the Smashing Table Widget I thought someone else might be happy if I shared my solution. The issue in your code is that you put the rows object you return as a string, however the Table Widget expects, let me quote from the Documentation:
To send a row to the tbody (or thead), send a array of hashes to rows (hrows for thead). The bindings work from row to column. Every column should be it's own array element off a cols hash. The hash must have a key of "value" in order to show up. To send multiple rows, use an array of these hashes.
So you have to transform the MySQL Result into an Array of Hashes. See my code below, note that "Loc Nr.", "Address" and "Status" are the Column Names of my MySQL Table:
results = db.query(sql)
hrows = [
{ cols: [ {value: 'Loc Nr.'}, {value: 'Address'}, {value: 'Status'}]}
]
table = Array.new
results.each do |row|
table.push({ cols: [ {value: row['Loc Nr.']}, {value: row['Address']}, {value: row['Status']}]})
end
send_event('locations', { hrows: hrows, rows: table } )
Hope you already found the solution but it might help someone else :D
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f39576678%2fsending-information-to-a-widget-in-dashing%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I know it's a bit late but since I stumbled upon this question on Stackoverflow when Googling for the same issue I had when trying to push data to the Smashing Table Widget I thought someone else might be happy if I shared my solution. The issue in your code is that you put the rows object you return as a string, however the Table Widget expects, let me quote from the Documentation:
To send a row to the tbody (or thead), send a array of hashes to rows (hrows for thead). The bindings work from row to column. Every column should be it's own array element off a cols hash. The hash must have a key of "value" in order to show up. To send multiple rows, use an array of these hashes.
So you have to transform the MySQL Result into an Array of Hashes. See my code below, note that "Loc Nr.", "Address" and "Status" are the Column Names of my MySQL Table:
results = db.query(sql)
hrows = [
{ cols: [ {value: 'Loc Nr.'}, {value: 'Address'}, {value: 'Status'}]}
]
table = Array.new
results.each do |row|
table.push({ cols: [ {value: row['Loc Nr.']}, {value: row['Address']}, {value: row['Status']}]})
end
send_event('locations', { hrows: hrows, rows: table } )
Hope you already found the solution but it might help someone else :D
add a comment |
I know it's a bit late but since I stumbled upon this question on Stackoverflow when Googling for the same issue I had when trying to push data to the Smashing Table Widget I thought someone else might be happy if I shared my solution. The issue in your code is that you put the rows object you return as a string, however the Table Widget expects, let me quote from the Documentation:
To send a row to the tbody (or thead), send a array of hashes to rows (hrows for thead). The bindings work from row to column. Every column should be it's own array element off a cols hash. The hash must have a key of "value" in order to show up. To send multiple rows, use an array of these hashes.
So you have to transform the MySQL Result into an Array of Hashes. See my code below, note that "Loc Nr.", "Address" and "Status" are the Column Names of my MySQL Table:
results = db.query(sql)
hrows = [
{ cols: [ {value: 'Loc Nr.'}, {value: 'Address'}, {value: 'Status'}]}
]
table = Array.new
results.each do |row|
table.push({ cols: [ {value: row['Loc Nr.']}, {value: row['Address']}, {value: row['Status']}]})
end
send_event('locations', { hrows: hrows, rows: table } )
Hope you already found the solution but it might help someone else :D
add a comment |
I know it's a bit late but since I stumbled upon this question on Stackoverflow when Googling for the same issue I had when trying to push data to the Smashing Table Widget I thought someone else might be happy if I shared my solution. The issue in your code is that you put the rows object you return as a string, however the Table Widget expects, let me quote from the Documentation:
To send a row to the tbody (or thead), send a array of hashes to rows (hrows for thead). The bindings work from row to column. Every column should be it's own array element off a cols hash. The hash must have a key of "value" in order to show up. To send multiple rows, use an array of these hashes.
So you have to transform the MySQL Result into an Array of Hashes. See my code below, note that "Loc Nr.", "Address" and "Status" are the Column Names of my MySQL Table:
results = db.query(sql)
hrows = [
{ cols: [ {value: 'Loc Nr.'}, {value: 'Address'}, {value: 'Status'}]}
]
table = Array.new
results.each do |row|
table.push({ cols: [ {value: row['Loc Nr.']}, {value: row['Address']}, {value: row['Status']}]})
end
send_event('locations', { hrows: hrows, rows: table } )
Hope you already found the solution but it might help someone else :D
I know it's a bit late but since I stumbled upon this question on Stackoverflow when Googling for the same issue I had when trying to push data to the Smashing Table Widget I thought someone else might be happy if I shared my solution. The issue in your code is that you put the rows object you return as a string, however the Table Widget expects, let me quote from the Documentation:
To send a row to the tbody (or thead), send a array of hashes to rows (hrows for thead). The bindings work from row to column. Every column should be it's own array element off a cols hash. The hash must have a key of "value" in order to show up. To send multiple rows, use an array of these hashes.
So you have to transform the MySQL Result into an Array of Hashes. See my code below, note that "Loc Nr.", "Address" and "Status" are the Column Names of my MySQL Table:
results = db.query(sql)
hrows = [
{ cols: [ {value: 'Loc Nr.'}, {value: 'Address'}, {value: 'Status'}]}
]
table = Array.new
results.each do |row|
table.push({ cols: [ {value: row['Loc Nr.']}, {value: row['Address']}, {value: row['Status']}]})
end
send_event('locations', { hrows: hrows, rows: table } )
Hope you already found the solution but it might help someone else :D
answered Nov 14 '18 at 13:33
Nils RehwaldNils Rehwald
559
559
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f39576678%2fsending-information-to-a-widget-in-dashing%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
how are you "sending" it to the html page? Can you post that code?
– DiegoSalazar
Sep 19 '16 at 18:05
also what does your .erb file look like?
– Ryan Litwiller
Sep 30 '16 at 1:47