1. SQL WIDGET PLUGIN
Project name: |
com_nexthink_SqlTimeSeriesNGet |
Source SVN: |
http://svn.intra.nexthink.com/service/portal/plugin--sql |
Contents
1.1. Version information and downloads
Latest version - V4 (64 bit):
Plugin Version
Portal Version
Date
Key features
Download
v1.3.1
Portal V4
2011-12-21
Support for 64 bit
Latest version - V3 (32 bit):
Plugin Version
Portal Version
Date
Key features
Download
v1.3.1
Portal 3.1 and upper
2011-10-13
Fix for ITS
Older versions:
Plugin Version
Portal Version
Date
Key features
Download
v1.3.0
Portal 3.1 and upper
2010-07-16
Oracle support
v1.2.1
Portal 3.1 and upper
2010-06-03
CSV export
v1.2.0
Portal 3.1.1 and upper
2009-12-08 09:53:09 +0100
Allows no SQL expression for daily value or table as well
v1.1.0
Portal 3.0.4 and 3.0.5
2009-06-04 16:27:11 +0200
MySQL support
v1.0.2
Portal v3.0.3
2009-02-11 16:28:50 +0100
Test step
v1.0.0
Portal v3.0.1
2008-12-16 13:56:23 +0100
Basic version
1.2. What's new ?
2010-07-15 [V1.2.0.0] Support for Oracle
2009-06-04 [v1.1.0.0] Support for MySQL
1.3. Summary
This project implements a Portal plugin, providing:
- an SQL connector to an arbitrary Oracle/Postgres/MySQL RDBMS,
- a configuration wizard to define all parameters, with in particular, SQL statements defining: a metric and an optional (top) table,
- a visualization widget, displaying the metric and the table in time:
1.4. Prerequisites
- An access to the RDBMS over TCP/IP, with an account able to read the wanted table(s).
- A working NEXThink Portal, version see "Version information" table above.
1.5. Limitations
- RDBMS credentials are managed in a per-widget basis (not centralized).
- RDBMS are stored in plain text into the Portal configuration.
- When the server is unreachable, it takes approx 3 minutes to time out.
1.6. Deployment on a Production Site
1.6.1. Prerequisites
Before you "go on-site", make sure you have the file with you, see ยง Version information and downloads above.
- You will need shell (SSH) access to the Portal server.
1.6.2. Quick installing (Portal V3.2.2 and upper)
As root:
cd /var/nexthink/portal rsquery/installPlugin.py /path/to/project--plugin--sql--rXXXX.plugin
1.6.3. Manual installing (Portal V3.2.1 and before)
- Be root.
Install the plugin as usual:
cd /var/nexthink/portal cat /path/to/plugin-sql--rXXXX.plugin | tar xvz
Import the module (this will install the necessary 3rd party packages):
cd /var/nexthink/portal plugin-install/plugin--sql.sh
The portal should restart automatically, make sure it did, and if not, do, as root:
/etc/init.d/nxt-tomcat restart
1.6.4. Installing the examples
- Create a test DB on the portal's Postgres server:
cd /var/nexthink/portal/ngets/com_nexthink_SqlTimeSeriesNGet/test/ ./build_database.sh postgres
The test DB contains items with dates from 2007-10-02 to 2010-10-28. - Log into the portal web site as admin.
- Take the sample module from the library:
- Now you can compute the widget for a small date range between 2008-01-07 and 2008-10-28.
- Upon error, see the file
tail -n 100 /var/nexthink/portal/log/portal.log
- See the metrics in its dashboard.
1.7. Using the widget
1.7.1. Creating your SQL expressions
- An SQL interactive terminal is useful, to create and test the SQL statements, and introspect the tables structures: For PosrgreSQL:
psql DATABASE -U USER
for MySQL:mysql DATABASE -u USER -p
1.7.2. SQL-specific steps of the wizard
- Widget instances can be created interactively in the Portal, via Create Widget in the Admin tab.
1.7.2.1. Step 1: parameters
Daily value
- SQL expression:
- The SQL expression must return a single value (the result of a reduction)
It can use these time-related tokens: %Y Year with 4 digits, %m Month with 2 digits, %d Day with 2 digits
Daily table
- SQL expression:
- An SQL statement which should return a table. If omitted, no table will be computed nor displayed.
It can use these time-related tokens: %Y Year with 4 digits, %m Month with 2 digits, %d Day with 2 digits
- Caption: The title appearing above the table, if the table is specified.
- Columns: Each lines defines how each column of the table will be handled. Each line has the format:
Column title or Column title = TYPE
where TYPE is one of string or number (by default string if omitted)
- SQL expression:
1.7.2.2. Step 2: tests
- This step allows to test the two SQL statements. A date can be entered. If no date is entered, the current date (today) is used.
- The results are output in plain text into the text area.
- Errors (such as connection, SQL, or column format) are also indicated into the text area.
1.7.3. SQL Hints
For the daily value:
Use a reduction function like COUNT, SUM, AVERAGE. Example:
SELECT count("ID") FROM ...
For the daily table:
- All computed rows will all be displayed. Hence, the table should not exceed a "reasonable" size (approx 5 columns and 50 rows).
- Tips:
to sort the table, use ORDER
to limit the number of rows, use LIMIT
to produce rows counting similar entries, use COUNT and GROUP BY
For all SQL statements:
- To have results sensitive to date/time, some time-related tokens can be used:
%Y
Year with 4 digits
%m
Month with 2 digits
%d
Day with 2 digits
Actually, all strftime tokens (aka formatting directives, aka format codes) are available; see http://docs.python.org/library/datetime.html?highlight=strftime#strftime-behavior.
SQL dialects
- Each RDBMS some syntactic specificities, especially to express date ranges. Examples:
Database type
Database
Daily value
Daily table
MySQL
NDOUtils (history tool for Nagios)
select count("object_id") from nagios_statehistory where state_type=1 and state_time>='%Y-%m-%d 00:00:00' and state_time<'%Y-%m-%d 23:59:59'
select state, count(*) from nagios_statehistory where state_type=1 and state_time>='%Y-%m-%d 00:00:00' and state_time<'%Y-%m-%d 23:59:59' group by state order by 1 desc
PostgreSQL
Data exported from McAfee ePO
select count("ID") from test_schema.test_table where "EventDateTime" between '%Y-%m-%d' and (date '%Y-%m-%d' + interval '1 day')
select "VirusName", COUNT(*) from test_schema.test_table where "EventDateTime" between '%Y-%m-%d' and (date '%Y-%m-%d' + interval '1 day') group by "VirusName" order by 2 desc
