Bug 1368089 - check_file_age broken
Summary: check_file_age broken
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: nagios-plugins
Version: 24
Hardware: Unspecified
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Nick Bebout
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-08-18 11:25 UTC by Mike Gerber
Modified: 2017-01-06 13:48 UTC (History)
11 users (show)

Fixed In Version: nagios-plugins-2.1.4-2.fc25 nagios-plugins-2.1.4-2.fc24 nagios-plugins-2.1.4-2.el6 nagios-plugins-2.1.4-2.el7
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2016-12-27 21:21:51 UTC


Attachments (Terms of Use)
Patch to 2.1.2 (1.17 KB, patch)
2016-08-18 11:47 UTC, Mike Gerber
no flags Details | Diff

Description Mike Gerber 2016-08-18 11:25:47 UTC
Description of problem:

Calling check_file_age is broken: 

# /usr/lib64/nagios/plugins/check_file_age 
Can't locate utils.pm in @INC (you may need to install the utils module) (@INC contains: . /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5) at /usr/lib64/nagios/plugins/check_file_age line 30.



Version-Release number of selected component (if applicable):

# rpm -q nagios-plugins-file_age 
nagios-plugins-file_age-2.1.1-1.fc24.x86_64

How reproducible:
Steps to Reproduce:

See above.

Additional info:

Upstream fix:

https://github.com/nagios-plugins/nagios-plugins/pull/106/commits/d46c3a8d263f2936fb79df3d02cd0f855dd94a13

Comment 1 Mike Gerber 2016-08-18 11:47:50 UTC
Created attachment 1191856 [details]
Patch to 2.1.2

An update to 2.1.2 fixes this. Proposed patch for the .spec attached.

Comment 2 Mike Gerber 2016-11-08 20:04:39 UTC
Any news on this? It's still broken.

Comment 3 Fedora Update System 2016-12-16 23:26:29 UTC
nagios-plugins-2.1.4-2.fc23 has been submitted as an update to Fedora 23. https://bodhi.fedoraproject.org/updates/FEDORA-2016-8ada3d2a1f

Comment 4 Fedora Update System 2016-12-16 23:27:00 UTC
nagios-plugins-2.1.4-2.el6 has been submitted as an update to Fedora EPEL 6. https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2016-dc9e470823

Comment 5 Fedora Update System 2016-12-16 23:27:19 UTC
nagios-plugins-2.1.4-2.fc25 has been submitted as an update to Fedora 25. https://bodhi.fedoraproject.org/updates/FEDORA-2016-f30fae0f67

Comment 6 Fedora Update System 2016-12-16 23:27:38 UTC
nagios-plugins-2.1.4-2.fc24 has been submitted as an update to Fedora 24. https://bodhi.fedoraproject.org/updates/FEDORA-2016-8586235698

Comment 7 Fedora Update System 2016-12-16 23:27:56 UTC
nagios-plugins-2.1.4-2.el7 has been submitted as an update to Fedora EPEL 7. https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2016-17165c490b

Comment 8 Fedora Update System 2016-12-19 01:51:28 UTC
nagios-plugins-2.1.4-2.el7 has been pushed to the Fedora EPEL 7 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2016-17165c490b

Comment 9 Fedora Update System 2016-12-19 02:28:12 UTC
nagios-plugins-2.1.4-2.fc23 has been pushed to the Fedora 23 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2016-8ada3d2a1f

Comment 10 Fedora Update System 2016-12-19 02:30:44 UTC
nagios-plugins-2.1.4-2.fc25 has been pushed to the Fedora 25 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2016-f30fae0f67

Comment 11 Fedora Update System 2016-12-19 19:18:09 UTC
nagios-plugins-2.1.4-2.el6 has been pushed to the Fedora EPEL 6 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2016-dc9e470823

Comment 12 Fedora Update System 2016-12-20 00:57:44 UTC
nagios-plugins-2.1.4-2.fc24 has been pushed to the Fedora 24 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2016-8586235698

Comment 13 Fedora Update System 2016-12-27 21:21:51 UTC
nagios-plugins-2.1.4-2.fc25 has been pushed to the Fedora 25 stable repository. If problems still persist, please make note of it in this bug report.

Comment 14 Fedora Update System 2016-12-27 22:48:01 UTC
nagios-plugins-2.1.4-2.fc24 has been pushed to the Fedora 24 stable repository. If problems still persist, please make note of it in this bug report.

Comment 15 Fedora Update System 2017-01-03 17:49:15 UTC
nagios-plugins-2.1.4-2.el6 has been pushed to the Fedora EPEL 6 stable repository. If problems still persist, please make note of it in this bug report.

Comment 16 Fedora Update System 2017-01-03 17:51:41 UTC
nagios-plugins-2.1.4-2.el7 has been pushed to the Fedora EPEL 7 stable repository. If problems still persist, please make note of it in this bug report.

