Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

httphandler.h File Reference


Detailed Description

The httphandler will attempt to connect() to a http server and HTTP 'GET' a url, then regex match against each line in HTTP header and content. This is useful to poll web servers to see if they are up and if up, scan headers for certain codes (e.g., "404 Not Found"), scan content for application error messages (e.g., "Error"), etc. Using the triptime: option events with the round trip time will be generated.

You may have multiple regex's, each generating its own events. This avoids connecting for each regex, rather it is is read one time for all. You may optionally specify a subsitution string that behaves similar to 'sed' to customize the generated events.

If you supply a substitution string, rather than copying the original complete matching string, the substitution string is used, replacing all occurances of the special charcters \[0-9] with the associated substring matches. Note: \0 matches the whole expression, while \1,\2 through \9 are substring matches 1, 2 through 9. For example, say you are watching a web server, you might want a special message if you start getting file not found responses. The regex is:

"HTTP/.* 404"

and the substitution is:
"my.website.com/ returned file not found! Call Fred at 555.555.5555 and yell at him"

Regex's are POSIX 1003.2 "extended" form.

NOTE: If you are NOT measuring triptime, then the httphandler will check the Last-Modified: timestamp via a HEAD request before doing the GET and applying the regex matching. If the file has not been modified since the last handler, then noregex matching will be done.

Wire keywords (standard handler keywords documented in Wire )

You my have multiple match: lines. Matches are applied in the order they are declared.

Example:

set noconnect create event { name: "noconnect"  priority: 1 }
set four-oh-four create event { name: "file not found"  priority: 1 }
set oracle-error create event { name: "oracle error"  priority: 1 }

create handler http { 
 url: http://webserver.mydomain.com
 noconnect: $noconnect
 match: $four-oh-four "" "HTTP/.* 404" "webserver home page is missing!"
 match: $oracle-error "" "ORA-[0-9][0-9][0-9][0-9][0-9][0-9]" ""
 timeout: 5
 cycletime: 60
}
Events generated:
Event NameTypeDescription
connect AW_EVENT_TYPE_STRING Was able to connect, send string of "url"
noconnect AW_EVENT_TYPE_STRING Was NOT able to connect, send string of "url"
service AW_EVENT_TYPE_STRING Found valid HTTP header, send string of "url"
noservice AW_EVENT_TYPE_STRING Did NOT find valid HTTP header, send string of "url"
match AW_EVENT_TYPE_STRING Regex match in line of HTTP header or body, send string of matching line or substitution
nomatch AW_EVENT_TYPE_STRING No regex match in any line of HTTP header or body, send string of "url"
triptime AW_EVENT_TYPE_INT32 Estimated round trip time in usec

#include "regexmatch.h"
#include "sysnet.h"
#include "monitor.h"
#include "wire.h"

Go to the source code of this file.

Data Structures

struct  aw_httphandler_cevents_t
 Events generated for connect(). More...

struct  aw_httphandler_mirror_t
 Holds events_sig, filename, and fd for mirroring the file that we GET. More...

struct  aw_httphandler_regex_t
 Specifies a regex and associated events. More...

struct  aw_httphandler_revents_t
 Events generated for regex matching. More...

struct  aw_httphandler_state_t
 State of handler during probing. More...

struct  aw_httphandler_t
 Handler object. More...

struct  aw_httphandler_watcher_t
 Compiled regex, associated events and state. More...


Defines

#define AW_HTTPHANDLER_LASTMODIFIED_BUFFER_SIZE   64
#define AW_HTTPHANDLER_READ_BUFFER_SIZE   4096

Enumerations

enum  aw_httphandler_state_cd_t {
  AW_HTTPHANDLER_IDLE, AW_HTTPHANDLER_WAIT_HEAD_CONNECT, AW_HTTPHANDLER_WAIT_HEAD_WRITE, AW_HTTPHANDLER_WAIT_HEAD_READ,
  AW_HTTPHANDLER_WAIT_GET_CONNECT, AW_HTTPHANDLER_WAIT_GET_WRITE, AW_HTTPHANDLER_WAIT_GET_READ, AW_HTTPHANDLER_DONE
}
 The state codes for each state on handler, nominal path is straight thru. More...


Functions

aw_httphandler_t * aw_create_httphandler (const byte_t *url, const aw_httphandler_cevents_t *cevents, const aw_timestamp_t timeout, u_int32_t nregexs, const aw_httphandler_regex_t *regexs, const byte_t *mirror_filename, const aw_event_sig_t *mirror_updated, int32_t(*regevent)(aw_handler_t *h, aw_address_t *eventid, u_int32_t index), int32_t(*regmaskevent)(aw_handler_t *h, aw_address_t *eventid, u_int32_t index), const aw_alarm_sched_t *sched, aw_logger_t *logger)
 Create a http handler.

void aw_free_httphandler (aw_httphandler_t *p)
 Free handler and all associated resources.

aw_handler_t * aw_wire_httphandler (aw_wire_mkhandler_args_t *args)
 Create a http handler using "wire". See header doc for keyword documentation.


Define Documentation

#define AW_HTTPHANDLER_LASTMODIFIED_BUFFER_SIZE   64
 

#define AW_HTTPHANDLER_READ_BUFFER_SIZE   4096
 


Enumeration Type Documentation

enum aw_httphandler_state_cd_t
 

The state codes for each state on handler, nominal path is straight thru.

Enumeration values:
AW_HTTPHANDLER_IDLE  not doing anything
AW_HTTPHANDLER_WAIT_HEAD_CONNECT  waiting on a connect()
AW_HTTPHANDLER_WAIT_HEAD_WRITE  waiting on a write()
AW_HTTPHANDLER_WAIT_HEAD_READ  waiting on a read()
AW_HTTPHANDLER_WAIT_GET_CONNECT  waiting on a connect()
AW_HTTPHANDLER_WAIT_GET_WRITE  waiting on a write()
AW_HTTPHANDLER_WAIT_GET_READ  waiting on a read()
AW_HTTPHANDLER_DONE  done


Function Documentation

aw_httphandler_t* aw_create_httphandler (  const byte_t *  url,
const aw_httphandler_cevents_t *  cevents,
const aw_timestamp_t  timeout,
u_int32_t  nregexs,
const aw_httphandler_regex_t *  regexs,
const byte_t *  mirror_filename,
const aw_event_sig_t *  mirror_updated,
int32_t(*  regevent)(aw_handler_t *h, aw_address_t *eventid, u_int32_t index),
int32_t(*  regmaskevent)(aw_handler_t *h, aw_address_t *eventid, u_int32_t index),
const aw_alarm_sched_t *  sched,
aw_logger_t *  logger
) 
 

Create a http handler.

aw_create_httphandler

Parameters:
url Url to GET
cevents Events to generate connect/noconnect
timeout Max time to connect()
nregexs How many regex strings
regexs Array of regex strings/events
mirror_filename If not NULL, put contents of GET into file
mirror_updated Event to generate when mirror is updated, may be NULL
regevent Function pointer for event registration
regmaskevent Function pointer for event mask registration
sched Run schedule
logger Logger object
Returns:
Handler object

void aw_free_httphandler (  aw_httphandler_t *  p  ) 
 

Free handler and all associated resources.

aw_free_httphandler

Parameters:
p The handler

aw_handler_t* aw_wire_httphandler (  aw_wire_mkhandler_args_t *  args  ) 
 

Create a http handler using "wire". See header doc for keyword documentation.

aw_wire_httphandler

Aware 0.11.1 Copyright (C) 1998-2005 Russell Leighton (russ@elegant-software.com)