-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from lamhoangtung/mattermost
Switch Microsoft Teams webhook to Mattermost webhook
- Loading branch information
Showing
11 changed files
with
89 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# pylint: disable=missing-module-docstring | ||
from .main import setup_ssh, loop_forever | ||
from .main import loop_forever, setup_ssh | ||
|
||
__all__ = ('setup_ssh', 'loop_forever') # pragma: no cover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,46 @@ | ||
"""Send push notification to Microsoft Teams using webhook. Just to manage all the instance""" | ||
"""Send push notification to Mattermost Channel using webhook. Just to manage all the instance""" | ||
|
||
import json | ||
import os | ||
from typing import Dict | ||
|
||
import pymsteams | ||
import requests | ||
|
||
COLAB_USER_NAME = 'colab' | ||
COLAB_USER_ICON_LINK = 'https://colab.research.google.com/img/colab_favicon_256px.png' | ||
|
||
def send_notification_to_microsoft_teams(webhook_address: str, spec: Dict): | ||
|
||
def send_notification_to_mattermost(webhook_address: str, spec: Dict[str, str]): | ||
""" | ||
Send push notification to Microsoft Teams using webhook. Just to manage all the instance | ||
Send push notification to Mattermost using webhook. Just to manage all the instance | ||
""" | ||
|
||
message = pymsteams.connectorcard(webhook_address) | ||
text = "" | ||
if os.environ.get("IS_TESTING_CI") is not None: | ||
message.text( | ||
"Hi @channel, a new CI/CD test for the colab ssh pip package was initialized! Here was it configuration:") | ||
text += "Hi @channel, a new CI/CD test for the Colab SSH pip package was initialized! Here was it configuration:" | ||
else: # pragma: no cover | ||
message.text( | ||
"Hi @channel, a new colab spot instance was created! Here was it configuration:") | ||
|
||
section = pymsteams.cardsection() | ||
section.addFact("CPU", spec['cpu']) | ||
section.addFact("RAM", spec['ram']) | ||
section.addFact("GPU", spec['gpu']) | ||
section.addFact("Hostname", spec['hostname']) | ||
section.addFact("Connection command", spec['ssh_command']) | ||
message.addSection(section) | ||
text += "Hi @channel, a new Colab spot instance was created :tada::tada::tada:! Here was it configuration:" | ||
text += "\n\n" | ||
text += f"| **CPU** | {spec['cpu']} |\n" | ||
text += f"|--------------|----------------------------------------------------------------|\n" | ||
text += f"| **RAM** | {spec['ram']} |\n" | ||
text += f"| **GPU** | {spec['gpu']} |\n" | ||
text += f"| **Hostname** | `{spec['hostname']}` |\n" | ||
text += "\n" | ||
text += "To **connect** to it, use the following configuration in your `~/.ssh/config` file:\n" | ||
text += f"```ssh-config\n{spec['ssh_config']}\n```\n" | ||
text += "Don't forget to **comment** to this post to **claim your colab instance** now, these thing don't really grow on tree ;). ***Happy coding!***\n" | ||
payload = { | ||
"username": COLAB_USER_NAME, | ||
"icon_url": COLAB_USER_ICON_LINK, | ||
"text": text | ||
} | ||
payload = json.dumps(payload) | ||
headers = { | ||
'Content-Type': 'application/json' | ||
} | ||
try: | ||
message.send() | ||
except Exception as exception: # pylint: disable=broad-except | ||
print(f"Error sending notification to Microsoft Teams: {exception}") | ||
response = requests.request( | ||
"POST", webhook_address, headers=headers, data=payload) | ||
response.raise_for_status() | ||
except Exception as ex: | ||
print(f"Cannot send notification to Mattermost: {ex}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,28 @@ | ||
#!/usr/bin/env python | ||
import os | ||
from setuptools import setup, find_packages | ||
__version__ = "0.1.4" | ||
|
||
from setuptools import find_packages, setup | ||
|
||
def readme(): | ||
with open(os.path.join(os.path.dirname(__file__), 'README.md')) as f: | ||
return f.read() | ||
|
||
__version__ = "0.1.5" | ||
|
||
def parse_requirements(filename): | ||
""" load requirements from a pip requirements file """ | ||
lineiter = (line.strip() for line in open(filename)) | ||
return [line for line in lineiter if line and not line.startswith("#")] | ||
|
||
def read_me(): | ||
with open(os.path.join(os.path.dirname(__file__), 'README.md')) as f: | ||
return f.read() | ||
|
||
install_requires = parse_requirements('requirements.txt') | ||
|
||
setup( | ||
name="linus_colab_ssh", | ||
version=__version__, | ||
description='Create SSH tunel to a running colab notebook', | ||
long_description=readme(), | ||
long_description=read_me(), | ||
long_description_content_type='text/markdown', | ||
url='https://github.com/lamhoangtung/colab_ssh', | ||
author='Hoang Tung Lam', | ||
author_email='[email protected]', | ||
include_package_data=True, | ||
packages=find_packages( | ||
exclude=["*.tests", "*.tests.*", "tests.*", "tests"]), | ||
install_requires=install_requires, | ||
keywords=['ssh', 'colab'], | ||
setup_requires=[], | ||
dependency_links=[], | ||
|
@@ -41,5 +34,7 @@ def parse_requirements(filename): | |
'License :: OSI Approved :: MIT License', | ||
'Programming Language :: Python :: 3.6', | ||
'Programming Language :: Python :: 3.7', | ||
'Programming Language :: Python :: 3.8', | ||
'Programming Language :: Python :: 3.9', | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters