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

Fixes #39 - raise warning on unread mails #56

Conversation

kgaikwad
Copy link
Member

No description provided.

attr_reader :file_path

def initialize
@file_path = '/var/spool/mail/root'
Copy link
Member

Choose a reason for hiding this comment

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

Would it be feasible to retrieve mail spool path from site-specific configuration file /etc/login.defs? This file defines the default path for MAIL_DIR, and its value differs based on distro.

On Fedora*

[anurag@coruscant ~]$ cat /etc/redhat-release 
Fedora release 25 (Twenty Five)
[anurag@coruscant ~]$ grep ^MAIL_DIR /etc/login.defs 
MAIL_DIR	/var/spool/mail
[anurag@coruscant ~]$ 

On Debian*

anurag@ellen:~$ cat /etc/debian_version 
wheezy/sid
anurag@ellen:~$ grep ^MAIL_DIR /etc/login.defs 
MAIL_DIR        /var/mail
anurag@ellen:~$ 

You may want to retain the default value of /var/spool/mail/root and fallback to it if the above queries fail.

Copy link
Member Author

Choose a reason for hiding this comment

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

@gnurag,
Thank you for providing information.
I will go through it and fix the code as per your suggestions.

Copy link
Member Author

Choose a reason for hiding this comment

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

@gnurag ,
Done with the suggested changes.
Instead of hard-coded path, value of MAIL_DIR is set as a mailbox path.
This value of MAIL_DIR is retrieved from config file /etc/login.defs .

Copy link
Member

Choose a reason for hiding this comment

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

LGTM.

end

def number_of_mails_present
cmd = "egrep '^Message-Id' #{file_path} | wc -l"
Copy link
Member

Choose a reason for hiding this comment

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

egrep --count can provide a count of matching lines, without passing the output to wc for counting.

@kgaikwad kgaikwad force-pushed the 39_check_if_root_having_unread_mails branch 2 times, most recently from a77cbac to 30e445b Compare April 26, 2017 10:59
@kgaikwad kgaikwad force-pushed the 39_check_if_root_having_unread_mails branch 2 times, most recently from f5cc6bd to 970843c Compare May 4, 2017 08:27
def guidline_steps
<<-EOF
Please follow steps manually to clear root mailbox i.e #{file_path}:
1) To read mails use vim or cat for mailbox file
Copy link
Member

Choose a reason for hiding this comment

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

What about defining this steps into procedures/system_mailbox and linking to them from the check
in assertion: this would be really nice user experience, if we listed the file for them, as well as allowed them
to delete that file.

@kgaikwad kgaikwad force-pushed the 39_check_if_root_having_unread_mails branch 2 times, most recently from 2d8143e to b22f01f Compare June 29, 2017 07:17
@kgaikwad
Copy link
Member Author

@iNecas, @gnurag, @swapab,
Done with the suggested changes. Ready for review.

  • Converted manual text steps to view & delete unread mail list to procedures
  • Added error_type key in options for method assert. So that instead of fail, we can pass and print other error types too.

@swapab
Copy link
Member

swapab commented Jun 29, 2017

I think, there should be a mail feature. And check should be for any new mail?.
It would be a structural change with all the check logic moving to mail feature and call feature(:mail).new_mail? from the check.

@kgaikwad kgaikwad force-pushed the 39_check_if_root_having_unread_mails branch from b22f01f to cab5e4c Compare June 29, 2017 12:17
@kgaikwad
Copy link
Member Author

@swapab,
I don't think to create mail as feature would be needed here.
There will be very less chance where future tasks will be related to system mails.
Due to this reason only I have not created mail as feature separately.

If you still think, this change should be needed, please let me know.
I will do modifications and update PR.


def run
if file_exists?(file_path)
mails_count = find_mails_count.to_i
Copy link
Member

Choose a reason for hiding this comment

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

can move to_i to the method itself.
Method name can be mails_count.

@swapab
Copy link
Member

swapab commented Jul 4, 2017

can keep the check as is. we'll introduce mail feature when firm use-case arrives.

