How to Setup Slack Notifications for Low Disk Space On Your Server | 2021

You probably want to know when your server is running out of disk space. An easy solution is to configure the cron job to run daily and send a notification to Slack if there is a problem.

Get disk space with df command

Seeing disk space on Linux is the df -h (For output in human readable format):

It lists each mounted file system on how large the physical disk is, and how much is being used.

To limit the output to a specific file system (in this case, root) you can run df /. However, it returns the header row, so you can filter it grep:

Then, select the fifth column (percent) with awk, And remove the percent sign symbol sed. This gives you a command that shows how full your main disk is:

df / | grep / | awk '{ print $5}' | sed 's/%//g'

Which, in this case, will come back “39“. If you want to change the disk to be monitored by this command, you must first edit df Statement.

Configure command line slack notifications

The easiest way to make slack notifications work With webhook. Webhooks allow you to send notifications in the form of POST requests to URLs without having to manage bot users or OAuth. You can format messages as JSON and post them using curl.

Slack’s. From Api portal, Create a new app, select your workspace to add it and give it a name. It will appear when it sends you a message, so choose something interesting.

Once you get your app, find the “Incoming Webhooks” tab under “Add Features and Functionality”.

This will let you create a new webhook, and you have to choose which channel it should post on. You can create a new channel for bot notifications, or add it to your own DM.

Once you have the URL, copy the sample request to verify that it works. “Hello world!” Must see. In the channel you select. If so, it is good to go to Slack.

Put it all together

In order for your server to actually notify you, you will create a script that you a. Can run with daily cron work. Here is the script’s shell, minus the notification command:

#!/bin/bash
CURRENT=$(df / | grep / | awk '{ print $5}' | sed 's/%//g')
THRESHOLD=90

if [ "$CURRENT" -gt "$THRESHOLD" ] ; then

fi

This script sets two variables, CURRENT (For output of df Order from above) and THRESHOLD (For a value you can configure). It then checks if the current value exceeds the threshold, and runs a command if it is.

You can set the notification any way you want, but here is an example — the webhook URL is not included, which you will have to paste at the end (no additional flag is required):

curl -X POST -H 'Content-type: application/json' --data "{"text":"Your server `$(hostname)` is currently at ${CURRENT}% disk capacity."}"

This will send a well-formatted information to the specified channel of your webhook, including the server’s hostname and current disk capacity.

You can paste this command into if The above script statement, which brings the whole thing together:

#!/bin/bash
CURRENT=$(df / | grep / | awk '{ print $5}' | sed 's/%//g')
THRESHOLD=90

if [ "$CURRENT" -gt "$THRESHOLD" ] ; then
curl -X POST -H 'Content-type: application/json' --data "{"text":"Your server `$(hostname)` is currently at ${CURRENT}% disk capacity."}"
fi

Save as diskspace.sh In your home directory, and make sure it has execution permissions chmod +x diskpace.sh. Open your crontab with crontab -e, And add the following line to the end:

0 * * * * ~/diskspace.sh

This will run your script every hour to check if your disk is full. But you will get notifications only when it is full, so you can check whether the script works by setting THRESHOLD Below current disk usage and running it manually.

For more detailed information, you can send the result to the script df -h, Well formatted in a code box, just by updating curl Statement:

curl -X POST -H 'Content-type: application/json' --data "{"text":"Your server `$(hostname)` is currently at ${CURRENT}% disk capacity.n ```$(df -h)``` "}"

Which will look like this in Slack:

Since the command to run the script can be anything you want, you can also configure email notifications using postfix such as mail handlers or any other feed that supports webhooks.

translate,google translate,tradutor,переводчик,traduction,google traduction,google tradutor,traduttore,,Apple, Google, Wal-Mart, IBM,GE,Coca-ColaVerizonAT&T,zillow,netflix,meowingtons,pch publishers clearing,filly fare,colourpop,,julie’s freebies,amazon prime video,boohoo.com,zaful,walmart,real country ladies,adt,stephan speaks relationships,acidmath,inner light media,burn 20,campbell’s,falken tyres,adobe video,dhgate,cricut the offcial,,,,youtube,facebook,amazon,gmail,google,yahoo,yahoo mail,weather,netflix,walmart,ebay,google translate,home depot,usps tracking,translate,craigslist,fox news,google docs,news,google maps,google classroom,roblox,cnn,lowes,calculator,amazon prime,paypal,speed test,hotmail,target,google drive,msn,instagram,zillow,twitter,best buy,aol mail,bank of america,wells fargo,maps,hulu,discord,ups tracking,trump,traductor,costco,reddit,indeed,disney plus,you tube,usps,pinterest,thank you coronavirus helpers,espn,etsy,linkedin,facebook login,twitch,doodle for google,nfl,dow jones,fedex tracking,capital one,chase,aol,kohls,dominos,airbnb,nba,harbor freight,spotify,bing,internet speed test,womens world cup 2019,wayfair,nfl scores,outlook,you,walgreens,finance,entertainment,solitaire,pizza hut,google flights,crestaurants near me,menards,youtube to mp3,macys,google news,xfinity,face,turbotax,amazon prime video,pandora,timer,yahoo finance,zoom,sports,verizon,,zaful,nitto tyres,c ufc fight pass,nikon instruments,skrewball whiskey,cameo,stremlabs,watkins,netbase quid,cswig life,sonubaits,visiting angels, JOY CHO / OH JOY!,MARYANN RIZZO,MASHABLE,PEUGEOT PANAMA,SALESFORCE,LONELY PLANET,,#translate,#google translate,#tradutor,#переводчик,#traduction,#google traduction,#google tradutor,#traduttore,c#Apple,# Google,# Wal-Mart,# IBM,#GE,cVerizon,AT&T,#zillow,#netflix,#meowingtons,c#filly fare,#colourpop,#,#julie’s freebies,#amazon prime video,c#zaful,#walmart,#real country ladies,#adt,#stephan speaks relationships,c#inner light media,#burn 20,#campbell’s,#falken tyres,#adobe video,c#cricut the offcial,#,#,#,#youtube,c#amazon,#gmail,#google,#yahoo,#yahoo mail,c#netflix,#walmart,#ebay,#google translate,#home depot,c#translate,#craigslist,#fox news,#google docs,#news,c#google classroom,#roblox,#cnn,#lowes,#calculator,c#paypal,#speed test,#hotmail,#target,#google drive,c#instagram,#zillow,#twitter,#best buy,#aol mail,c#wells fargo,#maps,#hulu,#discord,#ups tracking,c#traductor,#costco,#reddit,#indeed,#disney plus,c#usps,#pinterest,#thank you coronavirus helpers,#espn,#etsy,c#facebook login,#twitch,#doodle for google,#nfl,#dow jones,c#capital one,#chase,#aol,#kohls,#dominos,c#nba,#harbor freight,#spotify,#bing,#internet speed test,c#wayfair,#nfl scores,#outlook,#you,#walgreens,c#entertainment,#solitaire,#pizza hut,#google flights,#google scholar,c#menards,#youtube to mp3,#macys,#google news,#xfinity,c#turbotax,#amazon prime video,#pandora,#timer,#yahoo finance,c#sports,#verizon,#,#zaful,#nitto tyres,c# ufc fight pass,#nikon instruments,#skrewball whiskey,#cameo,#stremlabs,c#netbase quid,#petlab co,#swig life,#sonubaits,#visiting angels,c#MARYANN RIZZO,#MASHABLE,#PEUGEOT PANAMA,#SALESFORCE,#LONELY PLANET,AFFILIATES DISCLAIMERDISCLAIMERWEBSITE DISCLAIMERThe information provided https://varor.in/ and our mobile application is for general informational purposes only. All information on the Site and our mobile application is provided in good faith, however we make no representation or warranty of any kind, express or implied, regarding the accuracy, adequacy, validity, reliability, availability or completeness of any information on the Site or our mobile application. UNDER NO CIRCUMSTANCE SHALL WE HAVE ANY LIABILITY TO YOU FOR ANY LOSS OR DAMAGE OF ANY KIND INCURRED AS A RESULT OF THE USE OF THE SITE OR OUR MOBILE APPLICATION OR RELIANCE ON ANY INFORMATION PROVIDED ON THE SITE AND OUR MOBILE APPLICATION. YOUR USE OF THE SITE AND OUR MOBILE APPLICATION AND YOUR RELIANCE ON ANY INFORMATION ON THE SITE AND OUR MOBILE APPLICATION IS SOLELY AT YOUR OWN RISK.EXTERNAL LINKS DISCLAIMERThe Site and our mobile application may contain (or you may be sent through the Site or our mobile application) links to other websites or content belonging to or originating from third parties or links to websites and features in banners or other advertising. Such external links are not investigated, monitored, or checked for accuracy, adequacy, validity, reliability, availability or completeness by us. WE DO NOT WARRANT, ENDORSE, GUARANTEE, OR ASSUME RESPONSIBILITY FOR THE ACCURACY OR RELIABILITY OF ANY INFORMATION OFFERED BY THIRD-PARTY WEBSITES LINKED THROUGH THE SITE OR ANY WEBSITE OR FEATURE LINKED IN ANY BANNER OR OTHER ADVERTISING. WE WILL NOT BE A PARTY TO OR IN ANY WAY BE RESPONSIBLE FOR MONITORING ANY TRANSACTION BETWEEN YOU AND THIRD-PARTY PROVIDERS OF PRODUCTS OR SERVICES.PROFESSIONAL DISCLAIMERThe Site cannot and does not contain blogger advice. The blogger information is provided for general informational and educational purposes only and is not a substitute for professional advice. Accordingly, before taking any actions based upon such information, we encourage you to consult with the appropriate professionals. We do not provide any kind of blogger advice. THE USE OR RELIANCE OF ANY INFORMATION CONTAINED ON THIS SITE OR OUR MOBILE APPLICATION IS SOLELY AT YOUR OWN RISK.AFFILIATES DISCLAIMERThe Site and our mobile application may contain links to affiliate websites, and we receive an affiliate commission for any purchases made by you on the affiliate website using such links. Our affiliates include the following:ClickbankCJ Affiliate by ConversantMaxBountyShareASaledigisotre24semrushwarriour plusclickbankTESTIMONIALS DISCLAIMERThe Site may contain testimonials by users of our products and/or services. These testimonials reflect the real-life experiences and opinions of such users. However, the experiences are personal to those particular users, and may not necessarily be representative of all users of our products and/or services. We do not claim, and you should not assume, that all users will have the same experiences. YOUR INDIVIDUAL RESULTS MAY VARY. The testimonials on the Site are submitted in various forms such as text, audio and/or video, and are reviewed by us before being posted. They appear on the Site verbatim as given by the users, except for the correction of grammar or typing errors. Some testimonials may have been shortened for the sake of brevity where the full testimonial contained extraneous information not relevant to the general public.The views and opinions contained in the testimonials belong solely to the individual user and do not reflect our views and opinions. We are not affiliated with users who provide testimonials, and users are not paid or otherwise compensated for their testimonials.

24 thoughts on “How to Setup Slack Notifications for Low Disk Space On Your Server | 2021

  • June 13, 2021 at 9:23 am
    Permalink

    Great work! That is the type of info that are supposed to be shared
    around the web. Disgrace on the seek engines for now not positioning this put up higher!
    Come on over and consult with my website . Thank you =)

  • June 13, 2021 at 10:04 pm
    Permalink

    Incredible! This blog looks just like my old one! It’s on a
    totally different topic but it has pretty much the
    same layout and design. Great choice of colors!

    My homepage: zielinki01

  • June 13, 2021 at 11:18 pm
    Permalink

    An outstanding share! I have just forwarded this onto a
    colleague who was conducting a little homework on this. And he in fact ordered me
    lunch due to the fact that I stumbled upon it for him…
    lol. So let me reword this…. Thanks for the meal!!
    But yeah, thanks for spending time to discuss this matter here on your internet site.

    Feel free to surf to my blog :: zielinki01

  • June 14, 2021 at 12:20 am
    Permalink

    I blog often and I seriously thank you for your information. The article has truly peaked my interest.
    I will bookmark your site and keep checking for new details about
    once a week. I subscribed to your RSS feed too.

    Feel free to surf to my site: zielinki01

  • June 14, 2021 at 12:59 am
    Permalink

    Saved as a favorite, I really like your website!

    My website: zielinki01

  • June 14, 2021 at 1:12 am
    Permalink

    This is very interesting, You are a very skilled blogger.
    I’ve joined your feed and look forward to seeking more of your great post.
    Also, I have shared your website in my social networks!

    My web site :: zielinki01

  • June 14, 2021 at 6:50 am
    Permalink

    It’s an remarkable article for all the online users; they will take benefit from it I am sure.

    Here is my web-site; zielinki01

  • June 15, 2021 at 8:12 am
    Permalink

    I think that is one of the such a lot important info for me.

    And i’m satisfied reading your article. However wanna observation on some normal things,
    The web site taste is great, the articles is really excellent :
    D. Excellent job, cheers betflix

  • June 16, 2021 at 4:41 am
    Permalink

    Does your blog have a contact page? I’m having problems locating it but,
    I’d like to shoot you an e-mail. I’ve got some ideas
    for your blog you might be interested in hearing. Either way, great site and I look forward to seeing it develop over time.
    wmคาสิโน ทางเข้า

  • June 17, 2021 at 3:50 pm
    Permalink

    Hi, this weekend is nice designed for me, since this point in time i am reading this wonderful
    educational article here at my residence. Ppslot

  • June 17, 2021 at 4:20 pm
    Permalink

    Wonderful beat ! I wish to apprentice while you amend your
    site, how can i subscribe for a blog web site? The account
    aided me a acceptable deal. I had been tiny bit acquainted of
    this your broadcast offered bright clear idea

  • June 17, 2021 at 5:59 pm
    Permalink

    Ahaa, its pleasant conversation regarding this article at this place at this website, I
    have read all that, so at this time me also commenting here.

  • June 17, 2021 at 8:13 pm
    Permalink

    You actually make it seem really easy with your presentation but I find this topic to be really something which I believe I’d never understand.
    It seems too complex and extremely wide for me. I’m taking a look forward in your next post, I’ll try to get the hold of
    it!

  • June 18, 2021 at 1:28 pm
    Permalink

    Today, while I was at work, my cousin stole my iphone and tested to see
    if it can survive a 40 foot drop, just so she can be a youtube sensation. My apple ipad is now destroyed and she has 83 views.

    I know this is entirely off topic but I had to share it with someone!

    Slot Pp

  • June 18, 2021 at 3:57 pm
    Permalink

    I do not even know the way I stopped up here, however I believed this submit used to be
    great. I do not understand who you are but certainly
    you are going to a well-known blogger for those who aren’t already.
    Cheers!

  • June 18, 2021 at 5:59 pm
    Permalink

    There is definately a great deal to know about this subject.
    I love all the points you have made.

  • June 19, 2021 at 6:44 am
    Permalink

    Excellent article. I certainly appreciate this website.

    Keep writing!

  • June 19, 2021 at 9:19 am
    Permalink

    Hi there, yes this piece of writing is actually fastidious and I have learned lot of things from it about blogging.

    thanks. wmคาสิโน

  • June 19, 2021 at 6:42 pm
    Permalink

    Hey I know this is off topic but I was wondering
    if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates.
    I’ve been looking for a plug-in like this for quite
    some time and was hoping maybe you would have some experience with something like this.
    Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.

  • June 19, 2021 at 8:17 pm
    Permalink

    It’s really a nice and helpful piece of info. I’m glad that you just
    shared this helpful info with us. Please stay us up to
    date like this. Thanks for sharing.

  • June 19, 2021 at 8:29 pm
    Permalink

    I was able to find good info from your blog articles.

  • June 19, 2021 at 11:09 pm
    Permalink

    I am regular visitor, how are you everybody?

    This article posted at this web page is actually fastidious.

  • June 20, 2021 at 1:45 pm
    Permalink

    Superb blog! Do you have any tips for aspiring
    writers? I’m hoping to start my own blog soon but I’m a little lost on everything.
    Would you recommend starting with a free platform like WordPress or go for a paid
    option? There are so many choices out there that
    I’m totally confused .. Any ideas? Appreciate it!

Comments are closed.

close