This is a Slack bot built to help users interact with AWS and OpenStack cloud resources through simple commands. The bot can create OpenShift clusters in AWS and virtual machines in OpenStack etc etc. It can connect to JIRA and Jenkins to perform some tasks.It also provides helpful information when mentioned or through direct messages.
- Infrastructure commands: Handles the infrastructure create tasks with different cloud providers : AWS, AZURE, GCP etc.
- JIRA & other tool commands: Handle JIRA commands and other jenkins/ci job trigger commands.
- Help Command: The bot responds with a list of available commands when mentioned with the word
help. - Other commands: Commands to display important team links, trigger a tool/job etc.
- Message Handling: The bot can respond to messages and mentions, providing helpful information or performing actions based on user input.
- Common slack SDK python module : we are building a common slack backend python module which is opensource and can be installable and reusable . Planning to push to pypi public python registry available to all.
- API interface using above module : we are also building an api wrapper around the SDK . This can be deployed an independet app and provides same integrations that we are using in slackbot . This will be helpful to have same functionality with other apps such as google chat etc.
- Slack Bolt for Python: Framework for building Slack apps.
- AWS SDK (Boto3): Interact with AWS services like EC2 and ROSA.
- OpenStack SDK: Interact with OpenStack resources.
- Python 3.x: The language used for development.
- Python 3.12
- Slack App with
SLACK_BOT_TOKENandSLACK_APP_TOKEN - AWS account with
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEY - OpenStack credentials (
OS_AUTH_URL,OS_PROJECT_NAME,OS_INTERFACE,OS_ID_API_VERSION,OS_REGION_NAME,OS_APP_CRED_ID,OS_APP_CRED_SECRET,OS_AUTH_TYPE) - AZURE
- GCP
- JIRA
- JENKINS
git clone https://github.com/openshift-sustaining/ocp-sustaining-bot.git
cd ocp-sustaining-bot
It's recommended to use a virtual environment to manage dependencies:
python3 -m venv .venv
source .venv/bin/activatepip install -r requirements.txtCreate a .env file in the root directory and add your Slack and cloud credentials you received from admin:
SLACK_BOT_TOKEN=xoxb-your-slack-bot-token
SLACK_APP_TOKEN=xapp-your-slack-app-token
AWS_ACCESS_KEY_ID=your-aws-access-key-id
AWS_SECRET_ACCESS_KEY=your-aws-secret-access-key
AWS_DEFAULT_REGION=us-west-2
OS_AUTH_URL=https://your-openstack-auth-url
OS_PROJECT_NAME=your-openstack-project-name
.
.
.python slack_main.pycreate-aws-cluster <cluster_name> Creates an AWS OpenShift cluster using the provided cluster_name.
aws vm create Creates an AWS EC2 instance.
Sample usage:
aws vm create --os_name=linux --instance_type=t2.micro --key_pair=new
aws vm create --os_name=linux --instance_type=t2.micro --key_pair=existing
aws vm list Lists AWS EC2 instances
Sample usage:
aws vm list --state=pending,running,shutting-down,terminated,stopping,stopped
aws vm list --type=t3.micro,t2.micro
aws vm list --type=t3.micro,t2.micro --state=pending,stopped
aws vm list --instance-ids=i-123456,i-987654
Note 1: The list of parameters that can be passed using the --type subcommand is extremely large. See https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2/client/describe_instances.html for the complete list. Search for t2.micro
openstack vm create
Creates an OpenStack VM with the specified name, os type, flavor, network and key name.
Sample usage:
openstack vm create --name=PAYMENTGATEWAY1 --os_name=fedora --flavor=ci.cpu.small --network=provider_net_ocp_dev --key_name=sustaining-bot-key
/aws vm modify --stop --vm-id=<instance_id> Stops a specific AWS EC2 instance by its instance ID. The instance can be restarted later.
/aws vm modify --delete --vm-id=<instance_id> Deletes a specific AWS EC2 instance by its instance ID.
openstack vm list Lists OpenStack VMs.
Sample usage:
openstack vm list -status=ACTIVE
openstack vm list -status=ERROR
hello Greets the user with a friendly message.
help Lists the available commands and how to use them.
The bot responds to the following events:
Direct Messages: Responds to DMs with helpful information. Mentions: If the bot is mentioned in a message, it can respond with a message or trigger an action.
Skills required for contributsions are the basic python coding , cloud providers SDK , jira and jekins integration knowledge . Even if you dont have it we can learn and do it.
Feel free to fork the repository and submit pull requests. Contributions are welcome!
- Fork this repository
- Create a new branch (git checkout -b feature-branch)
- Do the changes and make sure you lint and format the code using ruff tool.
- Install Ruff :
pip install ruff - Check code quality :
ruff format --check . - Format the code :
ruff format . --respect-gitignore
- Install Ruff :
- Commit your changes (git commit -am 'Add new feature')
- Push to the branch (git push origin feature-branch)
- Create a new Pull Request
- There is a dev slack bot namely : ocp-sustaining-bot is already created . Please get those credentials along with other cloud credentials of the slack bot.
- There is a testing slack workspace created : slackbot-template.slack.com . Please get your user/mail added to this by the admin.
- Make sure you add your local .env file with all secrets to the repo root.
- Once you have your code changes ready then run the code locally using
python slack_main.py - Then from the slackbot template workspace run your command by mention or direct message to test.
Please refer to the below google docs https://docs.google.com/document/d/1D_efhIfCjikWhoY43WqJOOe25DEKsWeXIbmEpqkFJfo/edit?tab=t.0 I will have those tasks added under our sustaining jira project soon.
-
A build pipeline called "Create Docker Image for Slackbot" will create the docker image and push it to the registry
quay.io/ocp_sustaining_engineering/slack_backendwhich is also open source. -
It runs as a docker container inside
project-toolsVM in our openstack cluster. -
Troubleshooting tips : Get the key of that server from admin to login . Then use below or similar commands to explore.
Docker container commands : To check if container is running or killed :
docker ps -aDocker run command :
docker run -d --name slack_backend --env-file /root/sec/.env --restart unless-stopped quay.io/ocp_sustaining_engineering/slack_backend:1.0.1To trace logs :
docker logs -f slack_backendIncrease the log:
update root/sec/.env and set LOG_LEVEL=DEBUG . Then stop the container and restart it with above mentioned run command.