26. 03. 2020 Nicolae Caragia NetEye

Report Problems By Email – NetEye 4

Use case : I want to send a PDF with services problems by email.

Let’s suppose a client wants to receive an email containing a file with a list of all service problems. Unfortunately, the SLM module doesn’t have the ability to specify the filter service_state on the object field, so I modified the export_csv_export.php script (contained in /usr/share/neteye/reporting/scripts) to adapt it to my needs.

You can find this script at the following URL:

https://github.com/caragian/reporting_pdf_email

This script allows you to:

  • Send a PDF file containing the Service Problems by Email

And its requirements are:

  • PHP5 or higher
  • A user in NetEye who has the correct Roles to view the respective Service Problems
  • Directory in NetEye : /neteye/shared/icingaweb2/extras/reporting/report_pdf_email/

This script takes information about Service Problems using the curl function.

In this case curl returns information in JSON format, which will be filtered to use only the information that we want to report in the PDF.

PDF files will also be saved in a local directory (default: /tmp/reporting).
Pay attention here because if you create multiple PDF files on the same day, the oldest files with the same name (default: current_date.service_problem.pdf) will be overwritten.

Implementing this script is quite simple, you just need to follow the guide at the link above and then change the email address.

Note #1: If you have a cluster, it may be necessary to change the domain.

Note #2: You can also change the filter to customize your report:

$baseUrl = sprintf(
                 '%s://%s%s/neteye/monitoring/list/services?service_state=2&limit='.$this->limit,
                    $this->getProtocol(),
                    $this->getDomain(),
                    $this->getPort()

In this case we want to report those service problems which have service_state=2, but by changing this line:

   '%s://%s%s/neteye/monitoring/list/services?service_state=2&limit='.$this->limit,

you will be able to report different elements.

In addition, you could also define a cronjob to automate this report:

* * * * *  systemctl status httpd.service > /dev/null 2>&1 &&  /usr/bin/php /neteye/shared/icingaweb2/extras/reporting/reporting_pdf_email/export_pdf_report.php -u root -p $(cat /root/.pwd_icingaweb2_root)  >/dev/null
Nicolae Caragia

Nicolae Caragia

Author

Nicolae Caragia

Leave a Reply

Your email address will not be published. Required fields are marked *

Archive