• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

Send nagios report as pdf file via email

August 26, 2015 by Sharad Chhetri

The tutorial will give you idea, how you can send Nagios Report as pdf file via email. We will achieve this requirement, with the help of script and using wkhtmltopdf command line tool. We will set the Nagios Report script in crontab and send it via email to receiver person/team.

In our previous post we shared, how we can convert website page into pdf. Logically we will use same thing here.

But the main part of script is how we can get the Nagios report URL. It is quite easy to get any Nagios Report URL from Web browser. You have to simply Right Click on your desired Report Section of Nagios Dashbaord, then from right click mouse menu ,select new tab or window. Now check address bar of newly opened tab in web browser , you will see long Nagios Report URL.

nagios-report

Steps to setup the Nagios Report script

1. Install wkhtmltopdf :

We will suggest you to follow the our previous post to install wkhtmltopdf command in your CentOS/Debian/Ubuntu system.

2. Create nagios_report script :

Once you install wkhtmltopdf . Create a script to send Nagios report pdf file through email.

In this script, we will get Nagios Event Log report in the form of pdf file, which is one day old.

(a) Install mutt :

With the help of mutt we will send the email .Hence install mutt in your system first.

   For CentOS / RHEL
    sudo yum install mutt

    For Ubuntu / Debian
    sudo apt-get install mutt

(b) Create a file nagios_report.sh

vi /opt/nagios_report.sh

(c) In nagios_report.sh file, write the following content. You can also do copy paste from below given script content.

Change the variable value like _USER, _PASSWORD,_TO_EMAIL etc. as per your requirement or information.
Here, _URL is the Nagios Report URL.

#!/bin/bash
#
# Author : Sharad Kumar Chhetri
# Date : 21-aug-2015
# Version : 1.0
# Description : The script will fetch the nagios eventlog report one day old.
#
## 

_URL="http://localhost/nagios/cgi-bin/showlog.cgi?archive=1"
_USER=nagios_username
_PASSWORD=Your_Nagios_password
_REPORT_PATH=/opt/NagiosReport
_FILE_NAME=Nagios-EventLog-`date +%F --date="yesterday"`.pdf
_TO_EMAIL=your@email.com
_WKHTMLTOPDF=`which wkhtmltopdf`

if [ -d $_REPORT_PATH ]
then
echo "NagiosReport directory already exist in /opt "
else
mkdir -p $_REPORT_PATH
echo $(ls -ld $_REPORT_PATH)
echo "$_REPORT_PATH directory created"
fi

### Create pdf file of Nagios Event Log , Set the --page-height and --page-width as per your requirement.
$_WKHTMLTOPDF --username $_USER --password $_PASSWORD   --page-height 1200 --page-width 900 "$_URL" "$_REPORT_PATH/$_FILE_NAME"

### Send Email with attachment
echo -e "Hello Team,nFind Nagios report dated of $(date +%F --date=yesterday), attachment is enclosed in this emailnBest RegardsnNagios Admin"|mutt -a "$_REPORT_PATH/$_FILE_NAME" -s "Report: Nagios Event Log  $(date +%F --date=yesterday)" -- $_TO_EMAIL

(d) Give executable permission nagios_report.sh script :

chmod 700 /opt/nagios_report.sh

Run the script manually from terminal to check.

sh /opt/nagios_report.sh

(e) Crontab setting :

As per your requirement now set the crontab for script. We are setting the script to be executed daily at 12:05 AM .

crontab -e
05 00 * * * /opt/nagios_report.sh

You can use this method for all types of report you generate on Nagios Dashboard. Logic is very simple, we just convert the website page into pdf file and send it through email.

Share this:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. How to use email id of Gmail for sending nagios email alerts
  2. send email after mysql backup through bash script in simple way
  3. NOTICE: nagios.cmd file not found. Please specify the location of this file in your /etc/vshell.conf file
  4. Install pdfedit for editing pdf file in Ubuntu
  5. Error: Could not open command file ‘/usr/local/nagios/var/rw/nagios.cmd’ for update!
  6. How to forcefully send mail from mailq in sendmail MTA
  7. Convert website page to pdf and image
  8. Bash Code Injection Vulnerability via Specially Crafted Environment Variables
  9. create noreply email id in postfixadmin mysql database
  10. Error: Could not stat() command file ‘/var/lib/nagios3/rw/nagios.cmd’!

Filed Under: Linux Tagged With: Nagios

Reader Interactions

