Wednesday, 12 February 2014

Enabling Synagios Email Alerts

So, you've just installed Synagios, restored from the backup file to get the default configuration, and now your Diskstation is monitored; but how do you make synagios send email alerts? This is fairly easy to set up but how you do it does depend on your email setup.

Sending to the Synology Email Server

The default configuration is set up to send notification emails to the local server, so if you are using the Synology email server, built into the diskstation, then all that's required is to add your email address to the default ds-admin account in the Contacts tab. The following video shows how.

Sending via your ISP

Many ISP's and most companies block emails coming from known broadband addresses to reduce spam, and many ISPs also block outward bound email messages to all addresses apart from their own relay servers for the same reason. It's never a good idea to send emails directly from a standard broadband account - always use the relay server unless you have a business account. Additionally, some ISPs require secure authentication to be able to send emails through their relay server.

So, even if you don't use the Synology email server it's a good idea to set it up to send to your ISP's SMTP relay server. Doing it this way means that setting up Synagios is the same as the above video, so, really simple, and the diskstation's mail server can handle all the difficult bits (authentication, relay servers etc.).

Sending from within a Corporate Network

This is something that will need to be cleared with the IT department at your company. It will probably be the same process as 'Sending via your ISP' above, but you'll need to know which internal email server to point the diskstation's email server at, and there may be other restrictions.


  1. Hi,
    I've installed Synagios on a DS214, and it seems to work (great contribution, thanks), except I'm not receiving emails.
    As you explained I've added my email address to the default ds-admin account in the Contacts tab. Also I've configured my NAS to properly send me email notifications (I've done a test and it works). I tried to let one of my servers down on purpose and also I've clicked on "Send custom service notification" on the detailed service page, but none of these actions triggers an email.
    Any idea ? Thanks

  2. In the Commands tab, in the nagrestconf GUI, there is 'notify-host-by-email' and 'notify-service-by-email'. They are as follows:

    /usr/bin/printf "mail from: nagios@localhost\r\nrcpt to: %b\r\nDATA\r\nSubject: %b\nFrom: nagios@diskstation\nTo: %b\n\n%b\n.\n" "$CONTACTEMAIL$" "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" "$CONTACTEMAIL$" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n\n$NOTIFICATIONAUTHOR$\n\t$NOTIFICATIONCOMMENT$\n" | /usr/local/bin/mailsender -

    /usr/bin/printf "mail from: nagios@localhost\r\nrcpt to: %b\r\nDATA\r\nSubject: %b\nFrom: nagios@diskstation\nTo: %b\n\n%b\n.\n" "$CONTACTEMAIL$" "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" "$CONTACTEMAIL$" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\nAdditional Info:\n\n$HOSTOUTPUT$\n\n$NOTIFICATIONAUTHOR$\n\t$NOTIFICATIONCOMMENT$\n" | /usr/local/bin/mailsender -

    First, check that your commands are the same as the above.

    So, to test notify-service-by email:
    Click on a service and choose 'Send custom service notification'
    (I know you did this already - just working it through)
    The email should be sent within a few seconds.

    If not, then:
    * Check that email alerts are actually enabled for the service.
    * Use the System -> Configuration tab in the nagios gui to check that the service has contacts set and the 'notification period' is correct.
    * Check all the components of the notify-*-by-email commands.

    To check all the components of the commands:
    Use putty or ssh to log into the diskstation, then paste the following:

    chroot /volume1/@appstore/Synagios/nagios-chroot/

    That gets you into the nagios installation.

    /usr/bin/printf "bob\n"

    Should output the word 'bob'.

    Now try mailsender:

    /usr/local/bin/mailsender -

    You should see the synology banner, e.g.

    RECV > 220 ESMTP Postfix

    Type 'quit' the enter, then Ctrl-d.

    Now, try a full email. Type (well paste) but put your email address in:

    /usr/bin/printf "mail from: nagios@localhost\r\nrcpt to: YOUR@EMAILADDR\r\nDATA\r\nSubject: Test\nFrom: nagios@diskstation\nTo: you\n\nTest\n.\n" | /usr/local/bin/mailsender -

    You should get the email.

    Something should go wrong for you before you get to this point, which should help you fix the problem. If all the above worked then I'm stumped.

  3. /usr/bin/printf "bob\n" works,
    but when I type "/usr/local/bin/mailsender", it replies :
    "Connecting to (
    connect error: Connection refused"

    My firewall is not activated, I've google this error with no success.

  4. Change to the IP address of your server and see if it works.

  5. Same result with the LAN IP address of the server (
    But I finally could make it work with my ISP smtp server, however I had to put my contact email as the sender otherwise the mail was not sent (I guess it's an anti-spam protection from the ISP). Mark, Thanks a lot for everything !

  6. You're very welcome :) Really glad you got it working.

    If you need this to work later on:

    Maybe your synology mail server wasn't listening on port 25?
    Test on your diskstation with 'netstat -l -t -n -p | grep :25', which should show:

    tcp 0 0* LISTEN 15397/master
    tcp 0 0 ::%134910348:25 ::%134910348:* LISTEN 15397/master

    If you got no output then maybe you hadn't set up or started your synology mail server?

  7. Strange Problem, my error is: SMTP connection lost after final dot
    Exim doesn't terminate incomings Mail with \CR, dot \CR
    I've tried it in the command line, the dot is ignored.
    Can anyone help?

    1. RFC2821 - "The mail data is terminated by a line containing only a period, that is, the character sequence "<CRLF>.<CRLF>"."

      So you might need to end with '\r\n.\r\n' as the RFC states. Edit the command to do that.

    2. As an addendum, I just found that using 'data' all in lowercase will produce the problem you're seeing. I've fixed the mailsender source code so it accepts upper case 'DATA' and lowercase 'data', but this might have been the problem you were seeing.

  8. Hi Mark! Works out of the box. Now i'm asking myself what i did the whole time without Nagios@Home :-D
    I have one question: in the Synology Mail Server's "Warteschleife" (i think thats perhaps wait loop or similar in English) is see deferred mails from MAILER-DAEMOn to the NAS's email address. This happens several times a day, not in a particualr time interval. Second is that it seems every time Nagios sends an email to my regualr email address, there is an additional email going from SYSTEM to the NAS's email address, which fails (to be seen in email history). Is there something to prevent this? in email security settinngs i already blacklisted these, but it doesn't work. Do you have a hint for me?

    1. Hi Thomas. I don't see the extra emails being sent on my system. You'll need to work out how to reproduce and then let me know. Although, aren't MAILER-DAEMON messages usually sent due to an email error condition? For example, I send an email, it's queued at the diskstation, the diskstation was unable to send for whatever reason, so it sends an email to you from MAILER-DAEMON with the problem. I don't know about SYSTEM. All I can say is that the exim mail server does not run inside the chroot, cron won't be able to send emails (but maybe you should check exactly), and nagios uses mailsender (unless you haven't set up to use it) that is so dumb it's only possible for it to send one email. Confused...

    2. Hi Thomas. Did you find out what the problem was, can you tell me how to replicate? Cheers! Mark.

    3. Hi Mark
      sorry i have been very busy the last days (still lacking the devolo-howto, too). I did not find any solution to this. so i would begin tracking it down from the log files. I am not in reach of my NAS now so are they stored under /var/log (in chroot) or should i look somewhere else?

    4. It's no problem, no rush! I was just wondering :) Yep, logs in CHROOT/var/log.

  9. Hi Mark!
    I have news to this: i discovered that, when i add Google
    SMTP ( as mail relay (had none before), these problems won't occur. But since Google rewrites the email sender addresses with the account you enter for verifying, i signed up at Mailjet. the free account offers 200mails/day (which is fairly enough) and after verification i can add as many sender addresses as i want.
    So now i have the Mailjet SMTP server as realy and no more errors


    1. Nice! Good to know about Google SMTP. I signed up with DnsExit, with a free 1 year trial at the time, when Virgin got rid of their email relay host, and now I pay for it. So annoying that ISPs are getting rid of mail relay.

  10. This comment has been removed by the author.

  11. This comment has been removed by a blog administrator.

  12. A very stylistic way of writing, creating effects especially in language and literature.