- Tomaz Muraus (Kami)
- Engineer at StackStorm
- Previously: Cloudkick, Rackspace, DivvyCloud
- Likes: Distributed systems, infrastructure, open standards and open source systems, startups, tinkering / "hacking" 80's music, working out
pip install st2client
from st2client.client import Client client = Client() actions = client.actions.get_all() print(actions) ...
npm install st2client
var st2client = require('st2client');
var client = st2client(config);
var auth = st2client.authenticate(config.credentials.user,
config.credentials.password);
auth.then(function onAuth() {
console.log(st2client.actions.list());
});
...
...
def _handle_pubmsg(self, connection, event):
trigger = 'irc.pubmsg'
payload = {
'source': {
'nick': event.source.nick,
'host': event.source.host
},
'channel': event.target,
'timestamp': event.timestamp,
'message': event.arguments[0]
}
self._sensor_service.dispatch(trigger=trigger, payload=payload)
...
{
"source": {
"nick": "Kami__",
"host": "gateway/web/irccloud.com/x-uvv"
},
"channel": "#test989",
"timestamp": 1419166748,
"message": "this is a test message"
}
Send an email using Mailgun API.
import httplib
import requests
from st2actions.runners.pythonrunner import Action
SEND_EMAIL_API_URL = 'https://api.mailgun.net/v2/%(domain)s/messages'
class SendEmailAction(Action):
def run(self, sender, recipient, subject, text, html=None):
domain = self.config['domain']
api_key = self.config['api_key']
data = {
'from': sender,
'to': recipient,
'subject': subject,
'text': text
}
if html:
data['html'] = html
api_url = SEND_EMAIL_API_URL % {'domain': domain}
response = requests.post(api_url, auth=('api', api_key), data=data)
return response.status_code == httplib.OK
Send an email using Mailgun API.
#!/usr/bin/env bash
API_KEY=$1
DOMAIN=$2
SENDER=$3
RECIPIENT=$4
SUBJECT=$5
MESSAGE=$6
curl -X POST -H "Content-Type: application/json" --user "api:key-${API_KEY}" \
https://api.mailgun.net/v2/${DOMAIN}/messages \
-d '{"from": "${SENDER}", "to": "${RECIPIENT}", "subject": "${SUBJECT}", "message": "${MESSAGE}"}'
Relay messages from IRC channel to Slack.
---
name: "relayed_matched_irc_message"
description: "Relay IRC message to Slack if the message contains word StackStorm"
enabled: true
trigger:
type: "irc.pubmsg"
parameters: {}
criteria:
trigger.message:
type: "icontains"
pattern: "StackStorm"
action:
ref: "slack.post_message"
parameters:
message: "{{trigger.source.nick}} on {{trigger.channel}}: {{trigger.message}}"
channel: "#irc-relay"
Your contributions are appreciated and welcome!