sFlowTrend-Pro includes an interface which can be used to control it from other applications. The intention of this capability is to allow an application, such as a switch element manager, to change the view within sFlowTrend-Pro to match the context of the external application. For example, if an element manager which has been integrated with sFlowTrend-Pro is being used to configure a switch, then the user could automatically make sFlowTrend-Pro display traffic information for that switch.
This part of the sFlowTrend-Pro help is intended for developers, who are working on integrating other applications with sFlowTrend-Pro.
When sFlowTrend-Pro runs, it automatically starts a web server, listening on TCP port 8087 (by default - you can change it with the advanced configuration properties, see Section 9.3, “Custom configuration”). When specific URLs are visited at this address, sFlowTrend-Pro will respond by taking an appropriate action. Several URLs are provided by default with sFlowTrend-Pro, which perform basic functions. These are actually implemented in JavaScript, which allows more complex control to be implemented relatively easily, if desired.
The URLs use standard http
GET
(or
query)
parameters, to pass information to sFlowTrend-Pro. For
example, the URL to change the switch and switch
interface currently being viewed in sFlowTrend-Pro, to
10.1.2.3
and
49
,
respectively, is
//localhost:8087/selectIfIndex.js?agent=10.1.2.3&ifIndex=49
.
The intention is that such URLs would be visited by an
external application, which directly controls sFlowTrend-Pro.
However, to test and demonstrate some of the URLs
available, you can point a web browser directly at
//localhost:8087
(on the system running sFlowTrend-Pro). This will display a
web page which allows different controls to be tried
out.
Note that for security reasons, by default sFlowTrend-Pro
only will respond to web requests from
localhost
(which, of course, means that sFlowTrend-Pro must be running
on the same system as the application or web browser
that is trying to access sFlowTrend-Pro). This can be changed
through the use of the advanced configuration properties
(see
Section 9.3, “Custom configuration”).
The following URLs are provided for easy integration. In most cases, these are sufficient, but if more flexibility is required custom URLs (see Section 9.4.3, “Creating custom URLs”) can be generated. With the default URLs, if the request is successful, then the URL will return the string "OK". If it fails, then the string "FAIL -", followed by an error message (where possible), is returned. These strings can be used by an application to understand the success of a request.
sFlowTrend-Pro comes with some web pages pre-packaged into
the application. However, these can be overridden, or
new ones generated, if specific customization is
desired. By default, the document root is the directory
html
in the sFlowTrend-Pro data directory. This will need to be
created before it can be used. Files placed in this
directory will form available URLs, in the customary
fashion for a web server. Files with the extension
html
will be served as html files, and those with the
extension
.js
will be interpreted as JavaScript scripts.
If html files are used with the sFlowTrend-Pro web server, these will be served up in the normal way, but will not affect the operation of sFlowTrend-Pro. JavaScript must be used to control sFlowTrend-Pro. To use JavaScript to generate a URL, first create the file (eg html/test.js, within the sFlowTrend-Pro data directory). The content of this file should be standard JavaScript 1.6, with some extensions to allow control of sFlowTrend-Pro. The available extensions are:
The object sFlowTrend
is
the main interface to the
running application. It has several
properties defined:
agentIP
.
agentIP
,
and the current interface to
ifIndex
.
Provides a means for JavaScript to write to
the current html document. Anything written
to
document
will be returned from this URL. Methods
available are:
s
to the document.
s
to the document, followed by a
new line.
getVars
is an Object, with properties set for each
get variable
passed in through the URL. For example, if
the URL was of the form
//localhost:8087/test.js?key=value
,
then getVars.key will contain
value
,
This is a simple example, which is actually the JavaScript for the selectAgent page.
var pretty = getVars.pretty == "true"; if (pretty) { pageName = "sFlowTrend select agent"; include("../inc/header.js"); } document.writeln(sFlowTrend.selectAgent(getVars.agent)); if (pretty) { document.writeln("<br>"); include("../inc/footer.js"); }
In this example, we first look for the get variable
pretty
.
We set a boolean variable to
true
if the get variable is set to the string
true
.
This is used to produce nicer formatted html; for
the case of integrating with an external
application, it is best to leave this unset, as the
result of the URL will be easier to parse. If
pretty
is set, then we include a header file, which just
provides a the standard HTML headers, and a style
sheet. Likewise, at the end, we include a footer
file if pretty is true.
The real work is in the line
document.writeln(sFlowTrend.selectAgent(getVars.agent));
.
This calls the
selectAgent
method with the get variable
agent
,
passed in through the URL, and then writes the
result to document.