Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: multiple machines disk space alert

by thanos1983 (Parson)
on Feb 21, 2017 at 11:58 UTC ( [id://1182423]=note: print w/replies, xml ) Need Help??


in reply to multiple machines disk space alert

Hello vikas330 ,

I think you are looking for this (Perl script to monitor disk space and send an email)?

Relevantly (disk check using perl).

Hope this helps.

Seeking for Perl wisdom...on the process of learning...not there...yet!

Replies are listed 'Best First'.
Re^2: multiple machines disk space alert
by vikas330 (Novice) on Feb 21, 2017 at 12:33 UTC
    Hello Thanos1983, Thanks for quick reply and suggestions. It really helps me a lot. But I need to print the output <need to check FS on mutliple machines and include all FS having more than 80% utilization> in tabular format in mail. So can you please help me in that. Thank you so much.

      Hello vikas330,

      Let's take the questions one by one:

      <FS having more than 80% utilization>: The link that I provided you (Perl script to monitor disk space and send an email) provides you the ability to set your own utilization limit. Sample of code based on description from link:

      # warning level 10% my $warning_level=10; # compare free disk space with warning level if ($df_free < $warning_level) { my $out = sprintf("Send an Email - Disk space on $dir => %0.2f%% (WARN +ING Low Disk Space)\n",$df_free); print $out; } else { my $out = sprintf("Disk space on $dir => %0.2f%% (OK)\n",$df_free); print $out; }

      In your case you can set the value to 20 instead of 10, this will mean that if the disk utilization will reach 80% then an email will be sent to you.

      <need to check FS on mutliple machines>: Regarding the multiple machines, here you could have to options. First and simplest option, apply this script on all machines you want to check the FS utilization on a cron tab as described on the link. Sample of description from link:

      You can run this script as a cron job: @hourly /path/to/df.pl

      By doing so each machine will email you separately in case that you have exceeded 80% utilization.

      In case that this is not what you really want to have as I suspect, then you need to do a bit of coding. I would write a script that can ssh on all machines and apply df -h, df -P or install the Filesys::DiskSpace which I find extremely useful and retrieve the data and compare them based on your threshold value (e.g. 80%).

      I prefer to use the module Net::OpenSSH::Parallel which can create multiple parallel ssh connections and retrieve all data. I have some samples of codes into an old question of mine (Best module to execute administrator commands on external operating systems (Linux)) where you will find samples of code for (Net::Telnet, Net::SSH, Net::OpenSSH and Net::SSH::Perl) if I remember correctly all will do your task executing bash commands remotely through ssh and telnet.

      In case of multiple machines you can create a simple loop where you ssh each machine separately and and collect data separately.

      As I said as up to you to play around and see what fits your criteria and how much you want to code.

      Regarding the tabular format hippo provided you multiple links where you can read and implement.

      Hope this is a more complete answer to your question.

      Seeking for Perl wisdom...on the process of learning...not there...yet!
        Hello thanos1983,

        Thanks for the detailed suggestion, sure I'm going through the links you have provided and trying to do the coding. It helps me a lot.

        Thank you so much.

      Hmm, putting data into tabular format is easy. Getting it right in an e-mail at the other end might be more complicated, especially if Outlook (or another mail reader) changes the font or unilaterally decides to reformat it.

      Maybe using HTML mail format is the way to go.

      Update: fixed a typo.

        Hello Laurent_R,

        Thanks for the suggesstion.

        Yes, you are right, HTML will help me geting the output in tabular format.

        Thank you so much.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1182423]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-25 22:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found