Coder Social home page Coder Social logo

err-stackstorm's Introduction

Activate development has moved to https://github.com/nzlosh/err-stackstorm

err-stackstorm

A plugin to run StackStorm actions, bringing StackStorm's chatops to Errbot.

Table of Contents

  1. Installation
  2. Requirements
  3. Supported Chat Backends
  4. Configuration
  5. Setup Action-Aliases
  6. Webhook
  7. Server-Side Events
  8. Chatops Pack
  9. Troubleshooting

Installation

Installation of the err-stackstorm plugin is performed from within a running Errbot instance. Ensure Errbot is up and running before attempting to install the plugin. See the Errbot installation documentation here https://github.com/Errbotio/Errbot for instructions on how to setup Errbot on your chat back-end. These instructions assume a running instance of StackStorm is already in place. See the official StackStorm documentation for details.

  1. Install Errbot on the target system using standard package manager or Errbot installation method.
  2. Configure Errbot, see the Configuration section for help.
  3. Enable Errbot's internal web server, see the Webhook section for help.
  4. Install Chatops pack on StackStorm, see the Chatops Pack section for help.
  5. Connect to your chat back-end and starting interacting with your StackStorm/Errbot instance.

The below command will install the plugin.

!repos install https://github.com/fmnisme/err-stackstorm.git

Requirements

The plugin has been developed and tested against the below software. For optimal operation it is recommended to use the following versions:

plugin tag (version) Python Errbot StackStorm client
1.4 3.4 5.1.2 2.5
1.3 3.4 5.1.2 2.5
1.2 3.4 5.0 2.2
1.1 3.4 4.3 2.2
1.0 2.7 3.x 2.1

Supported Chat Back-ends

Errbot provides official support for a few of major chat back-ends and many more chat back-ends are available through unofficial plugins.

Back end Mode value Support type
Hipchat hipchat Integrated
IRC irc Integrated
Slack slack Integrated
Telegram Messenger telegram Integrated
Text text Integrated
XMPP xmpp Integrated
Skype skype Plugin
Mattermost mattermost Plugin
Rocket Chat aoikrocketchaterrbot Plugin
Glip Glip Plugin
Gitter gitter Plugin
VK VK Plugin
Discord discord Plugin
Cisco Spark CiscoSpark Plugin
TOX tox Plugin
CampFire campfire Plugin

Back-end support will provide a minimum set of back-end chat functionality to the err-stackstorm plugin like connect to and authenticate with chat back-end, identify users/rooms and send_message to users/rooms. Advanced formatting may not be available on all back-ends since adaptor code is required in the err-stackstorm plugin to translate ActionAlias extra parameter on a per back-end basis.

Currently supported extra back-ends

  • Slack

Configuration

Edit the config.py configuration file which is used to describe how the plugin will communicate with StackStorm's API and authentication end points. If you followed the Errbot setup documentation this file will have been created by downloading a template from the Errbot GitHub site. If this file has not already been created, please create it following the instructions at https://github.com/Errbotio/Errbot

STACKSTORM = {
    'auth_url': 'https://stackstorm.example.com/auth/v1',
    'api_url': 'https://stackstorm.example.com/api/v1',
    'stream_url': 'https://stackstorm.example.com/stream/v1',

    'verify_cert': True,
    'api_auth': {
        'user': {
            'name': 'my_username',
            'password': "my_password",
        },
        'token': "<User token>",
        'key': '<API Key>'
    },
    'timer_update': 900, #  Unit: second.  Interval for Errbot to refresh to list of available action aliases.
}
Option Description
auth_url StackStorm's authentication url end point. Used to authenticate credentials against StackStorm.
api_url StackStorm's API url end point. Used to execute action aliases received from the chat back-end.
stream_url StackStorm's Stream url end point. Used to received chatops notifications.
verify_cert Default is True. Verify the SSL certificate is valid when using https end points. Applies to all end points.
api_auth.user.name Errbot username to authenticate with StackStorm.
api_auth.user.password Errbot password to authenticate with StackStorm.
api_auth.token Errbot user token to authenticate with StackStorm. Used instead of a username/password pair.
api_auth.key Errbot API key to authenticate with StackStorm. Used instead of a username/password pair or user token.
timer_update Unit: seconds. Default is 60. Interval for Errbot to refresh to list of available action aliases. (deprecated)

Authentication

Authentication is possible with username/password, User Token or API Key. In the case of a username and password, the plugin is requests a new User Token after it expires. In the case of a User Token or API Key, once it expires, the Errbot plugin will no longer have access to the st2 API.

The Errbot plugin must have valid credentials to use StackStorm's API. The credentials may be;

  • username/password
  • user token
  • api key

See https://docs.stackstorm.com/authentication.html for more details.

Username/Password

Using a username and password will allow Errbot to renew the user token when it expires. If a User Token is supplied, it will be used in preference to username/password authentication until the token expires.

User Token

To avoid using the username/password pair in a configuration file, it's possible to supply a pre-generated User Token as generated by StackStorm. Note when the token expires, a new one must be generated and updated in config.py which in turn requires Errbot to be restarted. This method is the least ideal for production environments.

API Key

API Key support has been included since StackStorm v2.0. When an API Key is provided, it is used in preference to a User Token or username/password pair. It is considered a mistake to supply a token or username/password pair when using the API Key.

How to expose action-aliases as plugin commands

  1. Connect Errbot to your chat environment.
  2. Write an action alias in StackStorm.
  3. Errbot will automatically refresh its action alias list.
  4. Type !st2help in your chat program to list available StackStorm commands.
  5. Type the desired command in your chat program, as shown in the help.

Send messages from StackStorm to Errbot using Errbot's native webhook support

Errbot has a built in web server which is configured and enabled through the bots admin chat interface. The StackStorm plugin is written to listen for StackStorm's chatops messages and delivers them to the attached chat back-end.

To configure Errbot's web server plugin, the command below can be sent to Errbot:

!plugin config Webserver {'HOST': '0.0.0.0', 'PORT': 3141,
'SSL': {'enabled': False, 'host': '0.0.0.0', 'port': 3142, 'certificate': '', 'key': ''}}

NOTE: The variables must be adjusted to match the operating environment in which Errbot is running. See Errbot documentation for further configuration information.

The configuration above is only applied for the current runtime and will not persist after the errbot process being restarted. Making the configuration change permanent is as simple as installing a special plugin:

!repos install https://github.com/tkit/errbot-plugin-webserverconfiguration

The configuration command from above is not required prior to installing this plugin.

In production environments it may be desirable to place a reverse-proxy like nginx in front of errbot.

Send notifications to Errbot from StackStorm using Server-Side Events (SSE)

As of StackStorm 1.4. server-sent events (SSE) were added which allowed chatops messages to be streamed from StackStorm to a connected listener (err-stackstorm in our case). The StackStorm stream url must be supplied in the configuration so err-stackstorm knows where to establish the http connection. The SSE configuration is complementary to the webhook method and both must be enabled for full chatops support between StackStorm and Errbot.

StackStorm Chatops pack configuration.

StackStorm's chatops pack is required to be installed and a notify rule file added to the pack.

The notify rule must be placed in /<stackstorm installation>/packs/chatops/rules. The rule file notify_errbot.yaml can be found in this repository under

Edit the chatops/actions/post_message.yaml file to use the errbot route as it's default value.

  route:
    default: "errbot"

Troubleshooting

Is the Errbot process running?

Check an instance of Errbot is running on the host

# ps faux | grep errbo[t]
root     158707  0.1  0.0 2922228 59640 pts/21  Sl+  Aug14   2:29  |   \_ /opt/errbot/bin/python3 /opt/errbot/bin/errbot -c /data/errbot/etc/config.py

Is the Errbot webhook listening?

Check Errbot's internal web server is listening on the correct interface.

# ss -tlpn | grep 158707
LISTEN     0      128                       *:8888                     *:*      users:(("errbot",158707,21))

OR

# netstat -tlpn | grep 158707
tcp        0      0 0.0.0.0:8888            0.0.0.0:*               LISTEN      158707/python3

Is the Errbot machine able to communicate with the StackStorm end points?

From the errbot machine perform a curl to the StackStorm endpoint:

curl http://<stackstorm_host>/api/v1/rules

Are the Errbot authentication credentials for StackStorm correct?

To test if the username/password pair, user token or api key supplied in the configuration is valid. In the examples below, the username for the bot is errbot.:

username/password pair

A successful username / password authentication is shown below:

$ st2 auth errbot
Password:
+----------+----------------------------------+
| Property | Value                            |
+----------+----------------------------------+
| user     | errbot                           |
| token    | 10342978da134ae5bbb7dc94d2ba9c08 |
| expiry   | 2017-09-29T14:31:20.799212Z      |
+----------+----------------------------------+

If the username and password are valid and correctly entered in errbot's configuration file, errbot will be authorised to interact with StackStorm's API/Stream end points.

user token

Test the errbot user token from the configuration using the st2 command. Make sure no environment variables are set that could provide a valid token or api key already.

$ st2 action-alias list -t 10342978da134ae5bbb7dc94d2ba9c08
+-----------------------------------+------------+---------------------------------------+---------+
| ref                               | pack       | description                           | enabled |
+-----------------------------------+------------+---------------------------------------+---------+
| packs.pack_get                    | packs      | Get information about installed       | True    |
|                                   |            | StackStorm pack.                      |         |
| packs.pack_install                | packs      | Install/upgrade StackStorm packs.     | True    |
| packs.pack_search                 | packs      | Search for packs in StackStorm        | True    |
|                                   |            | Exchange and other directories.       |         |
| packs.pack_show                   | packs      | Show information about the pack from  | True    |
+-----------------------------------+------------+---------------------------------------+---------+

If a list of action aliases are shown, the token is valid.

api key

Confirm the api key has been created and still registered with StackStorm by using it with the st2 command.

$ st2 apikey list --api-key ZzVk3DEBZ4FiZmMEmDBkM2x5ZmM5jWZkZWZjZjZmMZEwYzQwZD2iYzUyM2RhYTkTNMYmNDYNODIOOTYwMzE20A
+--------------------------+--------+-------------------------------------------+
| id                       | user   | metadata                                  |
+--------------------------+--------+-------------------------------------------+
| 586e6deadbeef66deadbeef6 | errbot | {u'used_by': u'errbot api access'}        |
+--------------------------+--------+-------------------------------------------+

Is Errbot connected correctly to the chat back-end?

How to test if the bot is connected to the chat back-end is dependant on the back-end. The simplest way is to send a message to the bot user account requesting the built in help.

E.g. Using a slack client the following command would be used /msg @bot_name !help.

The bot should respond with its help text.

bot [11:01 AM]
_All commands_

*Backup*
_Backup related commands._
• *.backup* - Backup everything.
*ChatRoom*
_This is a basic implementation of a chatroom_
• *.room join* - Join (creating it first if needed) a chatroom.
• *.room occupants* - List the occupants in a given chatroom.
• *.room invite* - Invite one or more people into a chatroom.
• *.room topic* - Get or set the topic for a room.

Is the StackStorm chatops pack installed and configured correctly?

Err-stackstorm requires the chatops pack to be installed. To confirm it is installed, use the st2 cli.

$ st2 pack list
+-------------------+-------------------+--------------------------------+---------+----------------------+
| ref               | name              | description                    | version | author               |
+-------------------+-------------------+--------------------------------+---------+----------------------+
| chatops           | chatops           | Chatops integration pack       | 0.2.0   | Kirill Enykeev       |

Confirm the notify_errbot.yaml is inside the chatops/rules directory

$ cat /opt/stackstorm/packs/chatops/rules/notify_errbot.yaml
---
name: "notify-errbot"
pack: "chatops"
enabled: true
description: "Notification rule to send results of action executions to stream for chatops"
trigger:
  type: "core.st2.generic.notifytrigger"
criteria:
  trigger.route:
    pattern: "errbot"
    type: "equals"
action:
  ref: chatops.post_result
  parameters:
    channel: "{{ trigger.data.source_channel }}"
    user: "{{ trigger.data.user }}"
    execution_id: "{{ trigger.execution_id }}"

The rule should be available via the st2 command st2 rule get chatops.notify-errbot

+-------------+--------------------------------------------------------------+
| Property    | Value                                                        |
+-------------+--------------------------------------------------------------+
| id          | 5a6b1abc5b3a0f0f5bcd54e7                                     |
| uid         | rule:chatops:notify-errbot                                   |
| ref         | chatops.notify-errbot                                        |
| pack        | chatops                                                      |
| name        | notify-errbot                                                |
| description | Notification rule to send results of action executions to    |
|             | stream for chatops                                           |
| enabled     | True                                                         |
| action      | {                                                            |
|             |     "ref": "chatops.post_result",                            |
|             |     "parameters": {                                          |
|             |         "user": "{{trigger.data.user}}",                     |
|             |         "execution_id": "{{trigger.execution_id}}",          |
|             |         "channel": "{{trigger.data.source_channel}}"         |
|             |     }                                                        |
|             | }                                                            |
| criteria    | {                                                            |
|             |     "trigger.route": {                                       |
|             |         "pattern": "errbot",                                 |
|             |         "type": "equals"                                     |
|             |     }                                                        |
|             | }                                                            |
| tags        |                                                              |
| trigger     | {                                                            |
|             |     "type": "core.st2.generic.notifytrigger",                |
|             |     "ref": "core.st2.generic.notifytrigger",                 |
|             |     "parameters": {}                                         |
|             | }                                                            |
| type        | {                                                            |
|             |     "ref": "standard",                                       |
|             |     "parameters": {}                                         |
|             | }                                                            |
+-------------+--------------------------------------------------------------+

Are events being sent via the StackStorm Stream?

From the errbot host connect to the StackStorm stream endpoint and watch for events emitted as actions are executed by StackStorm.

curl -s -v -H 'Accept: text/event-stream' -H 'X-Auth-Token: 10342978da134ae5bbb7dc94d2ba9c08' http://<stackstorm_host>/stream/v1

Are the events seen in the errbot logs using errbot as their route?

To see the events in the log, the debug level BOT_LOG_LEVEL = logging.DEBUG will need to be added to errbot's configuration file config.py.

If events are configured correctly, logs will be shown like this (st2.announcement__errbot)

17:04:12 DEBUG    root                      Dispatching st2.announcement__errbot event, 990 bytes...
17:04:12 DEBUG    lib.st2pluginapi          *** Errbot announcement event detected! ***
st2.announcement__errbot event, 990 bytes

If the announcement event is showing as

2018-01-26 15:51:55,246 DEBUG    sseclient                 Dispatching st2.announcement__chatops event, 508 bytes...

This indicates that the route wasn't set to errbot, see the Install Chatops section.

err-stackstorm's People

Contributors

chilicat avatar fmnisme avatar nzlosh avatar vutny avatar ytjohn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

err-stackstorm's Issues

user not mentioned with reply

When direct messaging bot on slack it is possible to extract api_user from the execution through
{{execution.context.api_user}}
this field looks like so from the backend:
u'api_user': u'@bwalczak',

When same message is sent from channel, bot is unable to mention user hence the reply:
'api_user': u'#botroom/bwalczak',

Implement unit tests

There's not enough unit tests in place to provide a good level of quality control.

multiple alias formats not working

I am trying to put multiple formats in single alias

following this --> https://docs.stackstorm.com/chatops/aliases.html#multiple-formats-in-a-single-alias

here's alias I've put together

---
name: "get_ip_address"
pack: "core"
description: "get_ip_address"
action_ref: "core.get_ip_address"
formats:
     - "get ip {{tag_key}} {{tag_value}} {{tag_key2}} {{tag_value2}}"
     - "get ip {{tag_key}} {{tag_value}}"
ack:
 format: "Thinking...\n Execution id: '{{execution.id}}'"
 enabled: false
 append_url: false
result:
 extra:
   slack:
     color: "#00AA00"
     pretext: "Here's your response {{execution.context.api_user}}"
     title: "title"
     text: "optional text"
 format: |
   {{ execution.result.stdout}}

when I hit !st2 get ip ec2_tag_cluster qa-blue I am getting result, but when I hit !st2 get ip ec2_tag_cluster qa-blue a b

I am getting st2 command 'get ip ec2_tag_cluster qa-blue a b' not found. Check help with !st2help

in st2help I can see two formats listed

!st2 get ip {{tag_key}} {{tag_value}} {{tag_key2}} {{tag_value2}} -- get_ip_address
!st2 get ip {{tag_key}} {{tag_value}} -- get_ip_address

Setup issues

Ubuntu 16.04 LTS

Having had no luck getting setup I decided to try this again on a clean machine without using virtualenv.

sudo apt-get install python-pip git python3-pip build-essentials cmake libffi-dev
sudo pip3 install errbot
mkdir errbot && cd errbot && errbot --init
pip3 install "errbot[slack]"
errbot

I ran the install plugin command and failed with the following output.

Output

[@CHANGE_ME ➡ @errbot] >>> !repos install https://github.com/fmnisme/err-stackstorm.git
[@CHANGE_ME ➡ @errbot] [␍]
Installing https://github.com/fmnisme/err-stackstorm.git...
Collecting st2client>=2.5.0 (from -r /home/ubuntu/errbot/data/plugins/fmnisme/err-stackstorm/requirements.txt (line 1))
  Downloading st2client-2.5.1-py2-none-any.whl (145kB)
    100% |████████████████████████████████| 153kB 2.2MB/s
