-

   rss_rss_hh_new

 - e-mail

 

 -

 LiveInternet.ru:
: 17.03.2011
:
:
: 51

:


SaltStack Telegram

, 02 2017 . 23:21 +

image
Telegram SaltStack. 2015.5.0, SaltStack Slack , Telegram . , .



, SaltStack , , . , .
, Telegram Python . , , Python-, SaltStack.



, :


  1. chat_id

. id python:


import requests

URL = 'https://api.telegram.org/bot'
TOKEN = <  >

try:
    request = requests.post('{url}{token}/getUpdates'.format(url=URL, token=TOKEN))
    print request.json()['result'][0]['message']['chat']['id']
except Exception,e:
    print str(e)

, . , SaltStack _modules/ :


import requests

URL='https://api.telegram.org/bot'

def notify(message, token, chat_id):
        message_data = {
                'chat_id': chat_id,
                'text': message
        }

        try:
                request = requests.post('{url}{token}/sendMessage'.format(url=URL, token=token), data=message_data)
        except Exception,e:
                return False, str(e)

        if not request.status_code == 200:
                return False, "Return status is unsuccessful"
        #         .
        return True, "Message was successfully sent"

, :
salt '*' saltutil.sync_modules


, :
image


, , ( send_telegram.sls)


send message about minion id:
  module.run:
    # telegram -  python-, notify -    
    - name: telegram.notify
    - kwargs:
      message: command executed on minion with id {{ grains['id'] }}
      token: <  >
      chat_id: 

:
salt '*' state.apply send_telegram


:
image


:
image



  1. Python requests
  2. Writing execution modules
  3. How do I use salt states?

Original source: habrahabr.ru (comments, light).

https://habrahabr.ru/post/330028/

:  

: [1] []
 

:
: 

: ( )

:

  URL