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

How to use check_mailbox with icinga2 #1

Closed
aspryne opened this issue Apr 9, 2019 · 16 comments
Closed

How to use check_mailbox with icinga2 #1

aspryne opened this issue Apr 9, 2019 · 16 comments

Comments

@aspryne
Copy link

aspryne commented Apr 9, 2019

Hi,

I have a stupid problem, but i don't understand how can I use this script with icingaweb2.
I juste want to watch the total number of my mail from my mailbox on icigaweb2.
i just have to modify command.conf ? or service.conf too ? or anything else.

thanks for your help

@aspryne aspryne changed the title How use check_mailbox with icinga2 How to use check_mailbox with icinga2 Apr 9, 2019
@ozzi-
Copy link
Owner

ozzi- commented Apr 9, 2019

Hi aspryne

First, download the newest version and save it under /etc/icinga2/scripts , get the script from https://raw.githubusercontent.com/ozzi-/check_mailbox/master/check_mailbox.sh

Then edit /etc/icinga2/conf.d/commands.sh and add:

object CheckCommand "check-mailbox" {
  command = [ ConfigDir + "/scripts/check_mailbox.sh" ]
  arguments += {
    "-H" = "$chm_host$"
    "-C" = "$chm_credential$"
    "-M" = "INBOX"
    "-w" = "1000"
    "-c" = "2000"
  }
}

Now edit /etc/icinga2/conf.d/hosts.conf

object Host "my mailbox server" {
  check_command = "ping4"
  address = "192.168.1.10"
}

Now edit /etc/icinga2/conf.d/services.conf

apply Service "mailboxserver imap" {
  check_command = "check-mailbox"
  vars.chm_host = "imap://192.168.1.10:143"
  vars.chm_credential = "username:password"
  assign where host.name == "my mailbox server"
}

Now you will see performance data in the servide "mailboxserver imap".
If you don't want to use a service (not recommended):

object Host "my mailbox server" {
  check_command = "check-mailbox"
  vars.chm_host = "imap://192.168.1.10:143"
  vars.chm_credential = "username:password"
}

let me know if you need any further info

@aspryne
Copy link
Author

aspryne commented Apr 9, 2019 via email

@ozzi-
Copy link
Owner

ozzi- commented Apr 9, 2019

Why this configuration is necessary ? Its just to verify the server disponibility ?
Yes, as this is common practise. Otherwise use this directly:

object Host "my mailbox server" {
  check_command = "check-mailbox"
  vars.chm_host = "imap://192.168.1.10:143"
  vars.chm_credential = "username:password"
}

Concerning the connection string, check this for reference:
https://support.office.com/en-us/article/pop-and-imap-email-settings-for-outlook-8361e398-8af4-4e97-b147-6c6c4ac95353

Port 993 is correct but it requires TLS (transport encryption) so use imaps:// instead of imap:// (s stands for secure).

Conerning your username, yes thats it.

In order to see anything on icingaweb, reload the icinga service as such:

sudo service icinga2 restart

For further questions I suggest you go check https://community.icinga.com/

@aspryne
Copy link
Author

aspryne commented Apr 10, 2019 via email

@ozzi-
Copy link
Owner

ozzi- commented Apr 11, 2019

Hi

What does your service.conf say?

  assign where host.name == "REPLACE THIS WITH the hostname"

@aspryne
Copy link
Author

aspryne commented Apr 11, 2019 via email

@ozzi-
Copy link
Owner

ozzi- commented Apr 11, 2019

The config provided above works for me. Try putting all together into one conf file.

@aspryne
Copy link
Author

aspryne commented Apr 11, 2019 via email

@ozzi-
Copy link
Owner

ozzi- commented Apr 11, 2019

Don't worry, we / you will figure it out ;)

Icinga , per defaults, reads all *.conf files in the folder conf.d. Go check /etc/icinga2/icinga2.conf. The last line says:

. . . 
include_recursive "conf.d"

Icinga does not care if you mix hosts and services etc. its just for keeping everything tidy.
You can name your file "blub.conf" it does not matter.

This is working for me (I added '2' to the service name as i have defined it somewhere else already):

root@monitoring:/etc/icinga2/conf.d# cat test.conf 
apply Service "check-mailbox2" {
 check_command = "check-mailbox2" 
 vars.chm_host = "imaps://outlook.office365.com:993" 
 vars.chm_credential = "user:mdp" 
 assign where host.name == "my mailbox server" 
} 

object Host "my mailbox server" { 
  check_command = "ping4" 
  address = "outlook.office365.com"
} 

object CheckCommand "check-mailbox2" { 
  command = [ ConfigDir + "/scripts/check_mailbox.sh" ] 
  arguments += { 
    "-H" = "$chm_host$" 
    "-C" = "$chm_credential$" 
    "-M" = "INBOX" 
    "-w" = "1000" 
    "-c" = "2000" 
  }
}
root@monitoring:/etc/icinga2/conf.d# icinga2 daemon -C
[2019-04-11 13:30:42 +0200] information/cli: Icinga application loader (version: r2.10.4-1)
[2019-04-11 13:30:42 +0200] information/cli: Loading configuration file(s).
[2019-04-11 13:30:42 +0200] information/ConfigItem: Committing config item(s).
[2019-04-11 13:30:42 +0200] information/ConfigItem: Instantiated 37 Services.
[2019-04-11 13:30:42 +0200] information/ConfigItem: Instantiated 1 IcingaApplication.
[2019-04-11 13:30:42 +0200] information/ConfigItem: Instantiated 88 Hosts.
[2019-04-11 13:30:42 +0200] information/ConfigItem: Instantiated 1 FileLogger.
[2019-04-11 13:30:42 +0200] information/ConfigItem: Instantiated 154 Dependencies.
[2019-04-11 13:30:42 +0200] information/ConfigItem: Instantiated 3 NotificationCommands.
[2019-04-11 13:30:42 +0200] information/ConfigItem: Instantiated 169 Notifications.
[2019-04-11 13:30:42 +0200] information/ConfigItem: Instantiated 1 NotificationComponent.
[2019-04-11 13:30:42 +0200] information/ConfigItem: Instantiated 7 HostGroups.
[2019-04-11 13:30:42 +0200] information/ConfigItem: Instantiated 1 GraphiteWriter.
[2019-04-11 13:30:42 +0200] information/ConfigItem: Instantiated 1 CheckerComponent.
[2019-04-11 13:30:42 +0200] information/ConfigItem: Instantiated 3 Zones.
[2019-04-11 13:30:42 +0200] information/ConfigItem: Instantiated 1 ExternalCommandListener.
[2019-04-11 13:30:42 +0200] information/ConfigItem: Instantiated 1 Endpoint.
[2019-04-11 13:30:42 +0200] information/ConfigItem: Instantiated 4 Users.
[2019-04-11 13:30:42 +0200] information/ConfigItem: Instantiated 1 IdoMysqlConnection.
[2019-04-11 13:30:42 +0200] information/ConfigItem: Instantiated 224 CheckCommands.
[2019-04-11 13:30:42 +0200] information/ConfigItem: Instantiated 16 UserGroups.
[2019-04-11 13:30:42 +0200] information/ConfigItem: Instantiated 4 TimePeriods.
[2019-04-11 13:30:42 +0200] information/ScriptGlobal: Dumping variables to file '/var/cache/icinga2/icinga2.vars'
[2019-04-11 13:30:42 +0200] information/cli: Finished validating the configuration file(s).

You can try:

assign where host.name

This will assign the service to all hosts that have a name.

@ozzi-
Copy link
Owner

ozzi- commented Apr 11, 2019

Further reading, a blog post of mine:
https://zgheb.com/i?v=blog&pl=41#ic_configuration

@aspryne
Copy link
Author

aspryne commented Apr 11, 2019 via email

@ozzi-
Copy link
Owner

ozzi- commented Apr 12, 2019

Hi aspryne
Ok cool now that we got this figured out. I don't recommend configuring this stuff in zone.d but ok.
I cannot see the screenshots you attached, so I can't really be of any help here.

@aspryne
Copy link
Author

aspryne commented Apr 12, 2019

my bad, can you see it now ?

Capture3
Capture
Capture2

@ozzi-
Copy link
Owner

ozzi- commented Apr 12, 2019

So your "ConfigDir" points to /usr/lib64/nagios/plugins? Interesting.
Permissions look ok, group all has read + execute.
Are you running SELinux? Never seen this problem.
This is beyond what I can help you with. Please go to icinga communtiy for any further help

@aspryne
Copy link
Author

aspryne commented Apr 12, 2019 via email

@ozzi-
Copy link
Owner

ozzi- commented Apr 12, 2019

cool we got it running!
cheers

@ozzi- ozzi- closed this as completed Apr 12, 2019
ozzi- pushed a commit that referenced this issue Jun 9, 2021
changed bc scale from 10 to 0 to get back integer
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

No branches or pull requests

2 participants