Comments

  1. Nishith Niranjan Vyas says

    December 28, 2022 at 2:58 pm

    Hello,

    Here is my error:

    [root@central-nagios opt]# ./nagios_report.sh
    NagiosReport directory already exist in /opt
    ./nagios_report.sh: line 29: You: command not found
    Can’t stat /opt/NagiosReport/Nagios-EventLog-2022-12-27.pdf: No such file or directory
    /opt/NagiosReport/Nagios-EventLog-2022-12-27.pdf: unable to attach file.

    The nagios_report.sh file is as shown below.
    =====================================================
    # Description : The script will fetch the nagios eventlog report one day old.
    #
    ##

    _URL=”http://localhost/nagios/cgi-bin/showlog.cgi?archive=1″
    _USER=nagiosadmin
    _PASSWORD=H3ll0#123
    _REPORT_PATH=/opt/NagiosReport
    _FILE_NAME=Nagios-EventLog-`date +%F –date=”yesterday”`.pdf
    _TO_EMAIL=nvblue@xyz.com
    #_WKHTMLTOPDF=`which wkhtmltopdf`
    _WKHTMLTOPDF=`xvfb-run /usr/bin/wkhtmltopdf`

    if [ -d $_REPORT_PATH ]
    then
    echo “NagiosReport directory already exist in /opt ”
    else
    mkdir -p $_REPORT_PATH
    echo $(ls -ld $_REPORT_PATH)
    echo “$_REPORT_PATH directory created”
    fi

    ### Create pdf file of Nagios Event Log , Set the –page-height and –page-width as per your requirement.
    $_WKHTMLTOPDF –username $_USER –password $_PASSWORD –page-height 1200 –page-width 900 “$_URL” “$_REPORT_PATH/$_FILE_NAME”

    ### Send Email with attachment
    echo -e “Hello Team,nFind Nagios report dated of $(date +%F –date=yesterday), attachment is enclosed in this emailnBest RegardsnNagios Admin”|mutt -a “$_REPORT_PATH/$_FILE_NAME” -s “Report: Nagios Event Log $(date +%F –date=yesterday)” — $_TO_EMAIL

    =====================================================

    Please Help…

  2. Bala says

    December 6, 2021 at 11:03 am

    I followed the steps. reports seems to be fine but mails i not getting triggered.

    error:
    Dec 6 16:12:49 nagios postfix/pickup[1345779]: 1E2956005D: uid=0 from=
    Dec 6 16:12:49 nagios postfix/cleanup[1351376]: 1E2956005D: message-id=
    Dec 6 16:12:49 nagios postfix/qmgr[1772]: 1E2956005D: from=, size=67572, nrcpt=1 (queue active)
    nagios postfix/error[1351382]: 1E2956005D: to=****************
    postfix/bounce[1351383]: 1E2956005D: sender non-delivery notification: 244E466463
    Dec 6 16:12:49 nagios postfix/qmgr[1772]: 244E466463: from=, size=2235, nrcpt=1 (queue active)
    Dec 6 16:12:49 nagios postfix/qmgr[1772]: 1E2956005D: removed
    Dec 6 16:12:49 nagios postfix/local[1351384]: 244E466463: to=, relay=local, delay=0.01, delays=0/0/0/0, dsn=2.0.0, status=sent (delivered to mailbox)
    Dec 6 16:12:49 nagios postfix/qmgr[1772]: 244E466463: removed

  3. Vinod Panday says

    March 12, 2018 at 6:54 am

    Hi,
    I am receiving two same email at the same time, what is the issue.

    • Sharad Chhetri says

      March 15, 2018 at 4:51 pm

      Hi Vinod,

      Check mail settings. May be same lines are duplicated.

      Regards
      Sharad

  4. Rajendra says

    March 15, 2017 at 10:47 am

    Error getting when using nagios report script in crontab

    NagiosReport directory already exist in /opt
    /opt/test.sh: line 28: –username: command not found
    Mar 15 16:17:01 uhcindia sendEmail[33425]: ERROR => The attachment [/opt/NagiosReport/Nagios-EventLog-2017-03-14.pdf] doesn’t exist!
    Mar 15 16:17:01 uhcindia sendEmail[33425]: HINT => Try specifying the full path to the file or reading extended help with “–help message”

    • Sharad Chhetri says

      March 15, 2017 at 5:32 pm

      Hi Rajendra,

      Change the variable value like _USER, _PASSWORD,_TO_EMAIL etc. as per your requirement or information in script.
      Here, _URL is the Nagios Report URL.

      Regards
      sharad

  5. Nagarjuna says

    April 25, 2016 at 7:41 am

    Great work !!! Worked…

    Could you please let me know, how can I configure to sent a mail to internal DL (Group mail)..

    • Nagarjuna says

      April 25, 2016 at 10:16 am

      I got resolved. My email exchange was blocking it…

  6. Sanakiyan says

    January 6, 2016 at 11:39 am

    kindly guide how to reset centos 6.7 root password

    • sharad chhetri says

      January 6, 2016 at 3:18 pm

      Hello Sanakiyan,

      You can follow the steps guided in our this post – https://sharadchhetri.com/2014/01/02/reset-forgot-root-password-centos-6-x-redhat-6-x/

      Feel free to revert with your feedback, I will be happy to assist.

      Regards
      Sharad

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Linux Command

What is Linux Internal And External Command

Linux Basic Commands With Examples For Every Beginner

tr command to convert lines to space , tab and vertical tab

smbpasswd command not found on CentOS 7 and RHEL 7

Solution : semanage command not found

Unix / Linux : How to print duplicate lines from file

More Posts from this Category

You Might Like These Articles!

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

libfuse

dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

Failed to open/create the internal network

VirtualBox Error: Failed to open/create the internal network

Always Useful Tips And Tricks

Password prompt in single user mode is not secure : CentOS/Red Hat

rsync all files,hidden files,symlinks,hardlinks to remotes Linux Server

How to zip directory in linux explained with examples

How to install pam_mysql in CentOS or Red Hat

Forward all incoming emails to other SMTP server or gateway

Virtual Machine inaccessible status on VirtualBox 4.3

Set GRUB password after installation of CentOS/Red Hat

Explore 90+ Article On "Linux Tips And Tricks"

Copyright © 2023 ยท
The material in this site cannot be republished either online or offline, without our permission.
Proudly Blogging From Bharat.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy