RSS scraping with Python and passing new items to Slack using Webhooks

So my use case is that I wanted new Red Hat Errata published at to be sent to one of our Slack channels. However the above url contains all errata and I´m only interested in critical errata to keep down the noise in the slack channel.

* First step is to create a slack webhook, visit: . Add the new webhook to the webhook variable in the script below. Also change channel name, etc in the payload variable.
* Next you need save the script to your linux box, lets create directory /usr/local/bin/errata-to-slack .
* I´m also using a library called feedparser to parse the RSS: , download it and place it in the same directory as your script.
* Next you need to touch the datafile /var/lib/rhn-errata.txt which will hold a list of errata already sent to slack. If you will run the script as another user than root, you will need to chown the datafile to the correct user.

#!/usr/bin/env python                                                                                                                                               
import feedparser                                                                                                                                                   
import json                                                                                                                                                         
import os                                                                                                                                                           
import sys                                                                                                                                                          
import requests                                                                                                                                                     
d = feedparser.parse('')                                                                                                
webhook = ''                                                                           
for post in d.entries:                                                                                                                                              
  if post.title.find('Critical:') > 0:                                                                                                                              
    f = open(datafile, 'r+')                                                                                                                                        
    if post.title not in                                                                                                                                  
      payload = {                                                                                                                                                   
        'text': post.title + ": " + + "\n"                                                                                                                
      payload['channel'] = "#alerts"                                                                                                                                
      payload['username'] = "alerts"                                                                                                                                
      payload['icon_emoji'] = "ghost"                                                                                                                               
        res =, data=json.dumps(payload))                                                                                                      
      except Exception as e:                                                                                                                                        
        sys.stderr.write('An error occurred when trying to deliver the message:\n  {0}'.format(e.message))                                                          
      if res.ok:                                                                                                                                                    

Leave a Reply

Your email address will not be published. Required fields are marked *