You are on page 1of 5

HTTP Event Gate

Request syntax
Checking Request Correctness
SecurOS Events
Custom HTTP Requests
Configuring HTTP Request Filter
Creating HTTP Request Handler
HTTP_EVENT_PROXY Events
HTTP_EVENT_PROXY Commands
Streaming via HTTP Event Gate

HTTP Event Gate is used for transmitting data from an external system to SecurOS. Data is transmitted via HTTP GET/POST requests.

Port - Port number of the SecurOS HTTP server, which


receives requests from the external system.

To transmit data to SecurOS, an external system should send a request to the specified port number of the HTTP server.

Request syntax
http://<video_server_IP_address>:<port>/event?<param1_name>=<param1_value>[&<param2_name>=<param2_value>[& . . . ]], where:

http://<video_server_IP_address>:<port>/event? — URL to send a request;


<video_server_IP_address> — IP address of the SecurOS Video Server, where the HTTP Event Gate object is created;
<port> — port number of the SecurOS HTTP server, specified in the object settings;
<param1_name>,<param2_name>,. . . — name of the parameters, which will be transmitted to the SecurOS.
<param1_value>,<param2_value>,. . . — value of the parameters, which will be transmitted to the SecurOS.

For example,

to transmit to SecurOS a license plate and coordinates of the vehicle, one should send the following request: http://172.16.1.41:808
0/event?plate=135&latitude=57.6565&longitude=37.8787,
or the following request to transmit a persons' name : http://172.16.1.41:8080/event?name=Alex

Checking Request Correctness


To check if request is correct, send it via web browser..

If the following request was sent: http://172.16.1.41:8080/event?plate=135&latitude=57.6565&longitude=37.8787, the server will return the
following string in the browser window: Event(HTTP_EVENT_PROXY|1|RECEIVED|_body<>,_method<GET>,_path</event>,_peer_address
<::1>,latitude<57.6565>,longitude<37.8787>,plate<135>) has been sent to SecurOS, where:

latitude<57.6565>,longitude<37.8787>,plate<135> — parameters transmitted in the request;


The following are SecurOS service parameters generated by the system automatically:
_body<> — text body of the POST request;
method<GET> — HTTP method used to transmit the request. Possible values: GET or POST .
path</event> — request path (see Custom HTTP Requests).
peer_address<::1> — IP address of the request sender. If a request is sent from the computer, where HTTP Event Gate is
deployed, this parameter has the value of ::1.
SecurOS Events
If a request is correct, then a response of the HTTP server is returned in the web browser.

Thus, if the following request was sent: http://172.16.1.41:8080/event?plate=135&latitude=57.6565&longitude=37.8787, then the following
event will be generated within SecurOS: Event : HTTP_EVENT_PROXY 1 RECEIVED
_body<>,plate<135>,_method<GET>,latitude<57.6565>,_path</event>,_peer_address<::1>,longitude<37.8787>,slave_id<S-PROKHOROV.
1>,owner<S-PROKHOROV>,date<19-12-14>,time<12:11:39.340>,core_global<1>

Custom HTTP Requests


Besides standard HTTP requests HTTP Event Gate supports custom requests. The rules of the custom request processing are specified in a
VB/JScript program.

To work with custom queries within SecurOS it is necessary to do the following:

1. Specify a list of the allowed requests using a HTTP Request Filter .


2. Specify an individual HTTP Request Handler for each request, that implements the following functions:
preparing data for the incoming unfiltered requests (for example, data in XML format);
sending a response to the request with prepared data.

Configuring HTTP Request Filter


HTTP request filter is defined in the paths.txt file, that is stored in the \Modules\http_event_proxy folder of the SecurOS install directory. One
line of the file corresponds to one request. If a URL of the request has a constant part and another part may vary, then you also can merge
them with the help of the * character. For example, see listing 1.

Listing 1. Using wild card in the request filter


/*if requests are the following:*/
/config/user1?par1=val1&par2=val2
/config/user2?par1=val1&par2=val2
...
/config/user16?par1=val1&par2=val2

/*create the following rule in paths.txt: to merge URLs*/


/config/user*

