Netcool/OMNIbus 7.4 HTTP Interface
The HTTP interface provides the following services:
- Table Collection Services – used to insert, update, delete and select rows from any ObjectServer database table (user or system)
- Row Element Services – enables a specific row in a table, identified by the RowSerial field or by the table’s primary key, to be inserted, updated or deleted
- SQL Command Factory – execute free form SQL statements
Access to the HTTP interface is controlled through Basic Authentication, with the credentials of a valid ObjectServer user needing to be supplied as part of each request. The HTTP interface can be accessed over HTTPS to secure the connection. The information returned by the services is in a JSON format, for which most popular programming or scripting languages have libraries available.
To enable the (non-SSL) HTTP interface, a number of properties need to be set in the ObjectServer’s properties file, the key ones being:
NRestOS.Enable: TRUE
NHttpd.EnableHTTP: TRUE
NHttpd.ListeningPort: 8080
When restarted, the ObjectServer should now be listening on port 8080 for requests.
The below Perl code snippet demonstrates how the Table Collection Services URI can be used to select rows from the alerts.status table, applying a filter and order by clause. For brevity the script doesn’t include any error checking, which would of course be a sensible inclusion for any production code:
#!perl
use strict;
use warnings;
use LWP::UserAgent;
use JSON;
use URI::Escape;
# Connection details
my $server = ‘192.168.81.163:8080’;
my $realm = ‘omnibus’;
my $user = ‘root’;
my $password = ”;
my $ua = LWP::UserAgent->new();
$ua->credentials($server, $realm, $user, $password);
# Construct a URI equivalent to the following SQL statement:
# select LastOccurrence, Node, Summary from alerts.status where Manager = ‘ConnectionWatch’ order by LastOccurrence DESC
my $db = ‘alerts’;
my $table = ‘status’;
my @columns = qw(LastOccurrence Node Summary);
my $collist = uri_escape_utf8(join(‘,’, @columns));
my $filter = uri_escape_utf8(“Manager=’ConnectionWatch'”);
my $orderby = uri_escape_utf8(‘LastOccurrence DESC’);
my $uri = “ http://$server/objectserver/restapi/$db/$table?filter=$filter&collist=$collist&orderby=$orderby”;
# Do a GET request
my $resp = $ua->get($uri);
# Convert the response into a JSON object
my $data = JSON->new()->decode($resp->content);
# Process the JSON object
foreach my $row (@{$data->{rowset}->{rows}}) {
print join(“t”, map { $row->{$_} } @columns ), “n”;
}
The below code shows how a row of data can be added to a table:
#!perl
use strict;
use warnings;
use LWP::UserAgent;
use JSON;
use HTTP::Request;
# Connection details
my $server = ‘192.168.81.163:8080’;
my $realm = ‘omnibus’;
my $user = ‘root’;
my $password = ”;
my $ua = LWP::UserAgent->new();
$ua->credentials($server, $realm, $user, $password);
# Generate a URI to insert a row (Node, StartTime, EndTime) into the custom.maintenance table
my $db = ‘custom’;
my $table = ‘maintenance’;
my $uri = “ http://$server/objectserver/restapi/$db/$table”;
# The row data
my $rowset =
{
‘rowset’ =>
{
‘coldesc’ => [
{
‘name’ => ‘Node’,
‘type’ => ‘string’,
},
{
‘name’ => ‘StartTime’,
‘type’ => ‘integer’,
},
{
‘name’ => ‘EndTime’,
‘type’ => ‘integer’,
}
],
‘rows’ => [
{
‘Node’ => ‘database01’,
‘StartTime’ => 1355232240,
‘EndTime’ => 1355240000
}
]
}
};
my $json_text = JSON->new()->encode($rowset);
# Generate a POST request
my $req = HTTP::Request->new(POST => $uri);
$req->content_type(‘application/json’);
$req->content($json_text);
my $resp = $ua->request($req);
print $resp->as_string();
The below code shows how rows can be deleted from a table:
#!perl
use strict;
use warnings;
use LWP::UserAgent;
use JSON;
use URI::Escape;
# Connection details
my $server = ‘192.168.81.163:8080’;
my $realm = ‘omnibus’;
my $user = ‘root’;
my $password = ”;
my $ua = LWP::UserAgent->new();
$ua->credentials($server, $realm, $user, $password);
# Delete all rows from custom.maintenance where Node is ‘database01’
my $db = ‘custom’;
my $table = ‘maintenance’;
my $filter = uri_escape_utf8(“Node=’database01′”);
my $uri = “ http://$server/objectserver/restapi/$db/$table?filter=$filter”;
# Do the DELETE request
my $resp = $ua->delete($uri);
print $resp->as_string();
Hits: 707