Comment 17 xsoft 2017-01-04 02:32:35 UTC
Please kindly note that nagios-plugins-2.1.4-2.el6 is BROKEN.
Just try to crate a dummy file ( > test.ok ) and test it. You will get File not found, CRIT. error.

(I'm fixing this for 2h now, thats to all auto-appliend ERATAs, 12 serveers done, 5 to go)

---

# ls -al /usr/lib64/nagios/plugins/check_file_age
-rwxr-xr-x. 1 root root 3843 Dec 17 00:09 /usr/lib64/nagios/plugins/check_file_age
# grep "print_revision" /usr/lib64/nagios/plugins/check_file_age
        print_revision($PROGNAME, '2.1.4');

# > test.ok
# ls test.ok
test.ok

# /usr/lib64/nagios/plugins/check_file_age -c 0 -w 0 -f ./test.ok
FILE_AGE CRITICAL: File not found - "./test.ok"

Comment 18 Steven Schlegel 2017-01-04 07:31:27 UTC
I am facing the same issue like "xsoft" told before. Last night the package "nagios-plugins-file_age" was updated to version "2.1.4-2.el6.x86_64". Now the Service-Check is broken in Nagios.

Nagios-Output:
Status Information:	CRIT - FILE_AGE CRITICAL: File not found - "/var/lib/puppet/state/last_run_report.yaml"

File does exist:
ls -la /var/lib/puppet/state/last_run_report.yaml
=>
-rw-r----- 1 root root 407130 Jan  4 08:08 /var/lib/puppet/state/last_run_report.yaml

Check should return: OK


Steps to reproduce:
touch /var/tmp/steven.txt

ls -la /var/tmp/steven.txt
=>
-rw-r--r-- 1 root root 0 Jan  4 08:22 /var/tmp/steven.txt

/usr/lib64/nagios/plugins/check_file_age -f "/var/lib/puppet/state/last_run_report.yaml"
=>
FILE_AGE CRITICAL: File not found - "/var/lib/puppet/state/last_run_report.yaml"


Regards,
Steven

Comment 19 Steven Schlegel 2017-01-04 08:29:54 UTC
(In reply to Steven Schlegel from comment #18)
> I am facing the same issue like "xsoft" told before. Last night the package
> "nagios-plugins-file_age" was updated to version "2.1.4-2.el6.x86_64". Now
> the Service-Check is broken in Nagios.
> 
> Nagios-Output:
> Status Information:	CRIT - FILE_AGE CRITICAL: File not found -
> "/var/lib/puppet/state/last_run_report.yaml"
> 
> File does exist:
> ls -la /var/lib/puppet/state/last_run_report.yaml
> =>
> -rw-r----- 1 root root 407130 Jan  4 08:08
> /var/lib/puppet/state/last_run_report.yaml
> 
> Check should return: OK
> 
> 
> Steps to reproduce:
> touch /var/tmp/steven.txt
> 
> ls -la /var/tmp/steven.txt
> =>
> -rw-r--r-- 1 root root 0 Jan  4 08:22 /var/tmp/steven.txt
> 
> /usr/lib64/nagios/plugins/check_file_age -f
> "/var/lib/puppet/state/last_run_report.yaml"
> =>
> FILE_AGE CRITICAL: File not found -
> "/var/lib/puppet/state/last_run_report.yaml"
> 
> 
> Regards,
> Steven

Steps to reproduce (fixed typo):
touch /var/tmp/steven.txt

ls -la /var/tmp/steven.txt
=>
-rw-r--r-- 1 root root 0 Jan  4 08:22 /var/tmp/steven.txt

/usr/lib64/nagios/plugins/check_file_age -f "/var/tmp/steven.txt"
=>
FILE_AGE CRITICAL: File not found -"/var/tmp/steven.txt"

Comment 20 Steven Schlegel 2017-01-04 09:10:34 UTC
I found out that the filename contains another char at the beginning and on the end:
# /usr/lib64/nagios/plugins/check_file_age -w 7200 -c 10800 /var/tmp/steven.txt 
=>
$VAR1 = '"/var/tmp/steven.txt"';
FILE_AGE CRITICAL: File not found - "/var/tmp/steven.txt"

So I made a quick change to the script (cut off all quotation marks from $filename):
[...]
foreach $filename (@filelist) {
        print Dumper($filename);
        $filename =~ s/"//g;
        print Dumper($filename);

        unless (-e $filename) {
[...]
}

After running the script again, the output changed from CRITICAL to OK:
# /usr/lib64/nagios/plugins/check_file_age -w 7200 -c 10800 /var/tmp/steven.txt 
=>
$VAR1 = '"/var/tmp/steven.txt"'; <--- before regex (print Dumper)
$VAR1 = '/var/tmp/steven.txt'; <--- after regex (print Dumper)
FILE_AGE OK: /var/tmp/steven.txt is 5 seconds old and 0 bytes  | age=5s;7200;10800 size=0B;0;0;0

I think the quotation mark (") is used as a part of the filename, so I would suggest to include a regex to remove that char from $filename.

Regards,
Steven

Comment 21 Kent Engström 2017-01-04 09:19:56 UTC
(In reply to Steven Schlegel from comment #20)
> I found out that the filename contains another char at the beginning and on
> the end:
...
> FILE_AGE CRITICAL: File not found - "/var/tmp/steven.txt"

The quotations marks seems to be added quite deliberately in the code:

--- begin code snippet ---
$opt_f = shift unless ($opt_f);

if (! $opt_f) {
        print "FILE_AGE UNKNOWN: No file specified\n";
        exit $ERRORS{'UNKNOWN'};
}

$opt_f = '"' . $opt_f . '"';
--- end code snippet ---

So removing the line at the end of the code snippet above should work, but before doing that it would be interesting to know why it was added in the first place...

Comment 22 xsoft 2017-01-04 09:22:44 UTC
Easy fix (bad escaping, white space)

# diff check_file_age check_file_age.working
80c80
< #$opt_f = '"' . $opt_f . '"';
---
> $opt_f = '"' . $opt_f . '"';

Comment 23 jan horacek 2017-01-04 09:24:39 UTC
i think this bug is not related to this specific bug, but anyway, quickfix is:

[root@anr ~]# diff check_file_age check_file_age.fixed
80c80
< #$opt_f = '"' . $opt_f . '"';
---
> $opt_f = '"' . $opt_f . '"';

Comment 24 Steven Schlegel 2017-01-06 07:48:28 UTC
(In reply to Kent Engström from comment #21)
> (In reply to Steven Schlegel from comment #20)
> > I found out that the filename contains another char at the beginning and on
> > the end:
> ...
> > FILE_AGE CRITICAL: File not found - "/var/tmp/steven.txt"
> 
> The quotations marks seems to be added quite deliberately in the code:
> 
> --- begin code snippet ---
> $opt_f = shift unless ($opt_f);
> 
> if (! $opt_f) {
>         print "FILE_AGE UNKNOWN: No file specified\n";
>         exit $ERRORS{'UNKNOWN'};
> }
> 
> $opt_f = '"' . $opt_f . '"';
> --- end code snippet ---
> 
> So removing the line at the end of the code snippet above should work, but
> before doing that it would be interesting to know why it was added in the
> first place...

When using "glob", perl needs double-quotes around the filename.

See: http://perldoc.perl.org/functions/glob.html
Quotation --->
"Note that glob splits its arguments on whitespace and treats each segment as separate pattern."
<--- Quotation

So removing / uncommenting the line "$opt_f = '"' . $opt_f . '"';" is not an option to me, because it breaks / splits the filename at every whitespace:

touch Steven\ Test.txt
ls -la Steven\ Test.txt
=>
-rw-r--r-- 1 root root 0  6. Jan 08:01 Steven Test.txt

/usr/lib64/nagios/plugins/check_file_age -f /root/Steven\ Test.txt 
=>
FILE_AGE CRITICAL: File not found - /root/Steven


So I made the following changes to check_file_age to be able to check files with whitespaces and without:

--- begin code snippet ---
$opt_f = '"' . $opt_f . '"';

# Check that file(s) exists (can be directory or link)
$perfdata = "";
$output = "";
@filelist = glob($opt_f);

foreach $filename (@filelist) {
        if ($filename !~ /^\./i) {
                $filename =~ s/"//g;
        }
        unless (-e $filename) {
--- end code snippet ---

If $filename contains a whitespace in it's name, then we want to keep double-quotes around it. If $filename does not have any whitespace in it's name, then we trim off all double-quotes.

Test with whitespace:
/usr/lib64/nagios/plugins/check_file_age -f /root/Steven\ Test.txt
=>
FILE_AGE OK: /root/Steven Test.txt is 11 seconds old and 0 bytes  | age=11s;240;600 size=0B;0;0;0

Test without whitespace:
/usr/lib64/nagios/plugins/check_file_age -f /root/mysql_install.log
=>
FILE_AGE OK: /root/mysql_install.log is 15 seconds old and 32187 bytes  | age=15s;240;600 size=32187B;0;0;0

I am not an expert, I just want to share my thoughts with you. ;)


diff /home/sschlegel/check_file_age /home/sschlegel/check_file_age.fixed 
87a88,90
> 	if ($filename !~ /^\./i) {
> 		$filename =~ s/"//g;
> 	}
115d117
<

I think we should create another bug-ticket, because it's not related to this one (like "jan horacek" said).

Regards,
Steven

Comment 25 Scott Wilkerson 2017-01-06 13:48:41 UTC
There already is another bug roport already filed for the current problem
https://bugzilla.redhat.com/show_bug.cgi?id=1410039

Upstreams fix is almost identical to what "Steven Schlegel" proposed


Note You need to log in before you can comment on or make changes to this bug.