Listing 2 represents a simple request filter.

Listing 2. Request filter example


/*If the paths.txt contains the following strings:
/get-analytics
/get-detectors
/get-state/*

/*then the allowed URLs are the following:


http://ip:port/get-analytics?par1=val1&par2=val2
http://ip:port/get-detectors
http://ip:port/get-state/linecross_detector
http://ip:port/get-state/abandoned_detector?from=26-01-14%2011:12:13&to=26-01-14%2012:13:14
/*etc.

/*and not allowed URLs are the following:


http://ip:port/get-analytics/plates
http://ip:port/command
/*etc.*/
Creating HTTP Request Handler
To process custom requests the following events and commands are supported by the HTTP Event Gate object:

HTTP_EVENT_PROXY Events

Event identifier Description Parameters

PENDING_REQUES Incoming custom _id Request identifier. Is used to respond to a request.


T request
_path Substring of the URL between :port and ?.

For example, if request string is http://ip:port/path/is?param1=value1, then the /path/is subs


tring will be the parameter value

_method HTTP request method. Possible values: GET/POST/DELETE .

_peer_address IP address of the sender.

custom Custom parameters are defined by the query contents (see Request syntax).
parameters

RECEIVED Incoming custom _path Substring of the URL between :port and ?.
request
For example, if request string is http://ip:port/path/is?param1=value1, then the /path/is subs
tring will be the parameter value

_method HTTP request method. Possible values: GET/POST/DELETE.

_peer_address IP address of the sender.

custom Custom parameters are defined by the query contents (see Request syntax ).
parameters

HTTP_EVENT_PROXY Commands

Command Description Parameters


identifier

RESPONSE Send a respond for the received request PENDING _id Request identifier received within the PENDING_REQUEST.
_REQUEST. Required parameter.

_body Request text body (for example, data in XML format).

_content_type Type of the data transmitted within _body parameter. Default


value is application/xml.

Example of possible values:

text/plain; charset=utf-8,
application/json; charset=utf-8 и т.д.

Listing 3 represents a request handler.


Listing 3. Request handler
/*paths.txt contains the following rules:
* /get-analytics
* /get-detectors
* /get-config/*
*/

/* SecurOS receives the following requests:


* http://ip:port/get-analytics
* http://ip:port/get-detectors?area=outdoor
* http://ip:port/get-config/abandoned?area=indoor
*/

//Declare custom events handler


functionfunction Init(){
Core.RegisterEventHandler("HTTP_EVENT_PROXY","1","PENDING_REQUEST","fRequestHandler");
}

//Request handler
function fRequestHandler(e){
switch(e._path){
case "/get-analytics": fGetAnalytics(e, e._id); break;
case "/get-detectors": fGetAnalytics(e, e._id); break;
default:
if( e._path.match(/get-config/ ) fGetConfig(e, e._path, e._id);
break;
}
}

//Response example
function fGetAnalytics(e, request_id){
...
var text= "<xml><param>value</param></xml>";
Core.DoReact("HTTP_EVENT_PROXY","1","RESPONSE","_id",request_id,"_body", text);
}
function fGetAnalytics(e, id){ ... }
function fGetConfig(e, path, id){ ... }

Streaming via HTTP Event Gate


HTTP Event Gate provides processing of the stream data, that is transmitted into SecurOS. Any text data (for example, XML) can be
transmitted. External application is sending HTTP POST request; the data is transmitted in the request body.

Example of the XML data transmission into SecurOS is shown below.


Listing 4. JScript program example to transmit XML data
function Init(){
Core.RegisterEventHandler("MACRO","1.1","RUN","fSend");
Core.RegisterEventHandler("HTTP_EVENT_PROXY","1","RECEIVED","fPrint");
}
function fSend(e){
var HTTP = new ActiveXObject("Msxml2.ServerXMLHTTP.3.0");
var url = "http://127.0.0.1:9050/event?id=777";
var XML = "<root><node1>value1</node1><node2>value2</node2></root>"
HTTP.open("POST",url,false);
HTTP.send(XML);
var response = HTTP.responseXML;
}
function fPrint(e){
Script.Echo(e._body);
}

You might also like