mirror of https://github.com/mikaku/Monitorix.git
included also the log_file option of the HTTP built-in in this new support #268
This commit is contained in:
parent
48ac929191
commit
30c2e2bfb9
|
@ -1,7 +1,7 @@
|
|||
#
|
||||
# Monitorix - A lightweight system monitoring tool.
|
||||
#
|
||||
# Copyright (C) 2005-2016 by Jordi Sanfeliu <jordi@fibranet.cat>
|
||||
# Copyright (C) 2005-2020 by Jordi Sanfeliu <jordi@fibranet.cat>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
@ -32,21 +32,37 @@ use Socket;
|
|||
sub logger {
|
||||
my ($url, $type) = @_;
|
||||
|
||||
if(open(OUT, ">> $main::config{httpd_builtin}->{log_file}")) {
|
||||
if($type eq "OK") {
|
||||
print OUT localtime() . " - $type - [$ENV{REMOTE_ADDR}] \"$ENV{REQUEST_METHOD} $url - " . ($ENV{HTTP_USER_AGENT} || "") . "\"\n";
|
||||
} elsif($type eq "NOTEXIST") {
|
||||
print OUT localtime() . " - $type - [$ENV{REMOTE_ADDR}] File does not exist: $url\n";
|
||||
} elsif($type eq "AUTHERR") {
|
||||
print OUT localtime() . " - $type - [$ENV{REMOTE_ADDR}] Authentication error: $url\n";
|
||||
} elsif($type eq "NOTALLOWED") {
|
||||
print OUT localtime() . " - $type - [$ENV{REMOTE_ADDR}] Access not allowed: $url\n";
|
||||
if($main::config{httpd_builtin}->{log_file}) {
|
||||
if(open(OUT, ">> $main::config{httpd_builtin}->{log_file}")) {
|
||||
if($type eq "OK") {
|
||||
print OUT localtime() . " - $type - [$ENV{REMOTE_ADDR}] \"$ENV{REQUEST_METHOD} $url - " . ($ENV{HTTP_USER_AGENT} || "") . "\"\n";
|
||||
} elsif($type eq "NOTEXIST") {
|
||||
print OUT localtime() . " - $type - [$ENV{REMOTE_ADDR}] File does not exist: $url\n";
|
||||
} elsif($type eq "AUTHERR") {
|
||||
print OUT localtime() . " - $type - [$ENV{REMOTE_ADDR}] Authentication error: $url\n";
|
||||
} elsif($type eq "NOTALLOWED") {
|
||||
print OUT localtime() . " - $type - [$ENV{REMOTE_ADDR}] Access not allowed: $url\n";
|
||||
} else {
|
||||
print OUT localtime() . " - $type - [$ENV{REMOTE_ADDR}] $url\n";
|
||||
}
|
||||
close(OUT);
|
||||
} else {
|
||||
print OUT localtime() . " - $type - [$ENV{REMOTE_ADDR}] $url\n";
|
||||
print STDERR localtime() . " - ERROR: unable to open logfile '$main::config{httpd_builtin}->{log_file}'.\n";
|
||||
}
|
||||
close(OUT);
|
||||
} else {
|
||||
print STDERR localtime() . " - ERROR: unable to open logfile '$main::config{httpd_builtin}->{log_file}'.\n";
|
||||
my $msg;
|
||||
if($type eq "OK") {
|
||||
$msg = localtime() . " - $type - [$ENV{REMOTE_ADDR}] \"$ENV{REQUEST_METHOD} $url - " . ($ENV{HTTP_USER_AGENT} || "") . "\"\n";
|
||||
} elsif($type eq "NOTEXIST") {
|
||||
$msg = localtime() . " - $type - [$ENV{REMOTE_ADDR}] File does not exist: $url\n";
|
||||
} elsif($type eq "AUTHERR") {
|
||||
$msg = localtime() . " - $type - [$ENV{REMOTE_ADDR}] Authentication error: $url\n";
|
||||
} elsif($type eq "NOTALLOWED") {
|
||||
$msg = localtime() . " - $type - [$ENV{REMOTE_ADDR}] Access not allowed: $url\n";
|
||||
} else {
|
||||
$msg = localtime() . " - $type - [$ENV{REMOTE_ADDR}] $url\n";
|
||||
}
|
||||
print("$msg");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -130,10 +130,12 @@ sub httpd_setup {
|
|||
}
|
||||
|
||||
# create the HTTPd logfile
|
||||
open(OUT, ">> " . $config->{httpd_builtin}->{log_file});
|
||||
close(OUT);
|
||||
chown($uid, $gid, $config->{httpd_builtin}->{log_file});
|
||||
chmod(0600, $config->{httpd_builtin}->{log_file});
|
||||
if($config->{log_file}) {
|
||||
open(OUT, ">> " . $config->{httpd_builtin}->{log_file});
|
||||
close(OUT);
|
||||
chown($uid, $gid, $config->{httpd_builtin}->{log_file});
|
||||
chmod(0600, $config->{httpd_builtin}->{log_file});
|
||||
}
|
||||
|
||||
setgid($gid);
|
||||
if(getgid() != $gid) {
|
||||
|
|
Loading…
Reference in New Issue