Upgrade to Pro — share decks privately, control downloads, hide ads and more …

20190307_Pythonの勉強がてら死活監視ツールを作った話

 20190307_Pythonの勉強がてら死活監視ツールを作った話

Pythonの勉強 がてら死活監視ツールを作った話. 2019/3/7にとらのあな主催のLT用に作成したスライド。 PythonとRaspberry Pi(申し訳程度)を 使って自社サービスの監視ツールについて話します。

More Decks by 虎の穴ラボ株式会社

Other Decks in Programming

Transcript

  1.       Python  ! 

       1 2019/03/07 OSC LT Python ! Copyright © 2019 Toranoana Inc. All Rights Reserved.
  2. 3 0 3 0 3 0 3 0 3 0

    3 0 2&1 2 Copyright © 2019 Toranoana Inc. All Rights Reserved. " <'% - *),! <76 8/ ,!. 45<JavaJavaScript #  <( +  <:  $ ; < 9
  3. # ! # ! # ! # ! # !

    # ! 3 Copyright © 2019 Toranoana Inc. All Rights Reserved.   • Python ? •  % " • $ • &   • 
  4.          

      Python?    JavaJavaScript   ↓     4 Copyright © 2019 Toranoana Inc. All Rights Reserved.
  5.          

      Python ?     5 Copyright © 2019 Toranoana Inc. All Rights Reserved. https://ec.toranoana.shop/tora/ec/item/200011766934/ https://ec.toranoana.shop/tora/ec/item/200011606097/
  6.          

      Python?  Raspberry Pi    Raspberry Pi Python 6 Copyright © 2019 Toranoana Inc. All Rights Reserved.
  7.          

      Python?  Mac  Raspberry Pi   7 Copyright © 2019 Toranoana Inc. All Rights Reserved.
  8.          https://toranoana-keeper.com/

    8 Copyright © 2019 Toranoana Inc. All Rights Reserved.
  9. 3 0 3 0 3 0 3 0 3 0

    3 0 -./4 %2 9 Copyright © 2019 Toranoana Inc. All Rights Reserved. Web) AP) DB) nginx' nginxhttp https !" ,*(5&7  KEEPER6 Rails' $ !$ #+1 MySQL' $ $+ 1
  10.       10 Copyright © 2019

    Toranoana Inc. All Rights Reserved. Web AP DB Web  http://toranoana-keeper.com/ HTTP   HTTP301   
  11.       11 Copyright © 2019

    Toranoana Inc. All Rights Reserved. Web AP DB AP  https://toranoana-keeper.com/ (TOP )  HTTP200 !   
  12. # # # # # # 12 Copyright © 2019

    Toranoana Inc. All Rights Reserved. Web AP DB DB  https://toranoana-keeper.com/search (! ) GET:'search[q]'='aaaa'  HTTP200 & % $"
  13.       13 Copyright © 2019

    Toranoana Inc. All Rights Reserved. Web AP DB "   slack"  !
  14. ! ! ! ! ! ! "#$ #pyenv  #

    $ $ pyenv install 3.6.8 $ pyenv local 3.6.8 #HTTP Requests  $pip install requests #Raspberry Pi (Mac  ) $ pip install RPi.GPIO 14
  15. " " " " " " %(Web  ) import

    requests #Web  (allow_redirects=False     $ ) url = "http://toranoana-keeper.com/" r = requests.get(url,allow_redirects=False) print (r.status_code, r.reason) ↓#! 301 Moved Permanently 15
  16.        (AP) import requests

    #AP url = "https://toranoana-keeper.com/" r = requests.get(url) print (r.status_code, r.reason) ↓  200 OK 16
  17.        (DB) import requests

    #DB url = "https://toranoana-keeper.com/search" r = requests.get(url,params={'search[q]': 'aaaa'}) print (r.status_code, r.reason) ↓  200 OK 17
  18.       (slack) #slack def post_slack(

    message ): print(message) slack_url = 'https://hooks.slack.com/services/***/***/*** payload_dic = { 'username': '  ', 'text': message } requests.post(slack_url, data=json.dumps(payload_dic)) 18
  19.        19

  20. ! ! ! ! ! ! #() #&(*'  )

    def main_unit():#1" num = 0 while True: num+= 1 try: if( num % 60 == 0): print(test_keeper( num ))#    finally: time.sleep( 1 ) l_tika( num % 2 == 0 )#%Raspberry Pi$ (L ) if( num > 3600 ): num = 0 20
  21.       (L ) import RPi.GPIO

    as GPIO GPIO.setmode(GPIO.BCM) # GPIO GPIO.setup(2, GPIO.OUT) # GPIO  #    L def l_tika( boo ): GPIO.output(2, boo) # GPIO ON/OFF 21
  22.        22

  23.        23

  24.        24 

  25.          

          25 # VScode  sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8') sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8') VScode CodeRunner  US-ASCII     
  26. ?= ?= ?= ?= ?= ?= 26 Linux(Raspberry Pi)3 ".+

    Mac065 C 65  -7:<D  git push/pull E2 -Linux;#.(,Mac389#.(,; .mac#%!;dammy_demon0 4' !$/30<D@  -Raspberry Pi;)&)*.1;' !$ Mac3dammy_demon3 >BA 
  27. CA CA CA CA CA CA  27 *#$ G/1K

    H@ OS:2 >BG/E L%+')Raspberry PiGPIOG/M *I57,-LED6  <D ;   ?893F=(+&$"+!J 4.0