Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change message and state when logfile is not found #37

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

kurneko
Copy link

@kurneko kurneko commented Sep 6, 2019

If logfile is not found. This plugin return "OK - No matches found.".
I worry about if I wrong name in --logfile option. i will not notice it.

In check_log3.pl, if can not read logfile, return error.
https://github.com/pmcaulay/nagios-plugins/blob/master/check_log3.pl#L921-L934

** Proposal

If logfile is not found. Return code UNKNOWN, And message 「UNKNOWN: Logfile is not found.」

@kurneko
Copy link
Author

kurneko commented Sep 9, 2019

oh... travisCI errors.
This error is not relevant.

[python 2.6]

0.12s$ curl -sSf -o python-2.6.tar.bz2 ${archive_url}
curl: (22) The requested URL returned error: 404 Not Found
Unable to download 2.6 archive. The archive may not exist. Please consider a different version.

[python 2.7 ~ ]

======================================================================
FAIL: test_logfile (test_check_log_ng.LogCheckerTestCase)
--logfile option
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_check_log_ng.py", line 564, in test_logfile
    line1, self.logfile1, line2, self.logfile2))
AssertionError: u'WARNING: Found 2 lines (limit=1/0): Sep  6 09:32:41 hostname test: ERROR at /h [truncated]... != u'WARNING: Found 2 lines (limit=1/0): Sep  6 09:32:41 hostname test: ERROR at /h [truncated]...
Diff is 985 characters long. Set self.maxDiff to None to see it.
----------------------------------------------------------------------

@ttkzw
Copy link
Contributor

ttkzw commented Sep 9, 2019

I fixed the issue #38 which Travis CI failed.

@kurneko
Copy link
Author

kurneko commented Oct 1, 2019

thanks. travis-ci check was ok.

@netmarkjp
Copy link
Contributor

@kurneko Thanks for PR.

"If log file does not exist, return OK" is expected behavior.
This PR lead to unaccepatable breaking change to default behavior, I hope you to add arg/opt to switch behavior.
(ex: --ensure-file-exist , --error-no-exist )

@kurneko
Copy link
Author

kurneko commented Oct 26, 2019

@netmarkjp

Thank you for checking

This PR lead to unaccepatable breaking change to default behavior, I hope you to add arg/opt to switch behavior.

OK. Add --error-no-exist option.
please review.

check_log_ng.py Outdated
@@ -613,6 +613,10 @@ def _check_log(self, logfile, seekfile):
_debug("logfile='{0}', seekfile='{1}'".format(logfile, seekfile))
logfile = LogChecker.to_unicode(logfile)
if not os.path.exists(logfile):
# if set error_no_exist, return UNKNOWN.
if self.config['error_no_exist']:
self.message = "UNKNOWN: Logfile is not found."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to contain logfile path in output.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I modified to display logfile path.

check_log_ng.py Outdated

# if set error_no_exist, return UNKNOWN.
if self.config['error_no_exist'] and log_exist == False:
self.message = "UNKNOWN: Logfile is not found."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to contain logfile path in output.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I modified to display logfile path.

check_log_ng.py Outdated
@@ -696,6 +702,11 @@ def _check_log_multi(self, logfile_pattern, remove_seekfile=False, tag=''):
self._remove_old_seekfile_with_inode(logfile_pattern, tag)
else:
self._remove_old_seekfile(logfile_pattern, tag)

# if set error_no_exist, return UNKNOWN.
if self.config['error_no_exist'] and log_exist == False:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think == False ( and == True ) is not good expression.
and not log_exist is better.

In this context, I think the log_exist variable is unnecessary, "and not logfile_list" is enough.
( Evaluation of "list" returns false if len(list) == 0 )

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log_exist is removed. and use len(logfile_list) == 0

check_log_ng.py Outdated
action="store_true",
dest="error_no_exist",
default=False,
help=("If file not exist, return UNKNOWN error.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use one of "not found" or "not exist" in all messages.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Use only "not exist".

@ttkzw
Copy link
Contributor

ttkzw commented Oct 28, 2019

The variable name log_exist is ambiguous.
I think logfile_exists or logfile_exist is better.

@ttkzw
Copy link
Contributor

ttkzw commented Oct 28, 2019

I think the option name --error-no-exist and the variable name error_no_exist are ambiguous.
What does not exist?

@kurneko
Copy link
Author

kurneko commented Nov 10, 2019

The variable name log_exist is ambiguous.
I think logfile_exists or logfile_exist is better.

The variable "log_exist" has been removed.

@kurneko
Copy link
Author

kurneko commented Nov 10, 2019

I think the option name --error-no-exist and the variable name error_no_exist are ambiguous.
What does not exist?

You’re right. Change "--error-no-exist" to "--error-logfile-not-exist".

@ttkzw
Copy link
Contributor

ttkzw commented Aug 19, 2020

This looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants