shimajima-eiji
10/11/2018 - 8:22 AM

python_webapi: [https://nomuraya.work/techzine/0191, https://shimajima-eiji.github.io/gist/python_webapi/]

# 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
# need: python3
# https://nomuraya.work/develop/cmd/python
pip3 install hug

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

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

#!/usr/bin/env python3
import hug

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

python_webapi

Usage

https://nomuraya.work/techzine/0191

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