Forum Discussion
winston_85158
Oct 16, 2014Nimbostratus
Anyone using HSL with Graylog
Hi,
Is anyone using HSL in combination with Graylog (see http://www.graylog2.org/)? It is central logging server that is expecting UDP based messages in a JSON format (GELF).
I'm hoping fo...
sirwinston
Jan 09, 2015Nimbostratus
I managed to get this working but forgot to share the result.
The iRule below works and sends access log type of information to Graylog using HSL. Information is send in the GELF format (JSON string). The result is that one can create nice dashboards based on HTTP status codes, response times etc.
when RULE_INIT {
set static::graylog_pool udp_graylog]
}
when CLIENT_ACCEPTED {
set hsl [HSL::open -proto UDP -pool $static::graylog_pool]
}
when HTTP_REQUEST {
set startTime [clock clicks -milliseconds]
set virtualHost [HTTP::host]
set protocol [HTTP::header "X-Forwarded-Proto"]
set xForwardedFor [HTTP::header "X-Forwarded-For"]
set path [HTTP::path]
set query [HTTP::query]
set method [HTTP::method]
set httpVersion [HTTP::version]
set correlationId [HTTP::cookie "correlation_id"]
set userAgent [regsub -all "\"" [HTTP::header "User-Agent"] "\\\""]
if { [HTTP::header Content-Length] ne "" } then {
set reqBytes [HTTP::header Content-Length]
} else {
set reqBytes 0
}
if { [HTTP::header "Referer"] ne "" } then {
set referer [regsub -all "\"" [HTTP::header "Referer"] "\\\""]
} else {
set referer -
}
}
when HTTP_RESPONSE {
set endTime [clock clicks -milliseconds]
set elapsed [expr {$endTime - $startTime}]
set backend [IP::server_addr]:[TCP::server_port]
set status [HTTP::status]
if { [HTTP::header Content-Length] ne "" } then {
set respBytes [HTTP::header Content-Length]
} else {
set respBytes 0
}
HSL::send $hsl "{\"version\": \"1.1\",\"host\":\"$virtualHost\",\"short_message\":\"$method $path $status\",\"level\":6,\"_facility\":\"F5_access_log\",\"_query\":\"$query\",\"_url\":\"$path\",\"_httpVersion\":\"$httpVersion\",\"_httpStatus\":$status,\"_method\":\"$method\",\"_protocol\":\"$protocol\",\"_referer\":\"$referer\",\"_userAgent\":\"$userAgent\",\"_x-forwarded-for\":\"$xForwardedFor\",\"_reqBytes\":$reqBytes,\"_respBytes\":$respBytes,\"_elapsed\":$elapsed,\"_correlationId\":\"$correlationId\"}"
}
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects