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

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

48783fcaf907ac381b37ecc33ed9e761?s=47 strviola
January 15, 2020

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

48783fcaf907ac381b37ecc33ed9e761?s=128

strviola

January 15, 2020
Tweet

More Decks by strviola

Other Decks in Programming

Transcript

  1. 4MBDL0QT͸͡Ί·ͨ͠ ॳ৺ऀ޲͚TMBDLOPUJpFSͷجຊ ϦϯΧʔζגࣜձࣾླ໦ཽଠ

  2. ຊ೔ͷ໨࣍  TMBDLOPUJpFSHFNͷ঺հ  ॳظઃఆ  "1*ͷ঺հ  4MBDL0QTͷ͋Δ࢓ࣄ 

    ·ͱΊͱࠓޙͷ՝୊
  3. 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" }
  4. ॳظઃఆ  w 8FCIPPL63-ͷऔಘ w IUUQTTMBDLDPNBQQT"'9%6";JODPNJOHXFCIPPLTʹΞΫηε w ϫʔΫεϖʔεɺ౤ߘઌνϟϯωϧͳͲઃఆ w 63-͸ઃఆը໘͔Β͍ͭͰ΋֬ೝߋ৽Մೳ

  5. ॳظઃఆ  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
  6. "1*ͷ঺հ  color pretext title title_link fields[0] fields[1] footer title

    title value value
  7. "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
  8. ·ͱΊ w TMBDLOPUJpFSHFNͷ঺հ w 8FCIPPL63-ͷऔಘํ๏ w "1*ͷ঺հ w ࠓޙͷ՝୊ w

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