Skip to content

Instantly share code, notes, and snippets.

@shimajima-eiji
Last active October 15, 2018 10:34
Show Gist options
  • Save shimajima-eiji/ed5b27eeb47181613abbdf04222f567c to your computer and use it in GitHub Desktop.
Save shimajima-eiji/ed5b27eeb47181613abbdf04222f567c to your computer and use it in GitHub Desktop.
# システム監視スクリプトを実行していてアラートが発生した時に動かす
# server.shは動かしておくこと
apt install curl
curl http://localhost:8000/send?message=$1
#!/usr/bin/env python3
import hug
@hug.get('/send')
def send(mes):
from server import send
send.execute(mes)

python_webapi

Usage

https://nomuraya.work/techzine/0191

  • run server.sh(WebAPI server)
    • hug -f (run_hug.py)
  • monitoring node
    • cron? driven. -> client.sh

client.sh

view latest

# システム監視スクリプトを実行していてアラートが発生した時に動かす
# server.shは動かしておくこと
apt install curl
curl http://localhost:8000/send?message=$1

endpoint.py

view latest

#!/usr/bin/env python3
import hug

@hug.get('/send')
def send(mes):
    from server import send
    send.execute(mes)

server.sh

view latest

# need: python3
# https://nomuraya.work/develop/cmd/python
pip3 install hug

#after create process (run_hug.py)
hug -f (run_hug.py)

server_send.py

view latest

# coding: utf-8
# server/send.py

def execute(message):
  import requests, json
  WEB_HOOK_URL = "(Slack Incomming Web hook URL)"
  requests.post(WEB_HOOK_URL, data = json.dumps({
    'text': 'user action :{}'.format(message),
    'usern

back

# need: python3
# https://nomuraya.work/develop/cmd/python
pip3 install hug
#after create process (run_hug.py)
hug -f (run_hug.py)
# coding: utf-8
# server/send.py
def execute(message):
import requests, json
WEB_HOOK_URL = "(Slack Incomming Web hook URL)"
requests.post(WEB_HOOK_URL, data = json.dumps({
'text': 'user action :{}'.format(message),
'usern
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment