Search code examples
smtpsalt-projectubuntu-server

Saltstack smtp.send_msg returning with attribute error


I set up a beacon that tracks disk usage on all the Ubuntu Server 16.04 minions on Ubuntu Server 16.04. We wanted a reactor that emails us when disk space reaches a certain point. This question focuses on the master's ability to send an email. When I run the following command on the salt-master:

sudo salt-call smtp.send_msg '[email protected]' 'Test message 3' subject='Test subject 3' profile='smtp-default'

I get the following result:

[ERROR   ] An un-handled exception was caught by salt's global exception handler:
AttributeError: 'str' object has no attribute 'get'
Traceback (most recent call last):
  File "/usr/bin/salt-call", line 11, in <module>
    salt_call()
  File "/usr/lib/python2.7/dist-packages/salt/scripts.py", line 391, in salt_call
    client.run()
  File "/usr/lib/python2.7/dist-packages/salt/cli/call.py", line 58, in run
    caller.run()
  File "/usr/lib/python2.7/dist-packages/salt/cli/caller.py", line 134, in run
    ret = self.call()
  File "/usr/lib/python2.7/dist-packages/salt/cli/caller.py", line 204, in call
    ret['return'] = func(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/salt/modules/smtp.py", line 95, in send_msg
    server = creds.get('smtp.server')
AttributeError: 'str' object has no attribute 'get'
Traceback (most recent call last):
  File "/usr/bin/salt-call", line 11, in <module>
    salt_call()
  File "/usr/lib/python2.7/dist-packages/salt/scripts.py", line 391, in salt_call
    client.run()
  File "/usr/lib/python2.7/dist-packages/salt/cli/call.py", line 58, in run
    caller.run()
  File "/usr/lib/python2.7/dist-packages/salt/cli/caller.py", line 134, in run
    ret = self.call()
  File "/usr/lib/python2.7/dist-packages/salt/cli/caller.py", line 204, in call
    ret['return'] = func(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/salt/modules/smtp.py", line 95, in send_msg
    server = creds.get('smtp.server')
AttributeError: 'str' object has no attribute 'get'

This is my salt --versions-report output of the master that returns the error:

Salt Version:
           Salt: 2017.7.1

Dependency Versions:
           cffi: 1.10.0
       cherrypy: unknown
       dateutil: 2.4.2
      docker-py: Not Installed
          gitdb: 0.6.4
      gitpython: 1.0.1
          ioflo: Not Installed
         Jinja2: 2.8
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: 1.0.3
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: Not Installed
      pycparser: 2.18
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.12 (default, Nov 19 2016, 06:48:10)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.2.0
           RAET: Not Installed
          smmap: 0.9.0
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4

System Versions:
           dist: Ubuntu 16.04 xenial
         locale: UTF-8
        machine: x86_64
        release: 4.4.0-93-generic
         system: Linux
        version: Ubuntu 16.04 xenial

I have uninstalled and reinstalled the salt-master and salt-minion and I have updated Python and the salt-master. I also created another salt-master and it ran into the same problem. What is the fix or solution to this?


Solution

  • I have discovered that the error has nothing to do with the installed Python libraries or if my system is updated or not. I found that I did not have an SMTP server set up and that I need to create an SMTP mail server or have an accessible SMTP mail server in order to send emails as notifications of the reactor system. I discovered that the solution was to set up an SMTP mail server and then create a .conf file in the /etc/salt/minion.d directory that referenced an SMTP mail server like so:

    smtp-default:
      smtp.sender: [email protected]
      smtp.server: 0.0.0.0
      smtp.tls: false
    

    After creating a .conf file similar to the one above and the profile of the salt-call command referring to the function declaration of the state file, I was able to send emails to the desired address.