Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Sébastien Luttringer
infrastructure
Commits
7ea5243b
Verified
Commit
7ea5243b
authored
Apr 26, 2018
by
Florian Pritz
Browse files
nginx-zabbix: Filter hosts to prevent discovery from adding bogus data
Signed-off-by:
Florian Pritz
<
bluewind@xinu.at
>
parent
04e1f8ea
Changes
1
Hide whitespace changes
Inline
Side-by-side
roles/zabbix-agent/files/nginx-zabbix.pl
View file @
7ea5243b
...
...
@@ -14,6 +14,7 @@ use Time::HiRes qw(time sleep);
my
$interval
=
30
;
my
$devmode
=
0
;
my
@nginx_log_file_paths
=
glob
("
/var/log/nginx/*-access.log /var/log/nginx/*/access.log
");
my
$hostname_regex
=
qr/^.*(archlinux\.org|pkgbuild\.com)$/
;
@nginx_log_file_paths
=
("
./test-access.log
")
if
$devmode
;
...
...
@@ -84,7 +85,10 @@ sub main {
$line
=
trim
(
$line
);
if
(
$line
=~
m/(?<remote_addr>\S+) (?<host>\S+) (?<remote_user>\S+) \[(?<time_local>.*?)\]\s+"(?<request>.*?)" (?<status>\S+) (?<body_bytes_sent>\S+) "(?<http_referer>.*?)" "(?<http_user_agent>.*?)" "(?<http_x_forwarded_for>\S+)"(?: (?<request_time>[\d\.]+|-))?/
)
{
my
$host
=
$+
{
host
};
my
%val
=
%+
;
my
$host
=
$val
{
host
};
next
unless
$host
=~
m/$hostname_regex/
;
if
(
not
defined
$values_per_host
->
{
$host
})
{
$values_per_host
->
{
$host
}
=
clone
(
$value_template
);
...
...
@@ -95,11 +99,11 @@ sub main {
my
$stat
=
$stat_per_host
->
{
$host
};
my
$values
=
$values_per_host
->
{
$host
};
$stat
->
add_data
(
$
+
{
request_time
})
if
$
+
{
request_time
}
!=
0
;
$stat
->
add_data
(
$
val
{
request_time
})
if
$
val
{
request_time
}
!=
0
;
$values
->
{
request_count
}
++
;
$values
->
{
cached_request_count
}
++
if
$
+
{
request_time
}
==
0
;
$values
->
{
cached_request_count
}
++
if
$
val
{
request_time
}
==
0
;
my
$status_key
=
defined
$values
->
{
status
}
->
{
$
+
{
status
}}
?
$
+
{
status
}
:
"
other
";
my
$status_key
=
defined
$values
->
{
status
}
->
{
$
val
{
status
}}
?
$
val
{
status
}
:
"
other
";
$values
->
{
status
}
->
{
$status_key
}
++
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment