I have a html content that gets generated dynamically and i want to display the same in the Grafana. Manually populating the Ajax Plugin is not feasible. I understand that the Ajax plugin can be used for the same. How can i send the html content to this plugin and what are the different parameters (image below) that have to be updated to get the data right?
I’m using Python to push the data to the Influxdb. example below -
The variable htmloutput contains the html data that has to be displayed.
client = InfluxDBClient(host='10.10.10.10', port=8086)
client.switch_database('TesDB')
json_body = [
{
"measurement": "MS1",
"tags": {
"Server": QA1,
},
"time": timestamp,
"fields": {
"HTMLCONTENT": htmloutput
}
}
]
client.write_points(json_body)
Sample HTML Output that I get which needs to be displayed -
HTML Code -
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-type" content="text/html;charset=UTF-8"><title>Errors</title><link rel="stylesheet" type="text/css" href="styles.css"><script src="code.js" type="text/javascript"></script></head><body onload="preparepage();"><input type="hidden" id="imageBase" value="img/"><a name="17">Problem 1</a></h3><div id="exp17"><div class="important"><div><p>104 errors of <b>General Exceptions</b>, at <b>Overview page</b> occupy <b>26.92%</b> in total. <br><br><b>Keywords</b><br>General<br>Unavailable, Temporary<br></div></div></div></div><br>
</body></html>
Thanks in advance.
Related
I am trying to fetch a page from the internet then save it into a HTML file. The page has this in the header:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" >
<head>
<meta http-equiv="Content-Type" content="text/html;charset=Shift_JIS" />
</head>
No matter what I try, the saved HTML page looks horrible and I just can't get it to save the Japanese characters properly.
I am using node-fetch, fs.writeFile and a module named jconv. I have tried all combinations but nothing works. Right now, the code is supposed to convert from SJIS to UTF-8, then fs should write the file with UTF-8 encoding.
fetch(link).
then((res) => {
if (res.ok) {
return res.text();
}
console.log("Invalid data");
}).
then((body) => {
// this is supposed to convert from SJIS to UTF-8
var buf = jconv.convert(body, 'SJIS', 'UTF-8');
// save file
fs.writeFile(path, buf, 'UTF-8', (err) => {
if (!err) {
console.log('Saved');
}
});
});
I have tried other encodings but the final HTML document still does not show the proper special characters, just like on the online page from which is taken. A page that I am testing right now is this
The line:
<meta http-equiv="Content-Type" content="text/html;charset=Shift_JIS" />
must also be modified to:
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
to have the charset information in the header match the new encoding.
Description:
WordPress Contact Form 7;
Mailing using smtp;
Form Settings: "use html-format" + "mail2 use html-format" checked;
Form Settings: Email body : just one mail-tag [calculated-template];
Problem with paragraph tag solved (all mail-tags upon receiving are shown inside "p" html-tag);
[calculated-template] is a mail-tag dynamically filled with html, based on submitted objects handled by VueJS2 on frontend;
[calculated-template] is populated by hooking at action 'wpcf7_posted_data':
add_action('wpcf7_posted_data', array('vue_handler','handle'), 1, 1);
vue_handler::handle($data) receives $data array with some wpcf7 data which can be modified. Contents of $data array:
_wpcf7 = "1166"
_wpcf7_version = "4.9.2"
_wpcf7_locale = "ru_RU"
_wpcf7_unit_tag = "wpcf7-f1166-p1167-o1"
_wpcf7_container_post = "1167"
columns-stringified = ""
fences-stringified = ""
your-name = "name"
your-email = "email#test.com"
calculated-template = ""
Then vue_handler::handle($data) injects html into email-tag [calculated-template].
Problem:
Finally [calculated-template] html-contents rendered escaped (Mailtrap.io, "HTML Source" tab):
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Title</title>
</head>
<body>
<h1>Example Header</h1>
</body>
</html>
The main idea of the snippet: opening and closing html-tag symbols "<", ">" rendered escaped: "<", ">";
SOLVED
By using another hook wpcf7_before_send_mail
In which I fully replaced mail body with my dynamic html.
List of all hooks:
http://hookr.io/plugins/contact-form-7/4.5.1/hooks/#index=a
I have this on my server
app.get('*', function(req, res) {
match({ routes, location: req.url }, (error, redirectLocation, renderProps) => {
const body = renderToString(<RouterContext {...renderProps} />)
res.send(`
<!DOCTYPE html>
<html>
<head>
<link href="//cdn.muicss.com/mui-0.6.5/css/mui.min.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="root">${body}</div>
<script defer src="assets/app.js"></script>
</body>
</html>
`)
})
})
And this on the client side
import { Router, hashHistory, browserHistory, match } from 'react-router'
let history = browserHistory
//client side, will become app.js
match({ routes, location, history }, (error, redirectLocation, renderProps) => {
render(<Router {...renderProps} />, document.getElementById('root'))
})
the problem
It works only when I remove the (let history = browserHistory), but it adds the /#/ hash prefix to my url(which I don't want to happen).
When I leave the let (history = browserHistory) there, it throws an error
Warning: React attempted to reuse markup in a container but the checksum was invalid. This generally means that you are using server rendering and the markup generated on the server was not what the client was expecting. React injected new markup to compensate which works but you have lost many of the benefits of server rendering. Instead, figure out why the markup being generated is different on the client or server:
(client) < ! -- react-empty: 1 -
(server) < section data-reactro
The error message is pretty clear, however, I don't understand why it works with the hashHistory but fails with the browserHistory
version incompatibility issue
solution
{
"history": "^2.1.2",
"react-router": "~2.5.2"
}
links:
https://github.com/reactjs/react-router/issues/3003
So I have a folder rules that that looks like this:
rule-001.json
rule-002.json
rule-003.json
Each *.json file is of a unified format:
{ name: 'AAA', descriptions: 'BBB' }
How can I generate a pages based on these files in Assemble?
The short answer is that you need to load your JSON data in your Gruntfile and use it to replace the Assemble pages object.
I have written a blog post about generating pages from data, based on the Assemble Blog Theme sample. In both cases, the pages data was stored in a single JSON file.
In your case, you need to load the data from all of JSON files in your Gruntfile, and transform the data into the pages format. You can do this any number of ways, but one simple way would be to write a function in your Gruntfile that does this:
function loadDataPages (jsonFileSpec) {
var path = require("path");
var jsonPaths = grunt.file.expand(jsonFileSpec);
var jsonPages = jsonPaths.map(function (jsonPath) {
var jsonData = grunt.file.readJSON(jsonPath);
var outputFileName = path.basename(jsonPath, path.extname(jsonPath)) + ".html";
var jsonPage = {
"data": jsonData,
"content": "This is the body content for page " + outputFileName,
"filename": outputFileName
};
return jsonPage;
});
return jsonPages;
}
and then you need to load this data object in your Grunt config and pass it to Assemble's pages option:
grunt.initConfig({
assemble: {
data: {
options: {
flatten: true,
layout: "source/templates/layouts/custom-data-layout.hbs",
pages: loadDataPages("source/custom-data/*.json")
},
files: {
"output/custom-data-pages/": ["source/custom-data/index.hbs"]
}
}
}
// ...
});
Here is what the layouts might look like:
custom-data-layout.hbs
<!DOCTYPE html>
<html>
<head>
<title>Custom Data - {{name}}</title>
</head>
<body>
<h1>Custom Data - {{name}}</h1>
<p>{{ description }}</p>
{{> body }}
</body>
</html>
index.hbs
---
layout: false
title: Custom Data Index
---
<!DOCTYPE html>
<html>
<head>
<title>{{title}}</title>
</head>
<body>
<h1>{{title}}</h1>
<ul>
{{#each pages }}
<li>{{basename}}</li>
{{/each}}
</ul>
</body>
</html>
Something like this should work for you. You just create separate Assemble tasks and call the main Assemble task with grunt.
https://gist.github.com/davidwickman/a0bf961e3099ea6b9c35
This is my HTML file below which draws a graph. When I am opening my HTML file using IE/Firefox/Chrome, I can see my graph properly.
I need to send this graph within an email body. When I try to use the below command, I can only see the plain text version of this HTML:
mail -r techgeeky#domain.com < graph.html
So I modified my file, graph.html like below by adding few lines at the top. And then again when I fire the above command, I am getting nothing in my mail body. Is there anything I need to add specifically at the top of the email to make this work? I am running SunOS 5.10.
From: techgeeky#domain.com
To: techgeeky#domain.com
Subject: MIME Test
Mime-Version: 1.0
Content-type: text/html; charset=utf-8
Content-transfer-encoding: us-ascii
<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart() {
// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Title');
data.addColumn('number', 'Value');
data.addRows([
['No Error Percentage', 100-16.81336174073654],
['Error Percentage', 16.81336174073654]
]);
// Set chart options
var options = {'title':'LIP Data Quality Report',
'width':700,
'height':600};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<!--Div that will hold the pie chart-->
<div id="chart_div" style="width:900px; height: 800px;"></div>
</body>
</html>
You would have to:
Grab the HTML generated with the javascript library
Strip out any scripting, events, etc.
Send the HTML string to your server (you may need to encode it)
Send the email with the HTML string as its body from your server.