0

我的帖子

个人中心

设置

  发新话题
我想使用Saltstack的Beacon功能,实现监控的文件发生改变时自动发送SMTP邮件
在Minon编辑了
/etc/sat/minion
my-smtp-login:
  smtp.server: someaddress
  smtp.sender: someaddress
  smtp.username: someaddress
  smtp.password: someaddress

beacons:
  inotify:
    /root/testfile:
     mask:
      - modify
      - delete_self


在Master上编辑了
/etc/salt/master
reactor:
  - 'salt/beacon/*/inotify//root/testfile':
    - /srv/salt/reactor/filechanges.sls

/srv/salt/reactor/filechanges.sls
filechanged:
  cmd.smtp.send_msg:
    - tgt: 'os:CentOS'
    - tgt_type: grain
    - arg:
      - name: 'This is a file change warning message'
      - sender: someaddress
      - recipient: someaddress
      - subject: 'Hosts File Changed On Minion2'
      - profile: my-smtp-login


当Minion端的/root/testfile发生改变时应该会触发事件 filechanges
但是查看Master事件信息时返回
但是在Master上查看事件时发现如下
salt/job/20171003093326415380/ret/Minion1        {
    "_stamp": "2017-10-03T01:33:26.829687",
    "cmd": "_return",
    "fun": "smtp.send_msg",
    "fun_args": [
        {
            "name": "This is a file change warning message"
        },
        {
            "sender": "someaddress"
        },
        {
            "recipient": "someaddress"
        },
        {
            "subject": "Hosts File Changed On Minion2"
        },
        {
            "profile": "my-smtp-login"
        }
    ],
    "id": "Minion1",
    "jid": "20171003093326415380",
    "out": "nested",
    "return": "The minion function caused an exception: Traceback (most recent call last):\n  File \"/usr/lib/python2.6/site-packages/salt/minion.py

\", line 1200, in _thread_return\n    return_data = func(*args, **kwargs)\n  File \"/usr/lib/python2.6/site-packages/salt/modules/smtp.py

\", line 99, in send_msg\n    msg = email.mime.text.MIMEText(message)\n  File \"/usr/lib64/python2.6/email/mime/text.py

\", line 30, in __init__\n    self.set_payload(_text, _charset)\n  File \"/usr/lib64/python2.6/email/message.py

\", line 224, in set_payload\n    self.set_charset(charset)\n  File \"/usr/lib64/python2.6/email/message.py

\", line 266, in set_charset\n    cte(self)\n  File \"/usr/lib64/python2.6/email/encoders.py

\", line 73, in encode_7or8bit\n    orig.encode('ascii')\nAttributeError: 'dict' object has no attribute 'encode'\n",
    "success": false
}



这是python版本的原因还是sls文件编写问题



重新编写的sls如下
  filechanged:
    cmd.smtp.send_msg:
      - tgt: 'ipv4:192.168.1.19'
      - tgt_type: grain
      - kwarg:
         message: 'This is a file change warning message'
         sender: someaddress
         recipient: someaddress
         subject: 'Hosts File Changed On Minion2'
         profile: my-smtp-login

成功返回结果
salt/job/20171004203758631636/ret/Minion2        {
    "_stamp": "2017-10-04T12:37:59.097454",
    "cmd": "_return",
    "fun": "smtp.send_msg",
    "fun_args": [
        {
            "message": "This is a file change warning message",
            "profile": "my-smtp-login",
            "recipient": "someaddress",
            "sender": "someaddress",
            "subject": "Hosts File Changed On Minion2"
        }
    ],
    "id": "Minion2",
    "jid": "20171004203758631636",
    "retcode": 0,
    "return": true,
    "success": true
}



‹‹ 上一贴:centos7.4+xeon gold 6154没法睿频   |   下一贴:利用亚马逊云boto实现EC2存储卷的自动快照 ... ››
  发新话题
快速回复主题
关于我们 | 诚聘英才 | 联系我们 | 网站大事 | 友情链接 |意见反馈 | 网站地图
Copyright©2005-2017 51CTO.COM
本论坛言论纯属发布者个人意见,不代表51CTO网站立场!如有疑义,请与管理员联系:bbs@51cto.com