Exemplo n.º 1
0
def send_ifttt_maker(data, action_config):
  """Send request to IFTTT Maker channel

  Sensor_type will be used as event name.
  {{value1}} will be set to data['message']
  {{value2}} will be set to data['sensor_data']
  {{value3}} will be set to data['board_id']

  Meact configuration:
  action_config = {
    "endpoint": "https://maker.ifttt.com/trigger",
    "auth_key": "authkey",
    "enabled": 1
  }
  """
  if not action_config.get('enabled'):
    sys.exit(1)

  LOG.info('Sending request to IFTTT maker')

  url = '{}/{}/with/key/{}'.format(action_config['endpoint'], data['sensor_type'], action_config['auth_key'])

  params = {
      'value1': data['message'],
      'value2': data['sensor_data'],
      'value3': data['board_id']
  }

  req = utils.http_request(url, method='PUT', params=params)
  if req:
    sys.exit(0)

  LOG.warning('Fail to send IFTTT maker requests')
  sys.exit(2)
Exemplo n.º 2
0
def send_instapush(data, action_config):
  """Send notification via instapush.im

  Allow to send notification to multiple apps (users).
  Instapush configuration:
  - Application name - rpi
  - Event title - event_name
  - Trackers - message
  - Push message - RPI notification: {message}

  Meact configuration:
  action_config = {
    "event": "event_name",
    "endpoint": "https://api.instapush.im/v1/post",
    "apps": [
      {"id": "instapush-app-id", "secret": "instapush-app-secret"}
    ],
    "enabled": 1
  }
  """
  if not action_config.get('enabled'):
    sys.exit(1)

  LOG.info('Sending notification via instapush.im')

  url = action_config['endpoint']
  params = {
    'event': action_config['event'],
    'trackers': {
      'message': data['message']
    }
  }

  for app in action_config['apps']:
    headers = {
      'Content-Type': 'application/json',
      'x-instapush-appid': app['id'],
      'x-instapush-appsecret': app['secret']
    }

    req = utils.http_request(url, method='POST', data=json.dumps(params), headers=headers)

    if not req:
      LOG.warning('Fail to send notification via instapush.im')
      sys.exit(2)

  sys.exit(0)
Exemplo n.º 3
0
def send_pushover(data, action_config):
  """Send notification via pushover.net

  Allow to send notification via pushover.net.

  Meact configuration:
  action_config = {
    "token": "auth_token",
    "user_key": "user_or_group_key",
    "endpoint": "https://api.instapush.im/v1/post",
    "priority": 0,
    "enabled": 1
  }
  """
  if not action_config.get('enabled'):
    sys.exit(1)

  LOG.info('Sending notification via pushover.net')

  url = action_config['endpoint']
  params = {
    'token': action_config['token'],
    'user': action_config['user_key'],
    'priority': action_config.get('priority', 0),
    'message': data['message']
  }

  req = utils.http_request(url, method='POST', data=params)

  if not req:
    LOG.warning('Fail to send notification via pushover.net')
    sys.exit(2)

  try:
    response = json.loads(req.text)
  except (ValueError, TypeError):
    LOG.warning('Fail to send notification via pushover.net')
    sys.exit(2)

  if not response.get('status'):
    LOG.warning('Fail to send notification via pushover.net')
    sys.exit(2)

  sys.exit(0)
Exemplo n.º 4
0
def send_bulksms(data, action_config):
  """Send SMS via www.bulksms.com

  Bulksms is HTTP<->SMS gateway.

  Meact configuration:
  action_config = {
    "endpoint": "https://bulksms.vsms.net/eapi/submission/send_sms/2/2.0",
    "user": "******",
    "password": "******",
    "recipient": ["your-number", "your-number2"],
    "enabled": 1
  }
  """
  if not action_config.get('enabled'):
    sys.exit(1)

  LOG.info('Sending SMS via bulksms.com')

  url = action_config['endpoint']
  params = {
      'username': action_config['user'],
      'password': action_config['password'],
      'msisdn': action_config['recipient'],
      'message': data['message'],
  }

  req = utils.http_request(url, params=params)

  if req:
    result = req.text.split('|')
    if result[0] == '0':
      sys.exit(0)

  LOG.warning('Fail to send SMS via bulksms.com')
  sys.exit(2)