Ad Widget

Collapse

PoC: Email to Zabbix trapper items

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BDiE8VNy
    Senior Member
    • Apr 2010
    • 680

    #1

    PoC: Email to Zabbix trapper items

    Hi there!

    First of all, this prove of concept is a very poor implementation and inspired by ZBXNEXT-3039.

    ZBXNEXT-3039 would allow full control from Zabbix fronted/server side. Here, since being based on Zabbix trapper resp. Zabbix sender, only fixed item variations are used and proper items of type Zabbix trapper have to exist.

    How does it work?

    The Python script makes use of inbox.py and py-zabbix.
    Before being started the script smtpToZbxTrap.py has to be edited to configure the following parameters:

    Code:
    BIND_TO_ADDR = '93.184.216.34'
    BIND_TO_PORT = 25
    
    ZABBIX_SERVER_ADDR = '127.0.0.1'
    ZABBIX_SERVER_PORT = 10051
    The BIND_* variables define where the script should listen for incoming Emails.
    The ZABBIX_* variables define where the script should send values to via Zabbix trapper protocol.

    Once started the script sends a bulk of item values for each received Email.

    The host in Zabbix to send the values to is derived from the recipient addresses. So a recipient address like:

    [email protected]

    would cause the values to be send to a host 'foobar' in Zabbix.

    An Email:
    Code:
    From: [email protected]
    To: [email protected]
    Subject: Something happened
    Message: This is the email body
    Will feed these items of type Zabbix trapper, if existent:
    Code:
    smtp.trap[subject,[email protected]] "Something happened"
    smtp.trap[message,[email protected]] "This is the email body"
    smtp.trap[sender] "[email protected]"
    smtp.trap[subject] "Something happened"
    smtp.trap[message] "This is the email body"
    Because I preferred the logging library used by py-zabbix I replaced the one used in inbox.py accordantly (see inbox.py-logging.patch)
    Attached Files
  • stebecga
    Junior Member
    • Apr 2016
    • 1

    #2
    Hi BDiE8VNy,

    are you still actively working on this? I was thinking of a similar setup to integrate other monitoring solutions or devices which only work via smtp.

    Please share your thoughts or newer ideas maybe we can work on this together.

    All the best

    Comment

    • niuk
      Junior Member
      • Jul 2016
      • 5

      #3
      The other option is to use webhook, kind of email to API call, i.e. https://context.io/how-it-works/api-overview Or sending to gmail and then retrieve via API, and API call to Zabbix i.e. https://www.npmjs.com/package/node-gmail-api. Very few lines of code
      Last edited by niuk; 29-07-2016, 15:57.

      Comment

      • sharpe
        Junior Member
        • Jul 2017
        • 2

        #4
        thank you

        Hi BDiE8VNy,

        thank you for your solution, I confirm that PoC is working, and I add my contribution to it - systemd configuration script to run it as system service:

        Code:
        [Unit]
        Description=smtpToZbxTrap inspired by https://www.zabbix.com/forum/showthread.php?p=186838
        #Requires=After=XYZ.service       # Requires the XYZ service to run first
        
        [Service]
        ExecStart=/path/to/smtpToZbxTrap.py
        # Required on some systems
        #WorkingDirectory=/working/directory
        Restart=always
        # Restart service after 10 seconds if node service crashes
        RestartSec=10
        # Output to syslog
        StandardOutput=syslog
        StandardError=syslog
        SyslogIdentifier=smtpToZbxTrap
        #User=zabbix
        #Group=zabbix
        #Environment=NODE_ENV=production PORT=25
        
        [Install]
        WantedBy=multi-user.target
        If you don't want to run it as root, uncomment User directive and change PORT=25 to uprivileged one (not below 1024).

        Comment

        • ZMS
          Junior Member
          • Nov 2020
          • 19

          #5
          hello
          i have a need to monitor incoming emails too
          how do i configure it with what you posted here?
          help plzz

          Comment

          Working...