Collecting sseclient-py (from -r /home/ubuntu/errbot/data/plugins/fmnisme/err-stackstorm/requirements.txt (line 2))
  Downloading sseclient_py-1.7-py2.py3-none-any.whl
Collecting jsonpath-rw>=1.3.0 (from st2client>=2.5.0->-r /home/ubuntu/errbot/data/plugins/fmnisme/err-stackstorm/requirements.txt (line 1))
  Downloading jsonpath-rw-1.4.0.tar.gz
Collecting pyyaml<4.0,>=3.11 (from st2client>=2.5.0->-r /home/ubuntu/errbot/data/plugins/fmnisme/err-stackstorm/requirements.txt (line 1))
  Downloading PyYAML-3.12.tar.gz (253kB)
    100% |████████████████████████████████| 256kB 1.5MB/s
Collecting six==1.10.0 (from st2client>=2.5.0->-r /home/ubuntu/errbot/data/plugins/fmnisme/err-stackstorm/requirements.txt (line 1))
  Downloading six-1.10.0-py2.py3-none-any.whl
Collecting python-dateutil (from st2client>=2.5.0->-r /home/ubuntu/errbot/data/plugins/fmnisme/err-stackstorm/requirements.txt (line 1))
  Downloading python_dateutil-2.6.1-py2.py3-none-any.whl (194kB)
    100% |████████████████████████████████| 194kB 1.6MB/s
Collecting requests[security]<2.15,>=2.14.1 (from st2client>=2.5.0->-r /home/ubuntu/errbot/data/plugins/fmnisme/err-stackstorm/requirements.txt (line 1))
  Downloading requests-2.14.2-py2.py3-none-any.whl (560kB)
    100% |████████████████████████████████| 563kB 1.5MB/s
Collecting prettytable (from st2client>=2.5.0->-r /home/ubuntu/errbot/data/plugins/fmnisme/err-stackstorm/requirements.txt (line 1))
  Downloading prettytable-0.7.2.zip
Collecting ply (from jsonpath-rw>=1.3.0->st2client>=2.5.0->-r /home/ubuntu/errbot/data/plugins/fmnisme/err-stackstorm/requirements.txt (line 1))
  Downloading ply-3.10.tar.gz (150kB)
    100% |████████████████████████████████| 153kB 3.8MB/s
Collecting decorator (from jsonpath-rw>=1.3.0->st2client>=2.5.0->-r /home/ubuntu/errbot/data/plugins/fmnisme/err-stackstorm/requirements.txt (line 1))
  Downloading decorator-4.2.1-py2.py3-none-any.whl
Collecting idna>=2.0.0; extra == "security" (from requests[security]<2.15,>=2.14.1->st2client>=2.5.0->-r /home/ubuntu/errbot/data/plugins/fmnisme/err-stackstorm/requirements.txt (line 1))
  Using cached idna-2.6-py2.py3-none-any.whl
Collecting cryptography>=1.3.4; extra == "security" (from requests[security]<2.15,>=2.14.1->st2client>=2.5.0->-r /home/ubuntu/errbot/data/plugins/fmnisme/err-stackstorm/requirements.txt (line 1))
  Downloading cryptography-2.1.4-cp27-cp27mu-manylinux1_x86_64.whl (2.2MB)
    100% |████████████████████████████████| 2.2MB 419kB/s
Collecting pyOpenSSL>=0.14; extra == "security" (from requests[security]<2.15,>=2.14.1->st2client>=2.5.0->-r /home/ubuntu/errbot/data/plugins/fmnisme/err-stackstorm/requirements.txt (line 1))
  Downloading pyOpenSSL-17.5.0-py2.py3-none-any.whl (53kB)
    100% |████████████████████████████████| 61kB 1.4MB/s
Collecting cffi>=1.7; platform_python_implementation != "PyPy" (from cryptography>=1.3.4; extra == "security"->requests[security]<2.15,>=2.14.1->st2client>=2.5.0->-r /home/ubuntu/errbot/data/plugins/fmnisme/err-stackstorm/requirements.txt (line 1))
  Downloading cffi-1.11.4-cp27-cp27mu-manylinux1_x86_64.whl (406kB)
    100% |████████████████████████████████| 409kB 1.6MB/s
Collecting enum34; python_version < "3" (from cryptography>=1.3.4; extra == "security"->requests[security]<2.15,>=2.14.1->st2client>=2.5.0->-r /home/ubuntu/errbot/data/plugins/fmnisme/err-stackstorm/requirements.txt (line 1))
  Downloading enum34-1.1.6-py2-none-any.whl
Collecting asn1crypto>=0.21.0 (from cryptography>=1.3.4; extra == "security"->requests[security]<2.15,>=2.14.1->st2client>=2.5.0->-r /home/ubuntu/errbot/data/plugins/fmnisme/err-stackstorm/requirements.txt (line 1))
  Using cached asn1crypto-0.24.0-py2.py3-none-any.whl
Collecting ipaddress; python_version < "3" (from cryptography>=1.3.4; extra == "security"->requests[security]<2.15,>=2.14.1->st2client>=2.5.0->-r /home/ubuntu/errbot/data/plugins/fmnisme/err-stackstorm/requirements.txt (line 1))
  Downloading ipaddress-1.0.19.tar.gz
Collecting pycparser (from cffi>=1.7; platform_python_implementation != "PyPy"->cryptography>=1.3.4; extra == "security"->requests[security]<2.15,>=2.14.1->st2client>=2.5.0->-r /home/ubuntu/errbot/data/plugins/fmnisme/err-stackstorm/requirements.txt (line 1))
Building wheels for collected packages: jsonpath-rw, pyyaml, prettytable, ply, ipaddress
  Running setup.py bdist_wheel for jsonpath-rw ... done
  Stored in directory: /home/ubuntu/.cache/pip/wheels/ff/80/3d/6d630248dd938306a8691b9658ee91e07fb794076d714f8ce8
  Running setup.py bdist_wheel for pyyaml ... done
  Stored in directory: /home/ubuntu/.cache/pip/wheels/2c/f7/79/13f3a12cd723892437c0cfbde1230ab4d82947ff7b3839a4fc
  Running setup.py bdist_wheel for prettytable ... done
  Stored in directory: /home/ubuntu/.cache/pip/wheels/b6/90/7b/1c22b89217d0eba6d5f406e562365ebee804f0d4595b2bdbcd
  Running setup.py bdist_wheel for ply ... done
  Stored in directory: /home/ubuntu/.cache/pip/wheels/ad/dd/ad/8ce1991a7b380dfe23d6cc81a4de5c2775bc728b5a0a7721aa
  Running setup.py bdist_wheel for ipaddress ... done
  Stored in directory: /home/ubuntu/.cache/pip/wheels/d7/6b/69/666188e8101897abb2e115d408d139a372bdf6bfa7abb5aef5
Successfully built jsonpath-rw pyyaml prettytable ply ipaddress
Installing collected packages: ply, decorator, six, jsonpath-rw, pyyaml, python-dateutil, idna, pycparser, cffi, enum34, asn1crypto, ipaddress, cryptography, pyOpenSSL, requests, prettytable, st2client, sseclient-py
Successfully installed asn1crypto cffi cryptography decorator enum34 idna ipaddress jsonpath-rw ply prettytable pyOpenSSL pycparser python-dateutil pyyaml-3.11 requests six-1.10.0 sseclient-py st2client
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Some plugins are generating errors:
  File "/home/ubuntu/.local/lib/python3.5/site-packages/yapsy/PluginManager.py", line 485, in loadPlugins
    candidate_module = imp.load_module(plugin_module_name,None,candidate_filepath,("py","r",imp.PKG_DIRECTORY))
  File "/usr/lib/python3.5/imp.py", line 244, in load_module
    return load_package(name, filename)
  File "/usr/lib/python3.5/imp.py", line 216, in load_package
    return _load(spec)
  File "<frozen importlib._bootstrap>", line 693, in _load
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/ubuntu/errbot/data/plugins/fmnisme/err-stackstorm/./init.py", line 2, in <module>
    from st2 import St2
  File "/home/ubuntu/errbot/data/plugins/fmnisme/err-stackstorm/st2.py", line 7, in <module>
    from lib.st2pluginapi import St2PluginAPI
  File "/home/ubuntu/errbot/data/plugins/fmnisme/err-stackstorm/lib/st2pluginapi.py", line 7, in <module>
    import sseclient
Removing /home/ubuntu/errbot/data/plugins/fmnisme/err-stackstorm as it did not load correctly.
Plugins reloaded.

From Log file

2018-01-14 08:59:20,580 DEBUG    errbot.core               *** text = !repos install https://github.com/fmnisme/err-stackstorm.git

2018-01-14 08:59:20,580 DEBUG    errbot.plugins.ACLs       Check repos_install for ACLs.
2018-01-14 08:59:20,580 INFO     errbot.plugins.ACLs       Matching ACL {} against username @CHANGE_ME for command Plugins:repos_install
2018-01-14 08:59:20,580 INFO     errbot.plugins.ACLs       Check if repos_install is admin only command.
2018-01-14 08:59:20,581 INFO     errbot.core               Processing command 'repos_install' with parameters 'https://github.com/fmnisme/err-stackstorm.git' from @CHANGE_ME
2018-01-14 08:59:20,597 DEBUG    errbot.flow               Test if the command repos_install is a trigger for an inflight flow ...
2018-01-14 08:59:20,597 DEBUG    errbot.flow               None matched.
2018-01-14 08:59:21,822 DEBUG    errbot.plugin_manager     All plugin roots:
2018-01-14 08:59:21,822 DEBUG    errbot.plugin_manager     -> /home/ubuntu/.local/lib/python3.5/site-packages/errbot/core_plugins
2018-01-14 08:59:21,822 DEBUG    errbot.plugin_manager     -> /home/ubuntu/errbot/plugins/err-example
2018-01-14 08:59:21,823 DEBUG    errbot.plugin_manager     -> /home/ubuntu/errbot/data/plugins/fmnisme/err-stackstorm
2018-01-14 08:59:21,823 DEBUG    errbot.plugin_manager     Add /home/ubuntu/errbot/data/plugins/fmnisme/err-stackstorm to sys.path
2018-01-14 08:59:21,823 DEBUG    errbot.plugin_manager     /home/ubuntu/.local/lib/python3.5/site-packages/errbot/core_plugins has no requirements.txt file
2018-01-14 08:59:21,823 DEBUG    errbot.plugin_manager     /home/ubuntu/errbot/plugins/err-example has no requirements.txt file
2018-01-14 08:59:21,823 INFO     errbot.plugin_manager     Installing packages from '/home/ubuntu/errbot/data/plugins/fmnisme/err-stackstorm/requirements.txt'.
2018-01-14 08:59:29,849 INFO     errbot                    webhooks:  Flag to bind /echo to                           echo
2018-01-14 08:59:29,869 ERROR    yapsy                     Unable to import plugin: /home/ubuntu/errbot/data/plugins/fmnisme/err-stackstorm/.
Traceback (most recent call last):
  File "/home/ubuntu/.local/lib/python3.5/site-packages/yapsy/PluginManager.py", line 485, in loadPlugins
    candidate_module = imp.load_module(plugin_module_name,None,candidate_filepath,("py","r",imp.PKG_DIRECTORY))
  File "/usr/lib/python3.5/imp.py", line 244, in load_module
    return load_package(name, filename)
  File "/usr/lib/python3.5/imp.py", line 216, in load_package
    return _load(spec)
  File "<frozen importlib._bootstrap>", line 693, in _load
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/ubuntu/errbot/data/plugins/fmnisme/err-stackstorm/./__init__.py", line 2, in <module>
    from st2 import St2
  File "/home/ubuntu/errbot/data/plugins/fmnisme/err-stackstorm/st2.py", line 7, in <module>
    from lib.st2pluginapi import St2PluginAPI
  File "/home/ubuntu/errbot/data/plugins/fmnisme/err-stackstorm/lib/st2pluginapi.py", line 7, in <module>
    import sseclient
ImportError: No module named 'sseclient'

Proposal: Out of Band chat backend user authentication

Implement an out of bands authentication mechanism over a secure channel that uses a challenge/response exchange and a One-Time use URL to exchange user credentials.

A description of the process is as follows:

  1. Chat user X@chatbackend triggers login with bot command /st2 authenticate <response string>.
  2. Err-stackstorm processes the trigger and calculates an unique ID and response hash.
  3. Err-stackstorm stores X@chatbackend identification using unique ID as key.
  4. Err-stackstorm responds via private 1to1 chat to X@chatbackend with a URL+unique ID.
  5. X@chatbackend opens a web browser (session UserX) and accesses URL+unique ID.
  6. Err-stackstorm looks up unique ID, and if it exists, presents a form requesting <response string>.
  7. UserX provides <response string> in form and submits.
  8. Err-stackstorm destroys URL reference, calculates hash from <response string> and compares with stored hash value.
  9. If hash values match a second form is presented requesting StackStorm API username/password.
  10. UserX provides username/password for StackStorm API.
  11. Err-stackstorm preforms authentication with user credentials.
  12. StackStorm API reponds with a User Token or authentication failure.
  13. Err-stackstorm discards user credentials and if authentication was successful stores User Token using UniqueID as key.
  14. Err-stackstorm sends private 1to1 to user X@chatbackend informing of authentication success/failure.

The data stored by err-stackstorm would allow using RBAC in Stackstorm by mapping a chatbackend user to a stackstorm user token. For example:

{
    "<unique id>" : {
        "response_hash": "<hash>",
        "backend_id": "U4H00PLGP",
        "st2_user_token": "3ade615c721a415eab09d092a09c1a5b",
        "authentication_date": "2017-10-10T17:39:42+0200"
    }
}

When a user calls an action alias, err-stackstorm will lookup the users backend_id and use the associated st2_user_token for all calls to StackStorm's API.

Rocketchat - error install plugin and callback

Hi I try install plugin err-stackstorm on errbot-rocketchat

I installed errbot-rocketchat with the follow link

https://github.com/cardoso/errbot-rocketchat

Rocketchat 0.65.1
Stackstorm 2.10.1
Python 3.6.7
Ubuntu 18.04
Errbot 5.2.0(edit setup.py on errbot-rocketchat before run virtualenv/bin/python setup.py install)

I have a connection between errbot and rocketchat.

I can configure plugin Webserver(add Webserver on Core_Plugins in errbot-rocketchat/src/aoikrocketchaterrbot/config.py file)

But when I try to install plugin err-stackstorm get the follow errors:

CRITICAL st2 Invalid credentials when communicating with StackStorm API.
ERROR errbot.plugin_manager Failed to execute pip install for ./bot_data/plugins/fmnisme/err-stackstorm/requirements.txt.

But the plugin and requeriments appears as installed and I can execute !st2help and commands run on Stackstorm

The problem is the callback not send to my channel on server chat, get the follow error:

12:01:59 DEBUG    aoikrocketchaterrbot      # ----- Call `callback_message` -----
12:01:59 DEBUG    errbot.core               *** frm = iperez
12:01:59 DEBUG    errbot.core               *** username = iperez
12:01:59 DEBUG    errbot.core               *** text = !st2 pack show ansible
12:01:59 DEBUG    errbot.core               Matching 'st2 pack show ansible' against '^st2 .*' produced a match
12:01:59 DEBUG    errbot.plugins.ACLs       Check st2_execute_actionalias for ACLs.
12:01:59 INFO     errbot.plugins.ACLs       Matching ACL {} against username iperez for command St2:st2_execute_actionalias
12:01:59 INFO     errbot.plugins.ACLs       Check if st2_execute_actionalias is admin only command.
12:01:59 INFO     errbot.core               Processing command 'st2_execute_actionalias' with parameters 'st2 pack show ansible' from iperez
12:01:59 DEBUG    errbot.core               Triggering callback_message on Backup
12:01:59 DEBUG    errbot.core               Triggering callback_message on Health
12:01:59 DEBUG    errbot.flow               Test if the command st2_execute_actionalias is a trigger for an inflight flow ...
12:01:59 DEBUG    errbot.core               Triggering callback_message on Help
12:01:59 DEBUG    errbot.flow               None matched.
12:01:59 DEBUG    errbot.core               Triggering callback_message on Plugins
12:01:59 DEBUG    st2                       Message received from chat backend.
		_body [<class 'str'>] pack show ansible
		_from [<class 'yapsy_loaded_plugin_AoikRocketChatErrbot_0.RocketChatUser'>] iperez
		_to [<class 'yapsy_loaded_plugin_AoikRocketChatErrbot_0.RocketChatUser'>] errbot
		_parent [<class 'NoneType'>] None
		_delayed [<class 'bool'>] False
		_extras [<class 'dict'>] {'msg_info': {'_id': '8gyZg6DvRveLXHbkv', 'rid': 'GENERAL', 'msg': '!st2 pack show ansible', 'ts': datetime.datetime(2019, 1, 16, 15, 1, 59, 622000, tzinfo=datetime.timezone.utc), 'u': {'_id': 'qsWobD2XnNokYJWyo', 'username': 'iperez', 'name': 'iperez'}, 'mentions': [], 'channels': [], '_updatedAt': datetime.datetime(2019, 1, 16, 15, 1, 59, 625000, tzinfo=datetime.timezone.utc)}}
		_flow [<class 'NoneType'>] None
		ctx [<class 'dict'>] {}


