Wednesday, November 7, 2018

Nagios Reports Generation

Nagios Report Generation and Sending Email

This cronjobs allow to download reports as html and attaching to mail body

30 4 * * * curl --silent http://localhost/sslviewer/sslcert.php



0 6 * * * wget -v --user xxx --password 'xxx' --no-check-certificate -O /home/lknic/`date +\%Y\%m\%d`-report.html "http://monitor.nic.lk/nagios/cgi-bin/avail.cgi?show_log_entries=&host=all&timeperiod=yesterday&timeperiod=24x7"

1 6 * * * sed -e 's/CLASS='\''dataOdd'\''/style='\''background-color:#bda9f0;'\''/g' -e 's/CLASS='\''dataEven'\''/style='\''background-color:#d6cbf1;'\''/g' -e 's/CLASS='\''hostUP'\''/style='\''background-color:#88eba8;'\''/g' -e 's/CLASS='\''hostDOWN'\''/style='\''background-color:#ebc8ac;'\''/g' -e 's/CLASS='\''hostUNREACHABLE'\''/style='\''background-color:#e4a240;'\''/g' /home/lknic/`date +\%Y\%m\%d`-report.html > /home/lknic/`date +\%Y\%m\%d`-reporttemp.html



2 6 * * * mutt -e 'set content_type=text/html realname="LK Domain Registry Monitoring System"' -s 'Daily Servers Status Report' 'xxx@com.com' < /home/lxxx/`date +\%Y\%m\%d`-reporttemp.html

3 6 * * * rm /home/xxx/`date -d '-7 days' +%Y%m%d`-report.html
3 6 * * * rm /home/xxx/`date -d '-7 days' +%Y%m%d`-reporttemp.html

Setting up email server in CentOS 7 with Devocot

stname -f
yum -y install postfix dovecot telnet squirrelmail openssl
mkdir /etc/postfix/ssl
cd /etc/postfix/ssl
openssl req -x509 -nodes -newkey rsa:2048 -keyout server.key -out server.crt -nodes -days 365
nano /etc/postfix/main.cf
myhostname = os.yourdomain.com
mydomain = yourdomain.com
myorigin = $mydomain
home_mailbox = mail/
mynetworks = 127.0.0.0/8
inet_interfaces = all
inet_protocols = all
inet_interfaces = localhost
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_sasl_auth_enable = yes
smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination
smtp_tls_security_level = may
smtpd_tls_security_level = may
smtp_tls_note_starttls_offer = yes
smtpd_tls_loglevel = 1
smtpd_tls_key_file = /etc/postfix/ssl/server.key
smtpd_tls_cert_file = /etc/postfix/ssl/server.crt
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom

nano  /etc/postfix/master.cf
submission     inet  n       -       n       -       -       smtpd
      -o syslog_name=postfix/submission
      -o smtpd_sasl_auth_enable=yes
      -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
      -o milter_macro_daemon_name=ORIGINATING
smtps     inet  n       -       n       -       -       smtpd
      -o syslog_name=postfix/smtps
                                                              21,1          37%

nano  /etc/postfix/master.cf
submission     inet  n       -       n       -       -       smtpd
      -o syslog_name=postfix/submission
      -o smtpd_sasl_auth_enable=yes
      -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
      -o milter_macro_daemon_name=ORIGINATING
smtps     inet  n       -       n       -       -       smtpd
      -o syslog_name=postfix/smtps
      -o smtpd_sasl_auth_enable=yes
      -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
      -o milter_macro_daemon_name=ORIGINATING

nano /etc/dovecot/conf.d/10-master.conf
 # Postfix smtp-auth
    unix_listener /var/spool/postfix/private/auth {
    mode = 0660
    user = postfix
    group = postfix
    }

nano  /etc/dovecot/conf.d/10-auth.conf
uncomment ldap authetication
nano /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:
mail uid and mail gid
nano  /etc/dovecot/conf.d/20-pop3.conf
pop3_uidl_format = %08Xu%08Xv

systemctl restart postfix ;  systemctl enable postfix ; systemctl restart dovecot ; systemctl enable dovecot
firewall-cmd --permanent --add-service=smtp
firewall-cmd --permanent --add-port=587/tcp
firewall-cmd --permanent --add-port=465/tcp
firewall-cmd --permanent --add-port=110/tcp
firewall-cmd --permanent --add-service=pop3s
firewall-cmd --permanent --add-port=143/tcp
firewall-cmd --permanent --add-service=imaps
firewall-cmd --permanent --add-service=http
firewall-cmd --reload

spamassassin unix - n n - - pipe flags=R user=spamd argv=/usr/bin/spamc -e /usr/sbin/sendmail -oi -f ${sender} ${recipient}