Skip to main content

Blog Post

Application Monitoring Using Slack Webhooks

by Bobby Gryzynger
July 29, 2020

Here at Mediacurrent, we use Slack for, well...just about everything. From talking shop on project teams to weekly knowledge share discussions, Slack forms the backbone of communications for our distributed team. That’s why on a recent project, when we had the need to monitor daily site cron jobs, posting these updates to a Slack channel felt like a natural solution. It prevented us from needing to log into a server to determine if a job ran successfully and provided visibility to the entire project team—if a job failed, everyone on the project team would be aware. Bonus points: it was surprisingly easy. 

Here’s what we did. First, we created a Slack channel specifically for project alerts. This prevented the project’s main channel from getting cluttered with messages on a daily basis. Next, we asked our Slack administrator to allow us to register an incoming Slack webhook. An incoming webhook allows you to send a message to a specific Slack channel, so when we registered the webhook, we selected our project’s alerts channel. Finally, at the beginning and end of our automated jobs we made a call to a PHP function: 

function send_slack_alert($message) {
  $ch = curl_init(getenv('SLACK_WEBHOOK_URL'));
  $data = ['text' => $message];
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
  curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-type: application/json',
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));

And what was the result? 

If everything went as planned, we called the function with a message such as: send_slack_alert(‘:thumbsup: Everything is A-OK. Carry on!’) and the project team received the reassuring message: 

👍  Everything is A-OK. Carry on!

And if things didn’t go quite as planned, we called the function with something like: send_slack_alert(‘:thumbsdown: Uh-oh, something went wrong. Better check the logs!’) and the project team received a call to action:

👎  Uh-oh, something went wrong. Better check the logs!

Either way, the project team was aware of whether or not a job completed successfully, and in the event of a problem, we would be the first ones to know.

One of the specific use-cases that we sent alerts for was automated archiving of content. The archiving job occurred at an off-peak time, in the wee-hours of the morning, and most days everything went as expected and we started our days off with a nice, big thumbs up. On the rare occasion that there was a problem, we were immediately notified and could intervene to analyze what caused the job to fail and step in to restart it manually. This made for a happy project team and a happy client because no one came to find days or weeks later that a critical automated behavior was failing on a regular basis, buried deep in the logs. 

All in all, Slack webhooks provide an easy and lightweight solution for application monitoring. They are painless to set up and leverage the communication tools that your project team is already comfortable with. The next time you need to add visibility to a project that relies on automated behaviors, consider integrating a Slack webhook into your application monitoring stack.

Meet team member, Bobby Gryzynger

Bobby is technologist with a strong background in art, media, and design creating his keen eye for Drupal Development. He enjoys expanding Drupal's reach by integrating external data into Drupal-based applications and has worked on huge projects including a faculty publications database at NYU whose data he integrated into a Drupal site.

He first started exploring web development as an undergraduate media production student looking to create a web presence for himself. He started with a simple, static HTML and CSS site and began adding more and more features. This sparked an interest in computer science and he began taking introductory programming and data structures courses. He continued studying computer science as a graduate art student, where he explored graphics and micro-controller programming while completing a software-based master's thesis project. After graduate school, he worked for a small NYC agency building static and CMS-based websites, but it wasn't until he took a job with NYU that he was introduced to Drupal. While at NYU, he managed over a dozen Drupal 7 and 8 sites and played a large role in developing custom modules and DevOps workflows. His desire to further contribute to the Drupal community and build his Drupal expertise led him to join Mediacurrent.

Outside of work, Bobby enjoys playing tennis and during his master's thesis, he took an interest in blowing glass and created 100 hand-blown, tungsten-filament light bulbs. He is also a new homeowner and enjoys working on home improvement projects including some landscaping, hardwood floor refinishing and wainscoting projects.

Learn more about Bobby >

Related Insights