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

Slack-Ops始めました 初心者向け "slack-notifier" の基本

strviola
January 15, 2020

Slack-Ops始めました 初心者向け "slack-notifier" の基本

strviola

January 15, 2020
Tweet

More Decks by strviola

Other Decks in Programming

Transcript

  1. TMBDLOPUJpFSHFNͷ঺հ w IUUQTHJUIVCDPNTUFWFOPTMPBOTMBDLOPUJpFS w ཁ͢Δʹ)BTIΛ+40/ʹͯ͠)5511045ͯ͘͠ΕΔ # Gemfile gem 'slack-notifier' #

    test.rb require 'slack-notifier' notifier = Slack::Notifier.new('WEBHOOK_URL') notifier.ping 'Hello World' # POST https://hooks.slack.com/services/... # Content-type: application/json # { "text": "Hello World" }
  2. ॳظઃఆ  w 8FCIPPL63-ͷอଘ w DPOpHTFDSFUTZNMFOD͕ແ೉ w ڞ௨Ϋϥε͔Βݺͼग़͠ ฐࣾ͸"QQMJDBUJPO3FDPSE 

    w BUUBDINFOUT͸"1*ʹ౉͢+40/ # app/models/application_record.rb def slack_webhook_url Rails.application.secrets.slack_webhook_url end def slack_post!(attachments:, webhook_url: slack_webhook_url, username: 'LFB bot') return if webhook_url.blank? notifier = Slack::Notifier.new(webhook_url, username: username) notifier.post attachments: attachments end
  3. "1*ͷ঺հ  # app/models/contact.rb def slack_notify!(host, title: '͓٬༷͔Β໰͍߹Θ͕ͤ͋Γ·ͨ͠ɻ') url_helper =

    Rails.application.routes.url_helpers attachment = { color: '#1155A7', pretext: '<!channel>', title: title, title_link: url_helper.system_managers_contact_url(self, host: host), fields: [ { title: 'ۜߦ໊', value: Bank.current.name }, { title: '͓٬༷ࢯ໊', value: "#{user.name}༷" } ], footer: "#{Rails.env} environment" } slack_post! attachments: [attachment] end
  4. ·ͱΊ w TMBDLOPUJpFSHFNͷ঺հ w 8FCIPPL63-ͷऔಘํ๏ w "1*ͷ঺հ w ࠓޙͷ՝୊ w

    ϋοϐʔʹͳΕΔ4MBDL0QT ໰͍߹ΘͤରԠ͚ͩͩͱؾ͕໓ೖΔ  4MBDLಋೖ͸ΰʔϧ͡Όͳ͍ɺελʔτͩ