L7_query - javascript/jQuery queries on DOM on target URLs

Templates, scripts for templates, scripts and requests for templates.

Moderators: Moderators, Developers

Post Reply
Author
Message
User avatar
johnrembo
Cacti User
Posts: 216
Joined: Mon Apr 24, 2006 3:33 am

L7_query - javascript/jQuery queries on DOM on target URLs

#1 Post by johnrembo » Fri Nov 19, 2010 8:23 am

Hello everyone,

if you're looking for an easy way to fetch and cacti-display some numbers from the particular website - this one should help

Let's take some figures from finance.google.com for example:
Image

Here's what script does:
# node L7_query.js "http://finance.google.com" gfinance.js
value1:11181 value2:1197 value3:2514
and here are these numbers on the graph:
Image

the jQuery script to fetch those 3 numbers looks like:

Code: Select all

var response=[];
jQuery('#sfe-mktsumm').find('td.bld').each( function(i,el) {
    var val=el.firstChild.innerHTML.replace(',','');
    val=Math.round(val,0);
    response.push('value'+(i+1)+':'+val);
} );

console.log(response.join(' '));
for retrieving single value it's even simpler (following script fetches current temperature from weather.yahoo.com for monaco->monte-carlo):

Code: Select all

var response=jQuery('#yw-cond').next().children('dd')[0].innerHTML.match(/\d+/)[0];
here's the result on the cacti server:
# node L7_query.js "http://weather.yahoo.com/monaco/monte-c ... 02/?unit=c" yweather.js
temperature:15
you can event allow for you customers to write, upload and execute these scripts, since they do only have access to DOM of particular website being queried against, not the cacti-system itself.
Attachments
L7_query.tar.gz
v0.1
(49.98 KiB) Downloaded 110 times
[url=http://forums.cacti.net/viewtopic.php?t=24934&highlight=zond]zond plugin[/url]
[url=http://forums.cacti.net/viewtopic.php?t=28384]memorize plugin[/url]
[url=http://forums.cacti.net/viewtopic.php?p=141322#141322]transporter plugin[/url]

Post Reply