@kgaikwad kgaikwad force-pushed the 39_check_if_root_having_unread_mails branch from cab5e4c to aa80b53 Compare July 5, 2017 05:02
@kgaikwad
Copy link
Member Author

kgaikwad commented Jul 5, 2017

Ready for review.
As I am not using any mail client package and there is no any info about any mail which says it is unread,
I am showing all mails count from file /var/spool/mail/root .

@@ -15,18 +15,14 @@ class Check < Executable
# the failure, will be offered to the user when running
# in interactive mode
#
# * +:warn* - issue warning instead of failure: this is less strict check,
# that could be considered as non-critical for continuing with the scenario
# * +:error_type* - error type if wants to override failure
Copy link
Member Author

Choose a reason for hiding this comment

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

@iNecas , @swapab
Here, I have replaced :warn option to :error_type.
Using this option, we can raise warning or any other error_type of exceptions.

@kgaikwad
Copy link
Member Author

@iNecas ,
Resolved conflicts.

@swapab
Copy link
Member

swapab commented Sep 8, 2017

@kgaikwad I tried this on my local setup.

# ./bin/foreman-maintain health check
Running ForemanMaintain::Scenario::FilteredScenario
================================================================================
Check for verifying syntax for ISP DHCP configurations:         
Not Found 404. Response: ""
              [FAIL]
Please check and verify DHCP configurations.
--------------------------------------------------------------------------------
check for paused tasks:                                               [OK]
--------------------------------------------------------------------------------
Check for mails in root's mailbox.:                                   [WARNING]
WARNING: Found 20 mail(s) in root's mailbox.
--------------------------------------------------------------------------------
There are multiple steps to proceed:
1) list mails from root's mailbox ({:file_path=>#<ForemanMaintain::Param:0x0000000194d8c8 @name=:file_path, @description="", @options={}, @required=false, @flag=false, @block=nil, @array=false>})
2) clear root's mailbox ({:file_path=>#<ForemanMaintain::Param:0x0000000194fbc8 @name=:file_path, @description="", @options={}, @required=false, @flag=false, @block=nil, @array=false>})
Select step to continue, [n(next), q(quit)] q
Scenario [ForemanMaintain::Scenario::FilteredScenario] failed. 

I think the key :file_path should have a String as value instead of ForemanMaintain::Param object.

@kgaikwad kgaikwad force-pushed the 39_check_if_root_having_unread_mails branch from 0c6ad0c to 9b26a52 Compare September 8, 2017 12:37
@kgaikwad
Copy link
Member Author

kgaikwad commented Sep 8, 2017

@swapab ,
I guess something is broken in my code due to new changes, I will check on this.

@kgaikwad kgaikwad force-pushed the 39_check_if_root_having_unread_mails branch from 9b26a52 to ba5a302 Compare September 12, 2017 12:12
@kgaikwad
Copy link
Member Author

@swapab ,

Sorry for confusion nothing is broken so far :-)
This param list shown along with procedure's description due to method runtime_message

I have overridden this method in both procedures. Now, it will show only procedure's description for this check.

@kgaikwad kgaikwad force-pushed the 39_check_if_root_having_unread_mails branch from ba5a302 to ad0adb8 Compare September 12, 2017 15:58
@kgaikwad
Copy link
Member Author

@swapab ,

Reverted the previous changes as fixed in PR-97.

@kgaikwad kgaikwad force-pushed the 39_check_if_root_having_unread_mails branch from ad0adb8 to fee376e Compare September 13, 2017 10:44
@kgaikwad
Copy link
Member Author

Pulled new changes from master and updated the PR.

@ntkathole
Copy link
Contributor

@kgaikwad Testing against satellite 6.3 on RHEL 7 gives some error on my setup

./bin/foreman-maintain advanced procedure run system-mailbox-clear-mailbox
Running ForemanMaintain::Scenario
================================================================================
clear root's mailbox:
/ clearing all existing mailssh: -c: line 0: syntax error near unexpected token `2'
sh: -c: line 0: `cat /dev/null >  2>&1'
                                         [OK]
--------------------------------------------------------------------------------