12:01:59 DEBUG    errbot.core               Triggering callback_message on Utils
12:01:59 DEBUG    lib.st2pluginapi          Create st2 client with https://172.17.0.2 https://172.17.0.2/api/v1 {'token': '2fc3fd8127144cbd90c58c812f2ff99b'}
12:01:59 DEBUG    errbot.core               Triggering callback_message on ACLs
12:01:59 DEBUG    errbot.core               Triggering callback_message on Webserver
12:01:59 DEBUG    requests.packages.urllib3 Starting new HTTPS connection (1): 172.17.0.2
12:01:59 DEBUG    errbot.core               Triggering callback_message on St2
/home/ivan/.local/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py:852: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)
12:01:59 DEBUG    requests.packages.urllib3 https://172.17.0.2:443 "POST /api/v1/actionalias/match HTTP/1.1" 200 1526
12:01:59 DEBUG    lib.st2pluginapi          Create st2 client with https://172.17.0.2 https://172.17.0.2/api/v1 {'token': '2fc3fd8127144cbd90c58c812f2ff99b'}
12:01:59 DEBUG    lib.st2pluginapi          Execution: ['pack show ansible', 'pack show {{ pack }}', 'pack_show', 'iperez', 'errbot', 'iperez', 'iperez']
12:01:59 DEBUG    requests.packages.urllib3 Starting new HTTPS connection (1): 172.17.0.2
/home/ivan/.local/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py:852: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)
12:01:59 DEBUG    requests.packages.urllib3 https://172.17.0.2:443 "POST /api/v1/aliasexecution HTTP/1.1" 201 6665
12:01:59 DEBUG    st2                       action alias execution result: type=<class 'str'> Something is happening ... 
12:01:59 DEBUG    errbot.flow               Test if the command st2_execute_actionalias is a trigger for an inflight flow ...
12:01:59 DEBUG    errbot.flow               None matched.
12:01:59 DEBUG    errbot.flow               Test if the command st2_execute_actionalias is an auto-trigger for any flow ...
12:01:59 DEBUG    sseclient                 Dispatching st2.liveaction__create event, 508 bytes...
12:01:59 DEBUG    sseclient                 Dispatching st2.execution__create event, 2649 bytes...
12:01:59 DEBUG    sseclient                 Dispatching st2.liveaction__update event, 508 bytes...
12:01:59 DEBUG    sseclient                 Dispatching st2.execution__update event, 2718 bytes...
12:01:59 DEBUG    sseclient                 Dispatching st2.liveaction__update event, 544 bytes...
12:02:01 DEBUG    sseclient                 Dispatching st2.execution__update event, 2821 bytes...
12:02:01 DEBUG    sseclient                 Dispatching st2.liveaction__update event, 1244 bytes...
12:02:01 DEBUG    sseclient                 Dispatching st2.execution__update event, 3633 bytes...
12:02:01 DEBUG    sseclient                 Dispatching st2.liveaction__create event, 611 bytes...
12:02:01 DEBUG    sseclient                 Dispatching st2.execution__create event, 5251 bytes...
12:02:01 DEBUG    sseclient                 Dispatching st2.liveaction__update event, 611 bytes...
12:02:01 DEBUG    sseclient                 Dispatching st2.execution__update event, 5320 bytes...
12:02:01 DEBUG    sseclient                 Dispatching st2.liveaction__update event, 647 bytes...
12:02:01 DEBUG    sseclient                 Dispatching st2.execution__update event, 5423 bytes...
12:02:01 DEBUG    sseclient                 Dispatching st2.liveaction__update event, 697 bytes...
12:02:01 DEBUG    sseclient                 Dispatching st2.liveaction__update event, 711 bytes...
12:02:01 DEBUG    sseclient                 Dispatching st2.execution__update event, 5543 bytes...
12:02:01 DEBUG    sseclient                 Dispatching st2.liveaction__create event, 687 bytes...
12:02:02 DEBUG    sseclient                 Dispatching st2.execution__create event, 2946 bytes...
12:02:02 DEBUG    sseclient                 Dispatching st2.liveaction__update event, 687 bytes...
12:02:02 DEBUG    sseclient                 Dispatching st2.execution__update event, 3015 bytes...
12:02:02 DEBUG    sseclient                 Dispatching st2.liveaction__update event, 723 bytes...
12:02:02 DEBUG    sseclient                 Dispatching st2.execution__update event, 3118 bytes...
12:02:02 DEBUG    sseclient                 Dispatching st2.liveaction__update event, 1703 bytes...
12:02:02 DEBUG    sseclient                 Dispatching st2.execution__update event, 4210 bytes...
12:02:02 DEBUG    sseclient                 Dispatching st2.liveaction__update event, 711 bytes...
12:02:02 DEBUG    sseclient                 Dispatching st2.execution__update event, 5571 bytes...
12:02:02 DEBUG    sseclient                 Dispatching st2.liveaction__create event, 1539 bytes...
12:02:02 DEBUG    sseclient                 Dispatching st2.execution__create event, 4291 bytes...
12:02:02 DEBUG    sseclient                 Dispatching st2.liveaction__update event, 1539 bytes...
12:02:02 DEBUG    sseclient                 Dispatching st2.execution__update event, 4360 bytes...
12:02:02 DEBUG    sseclient                 Dispatching st2.liveaction__update event, 1575 bytes...
12:02:02 DEBUG    sseclient                 Dispatching st2.execution__update event, 4463 bytes...
12:02:02 DEBUG    sseclient                 Dispatching st2.announcement__errbot event, 965 bytes...
12:02:02 DEBUG    lib.st2pluginapi          *** Errbot announcement event detected! ***
st2.announcement__errbot event, 965 bytes

12:02:02 DEBUG    lib.st2adapters           Posting Message: whisper=False, message=Getting back to you about the `ansible` pack: {~}
Here's the full index entry at StackStorm Exchange: ```author: StackStorm, Inc.
content:
  actions:
    count: 8
    resources:
    - command_local
    - galaxy.list
    - playbook
    - vault.decrypt
    - vault.encrypt
    - galaxy.install
    - command
    - galaxy.remove
  tests:
    count: 1
    resources:
    - test_actions_lib_ansiblebaserunner.py
