Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Shared procedures
- # Contact Tim Riker <[email protected]> for changes
- proc resetforwardhost {} {
- if {[HTTP::header exists X-Forwarded-Host]}{
- HTTP::header remove X-Forwarded-Host
- }
- HTTP::header insert X-Forwarded-Host [HTTP::host]
- }
- proc loglist {mylog} {
- upvar 1 $mylog log
- set list {}
- foreach key [lsort [array names log]] {
- if { ($log($key) contains " ") } {
- lappend list "$key=\"$log($key)\""
- } else {
- lappend list "$key=$log($key)"
- }
- }
- return $list
- }
- proc hsllog {mylog {hslname "hslname"} {hslpool "pool_splunk-syslog_lb"}} {
- upvar 1 $mylog log
- # https://tools.ietf.org/html/rfc5424 <local0.info>version rfc-3339time host procid msgid structured_data log
- set time [clock clicks -milliseconds]
- set output "<134>1 [clock format [string range $time 0 end-3] -gmt 1 -format %Y-%m-%dT%H:%M:%S.[string range $time end-2 end]+00:00] [getfield [info hostname] "." 1] $hslname [TMM::cmp_group].[TMM::cmp_unit] - "
- append output [join [call /Common/proc::loglist log] " "]
- HSL::send [HSL::open -proto UDP -pool $hslpool] $output
- }
- proc errorpage {code mylog {title ""} {erroruri ""} {page "/Common/error.html"}} {
- upvar 1 $mylog log
- if { $title == "" } {
- set title $log(reason)
- }
- if { $erroruri == "" } {
- catch { set erroruri "https://${log(http_host)}${log(http_uri)}" }
- }
- set text [join [call /Common/proc::loglist log] "<br>"]
- set error_page [string map [list TITLE "$title" ERRORURI "[URI::encode $erroruri]" TEXT $text] [ifile get $page]]
- HTTP::respond $code content $error_page "Content-Type" "text/html; charset=utf-8" Virtual-Name [virtual name] Connection close
- event disable
- return
- }
- proc whitelist {datagroup {hslpool "pool_splunk-syslog_lb"}} {
- if { not [class match [IP::client_addr] equals $datagroup] } {
- set log(virtual_name) "[virtual name]"
- set log(datagroup) $datagroup
- set log(reason) "Not Available"
- set log(client_addr) [IP::client_addr]
- set log(client_port) [TCP::client_port]
- set log(http_host) [HTTP::host]
- set log(http_uri) [HTTP::uri]
- set log(virtual_name) [virtual name]
- call /Common/proc::hsllog log whitelist $hslpool
- call /Common/proc::errorpage 403 log
- }
- }
- proc blacklist {datagroup {hslpool "pool_splunk-syslog_lb"}} {
- if { [class match [IP::client_addr] equals $datagroup] } {
- set log(virtual_name) "[virtual name]"
- set log(datagroup) $datagroup
- set log(reason) "Not Available"
- set log(client_addr) [IP::client_addr]
- set log(client_port) [TCP::client_port]
- set log(http_host) [HTTP::host]
- set log(http_uri) [HTTP::uri]
- set log(virtual_name) [virtual name]
- call /Common/proc::hsllog log blacklist $hslpool
- call /Common/proc::errorpage 403 log
- }
- }
Add Comment
Please, Sign In to add comment