and also running system-mailbox-list-mailbox stucked (never ends)

./bin/foreman-maintain advanced procedure run system-mailbox-list-mailbox
Running ForemanMaintain::Scenario
================================================================================
list mails from root's mailbox:

@theforeman-bot
Copy link
Member

@kgaikwad, the Redmine ticket used is for a different project than the one associated with this GitHub repository. Please either:

If changing the ticket number used, remember to update the PR title and the commit message (using git commit --amend).


This message was auto-generated by Foreman's prprocessor

@sean797
Copy link
Member

sean797 commented Mar 16, 2018

Whats the motivation behind this? Can we at least add it to the commit message please.

@kgaikwad kgaikwad force-pushed the 39_check_if_root_having_unread_mails branch 2 times, most recently from 0679740 to 9b8e044 Compare March 16, 2018 19:12
@kgaikwad
Copy link
Member Author

@sean797, updated the commit message.

@ntkathole , added advanced_run metadata to above procedures and updated the pull-request.

metadata do
label :unread_mail
description "Check for mails in root's mailbox."
tags :unread_mail
Copy link
Contributor

Choose a reason for hiding this comment

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

@kgaikwad We are tagging this check with unread_mail...Currently this check won't run before upgrade unless user run it explicitly ( foreman-maintain health check --label unread-mail ). So I think to this need to add in scenario definitions https://github.com/theforeman/foreman_maintain/blob/master/definitions/scenarios/upgrade_to_satellite_6_3.rb#L23

add_step(Checks:::UnreadMail.new)

Copy link
Member Author

Choose a reason for hiding this comment

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

@ntkathole ,
It's not intended to be a pre/post upgrade checks. That's why tagged as unread_mail so that any user can run it explicitly whenever required.

end

private

Copy link
Member

Choose a reason for hiding this comment

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

@kgaikwad, would it make sense to make file_path and mailbox_dir lazy so that they are evaluated during the run instead of initialization? I see two advantages there:

  • it takes time during scenario execution when there is already something printed out and scenario can start quicker
  • if (hypothetically) if file_path is subject of change in some of the previous steps we won't notice

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, make sense! And advantages mentioned are legit.
I will do modifications as suggested.

We have many crons, they end up in root mail folder
(or file technically). With this commit it will check for
unread mails from root's mailbox.
If unread mails, provide steps to list & clear mailbox.
@kgaikwad kgaikwad force-pushed the 39_check_if_root_having_unread_mails branch from 9b8e044 to 7030fcf Compare April 20, 2018 11:04
@kgaikwad
Copy link
Member Author

@mbacovsky, @ntkathole,
Updated the pull-request as per suggested changes.

@ntkathole
Copy link
Contributor

Looks good!

Copy link
Member

@iNecas iNecas left a comment

Choose a reason for hiding this comment

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

Approved: @mbacovsky feel free to merge unless any more comments.

@sean797
Copy link
Member

sean797 commented Jun 12, 2018

Whats the motivation behind this? I did ask already but it seems the commit message was updated telling me what this commit does (which is useful 👍 ) but the motivation behind why we are doing it would be nice.

Right now, I'm thinking why the hell would we want to warn users about unread mails in root's mailbox!!?

from man cron "When executing commands, any output is mailed to the owner" this means foreman-maintain is going to warn users that they have cronjobs ran that produced output, I'm wondering why that is useful?

@kgaikwad
Copy link
Member Author

@sean797,
Initially, this check was suggested by @lzap so he can provide better insights.

@lzap
Copy link
Member

lzap commented Jun 13, 2018

I think I was brainstorming but the original ticket is no longer accessible probably because folks disabled issues in this repo - don't know the details. I guess it won't hurt to warn user, but the amount of code written to do one-line check is just worrisome :-) If anyone told me in advance we are gonna deliver 100 lines of code for this, I'd say: please no, just close the idea.

@upadhyeammit
Copy link
Contributor

As per the recent comment of @lzap and @sean797 I am closing this pr.

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

Successfully merging this pull request may close these issues.

None yet

10 participants