description: st2 content pack containing ansible integrations
email: [email protected]
keywords:
- ansible
- cfg management
- configuration management
name: ansible
ref: ansible
repo_url: https://github.com/StackStorm-Exchange/stackstorm-ansible
version: 0.5.5

To install the pack: `pack install ansible`
If the pack is already installed, I will upgrade it to the latest version, keeping the config.
, user=iperez, channel=iperez, extra={}
12:02:02  CRITICAL lib.st2pluginapi          St2 stream listener - An error occurred: <class 'ValueError'> Argument `in_reply_to` must be given..Backing off 10 seconds.

My errbot-rocketchat/src/aoikrocketchaterrbot/config.py file

# coding: utf-8
"""
Errbot config module.

Config options:
https://github.com/errbotio/errbot/blob/master/errbot/config-template.py
"""
from __future__ import absolute_import

# Standard imports
from datetime import datetime
import logging


# Backend name
BACKEND = 'AoikRocketChatErrbot'

# Data directory containing data of backends and plugins
BOT_DATA_DIR = './bot_data'

# Directory containing extra backends
BOT_EXTRA_BACKEND_DIR = './backends'

# Directory containing extra plugins
BOT_EXTRA_PLUGIN_DIR = './plugins'

# Admin bot user names
BOT_ADMINS = ('iperez')

# Core plugin names
CORE_PLUGINS = ('ACLs', 'Backup', 'Health', 'Help', 'Plugins', 'Utils', 'Webserver')

# Log file path
BOT_LOG_FILE = './errbot.log'

# Logging level
BOT_LOG_LEVEL = logging.DEBUG

STACKSTORM = {
    'auth_url': 'https://172.17.0.2/auth/v1',
    'api_url': 'https://172.17.0.2/api/v1',
    'stream_url': 'https://172.17.0.2/stream/v1',

    'verify_cert': False,
    'api_auth': {
        'user': {
            'name': 'admin',
            'password': "changeme",
        },
        'token': "2fc3fd8127144cbd90c58c812f2ff99b",
        'key': 'NjNjNWIzYmI1ZThjMWIwNTM0NzM0NWJjNGNmNmJhNzAyYWI3ZWNmY2UxZDY1OGJjODVmYTVmY2NjMTJkMjUwZQ'
    },
    'timer_update': 600, #  Unit: second.  Interval for Errbot to refresh to list of available action aliases.
}

class AOIKROCKETCHATERRBOT_CONFIG(object):
    """
    Config object for AoikRocketChatErrbot.

    Config values can be overridden by env variables. Config key `SERVER_URI`
    maps to env variable name `AOIKROCKETCHATERRBOT_SERVER_URI`. Use string
    '0', 'false' or 'no' to mean boolean false in env variable value.
    """

    # Meteor server URI.
    #
    # Required.
    #
    # E.g.: 'ws://127.0.0.1:3000/websocket'
    #
    SERVER_URI = 'ws://127.0.0.1:3000/websocket'

    # Meteor client login username.
    #
    # Required.
    #
    LOGIN_USERNAME = 'errbot'

    # Meteor client login password.
    #
    # Required.
    #
    LOGIN_PASSWORD = 'errbot'

    # Whether patch meteor client to fix an existing bug.
    #
    # Default is true.
    #
    PATCH_METEOR_CLIENT = True

    # Whether reconnect is enabled.
    #
    # Default is true.
    #
    RECONNECT_ENABLED = True

    # Whether heartbeat is enabled.
    #
    # If enabled, a specified heartbeat function will be called at a specified
    # interval.
    #
    # Default is false.
    #
    HEARTBEAT_ENABLED = False

    # Heartbeat interval in seconds.
    #
    # Default is 10.
    #
    HEARTBEAT_INTERVAL = 10

    # Create heartbeat function
    @classmethod
    def _heartbeat_func(cls, backend):
        """
        Heartbeat function.

        :param backend: Backend object.

        :return: None.
        """
        # Create message
        msg = 'Heartbeat: {}'.format(datetime.now().strftime('%H:%M:%S'))

        # Send message
        backend.send_rocketchat_message(
            params={
                # Room ID
                'rid': 'GENERAL',
                # Message
                'msg': msg,
            }
        )

    # Heartbeat function object.
    #
    # The function takes the backend object as argument.
    #
    # Required if config `HEARTBEAT_ENABLED` is true.
    #
    HEARTBEAT_FUNC = _heartbeat_func

    # Logging level for this backend only
    BOT_LOG_LEVEL = logging.DEBUG

I need the function ACL to limit action-alias to chat channels/users and server chat on-premise

MESSAGE_SIZE_LIMIT not honoured

Hi there,
It seems that MESSAGE_SIZE_LIMIT is not honoured for st2 responses. I was able to test it by making an action that returns large output and set MESSAGE_SIZE_LIMIT=100.
Result was cut in the middle (afaik Slack defaults to 4k characters)

Is this repo under active maintenance?

Hi @nzlosh

I have found out that you started active development and fixing issues in your own repo at https://github.com/nzlosh/err-stackstorm

Just want to check here, would you plan to keep maintaining this repository, to port changes, accept issues or contributions and so on?
I'm asking primarily because if I would like to create new bleeding edge StackStorm+Errbot deployment, which plugin is better to pick up?

Thank you for your dedication to this awesome project!

Fix SSL certificate verification.

SSL verification is implemented inconsistently in the plugin and doesn't handle dev/poc cases where an SSL certificate is self-signed but the user wishes to continue regardless.

Installation documentation missing chatops pack step

When setting up a new installation, errbot depends on the chatops pack being installed before copying the errbot rule file into the pack directory. This step isn't included in the documentation and needs to be fixed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.