Giter Club home page Giter Club logo

cloudflare-analytics-notification's Introduction

Cloudflare Analytics Notification

GitHub GitHub top language GitHub last commit

A python script that sends a daily webhook notification (Discord message) with the most recent Cloudflare analytics for your website.

Cloudflare API Repo: python-cloudflare

In order for this to work...

  • You need to be using Cloudflare on your website
  • You need to have a chat app that supports webhooks (i use discord)
  • A web server to automate running the script

Configuring the python script...

You will need to change the 3 variables at the bottom of the script

email = 'email_of_Cloudflare_account'
token = 'global_API_Key_for_Cloudflare_account'
webhookurl = 'webhook_URL_to_send_message(i_use_Discord)'

Accessing your Cloudflare Global API key

  • Login to Cloudflare
  • Head over to My Profile -> API Tokens -> API Keys -> VIEW Global API Key (enter your password and copy key). Make sure to keep this key private, its the password to your account though the API.

Creating a Webhook and getting the URL

I will show an example using Discord but this is possible with any app that uses webhooks.

  • Login to Discord using on Desktop or Browser (does not work on mobile).
  • Click on the Discord server you want to send these messages too.
  • Go to Server Settings -> Integrations -> View Webhooks -> either New Webhooks or click on an existing one and copy the Webhook URL

Running the Python script

You can use any computer to run the script on as long as python is installed but to get the most automation out of it I will be running this script on my Linux web server.

  • Make sure to pip install any new libraries and know where python is installed. For me python is installed at #!/usr/bin/python but yours may be different such as #!/usr/bin/env/python. This is line is specified at the top of the python script.

On Linux

If you are using a Linux web server and have python installed you just need to upload the configured script to the server make it executable and run it daily. In order to run the script daily I use crontab.

Make script executable
  • First we need to make the file executable. 'chmod a+x /example/file/path/CloudflareAnalyticsNotification.py
  • Now run the script by typing in the path of the file to see if it is working properly. python /example/file/path/CloudflareAnalyticsNotification.py
Configure crontab
  • To access crontab type crontab -e
  • Start a new line and configure the crontab timing, I chose to run the script once per day at 8pm, use this website crontab.guru if you want to configure it differently.
  • After settings the timing enter the path of the python file /example/file/path/CloudflareAnalyticsNotification.py
  • Save and exit crontab
  • The crontab job should look similar to the picture
00 20 * * * /home/mannix/python/CloudflareAnalyticsNotifications.py

Discord Message Example

cloudflare-analytics-notification's People

Contributors

jacobmannix avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.