#!/usr/bin/perl -w ############################################################################### # HCCServerinfo.pm - A custom API module for CPanel # Version 0.1.2 beta - 11/MAY/2005 # (c) 2003, 2005 Juan R. Pozo # http://html.conclase.net/cp/scripts/ # mailto:jrpozo@conclase.net # Mailing-list: http://www.conclase.net/mailman/listinfo/cpanel_conclase.net ############################################################################### # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 2 of the License, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################### # For INSTALLATION and DOCUMENTATION please see: # http://html.conclase.net/cp/scripts/HCCServerinfo.txt (plain text), or # http://html.conclase.net/cp/scripts/HCCServerinfo.pdf (Acrobat) ############################################################################### # Please consider making a donation today. Visit my amazon.com wishlist at: # http://html.conclase.net/link/wishlist # Thank you :) ############################################################################### package Cpanel::HCCServerinfo; use strict; use vars qw(@ISA @EXPORT $VERSION $prefix); require Exporter; @ISA = qw(Exporter); @EXPORT = qw( HCCServerinfo_init HCCServerinfo_status ); $VERSION = '0.1.2'; $prefix = "HCCServerinfo"; Cpanel::Lang::loadlang($Cpanel::CPDATA{LANG}); require 5.004; sub HCCServerinfo_init { return(1); } sub HCCServerinfo_status { # Available options are: services, memory, swap, load, partitions my @options = @_; my $up; foreach (@options) { if (/^\s*['"]?\s*services\s*['"]?\s*$/i) { my ($message, $icon, $status); opendir(SRV, "/var/run/chkservd") or die($!); my @srvs = grep { -f "/var/run/chkservd/$_" } readdir(SRV); closedir(DIR); foreach my $srv (sort @srvs) { open(SRV, "; close(SRV); if (defined($up) && $up) { $message = "ServiceUp"; $icon = "ServiceUpIcon"; $status = "StatusOK"; } else { $message = "ServiceDown"; $icon = "ServiceDownIcon"; $status = "StatusAlert"; } print "\n"; print "$srv\n"; print "" . lang($message) . "\n"; print "\""\n"; print "\n"; } } elsif (/^\s*['"]?\s*memory\s*['"]?\s*$/i) { my @free = `/usr/bin/free`; foreach my $line (@free) { if ($line =~ /^-\/\+ buffers\/cache:\s+(\d+)\s+(\d+)/) { my $icon = "MemoryIconOK"; my $status = "StatusOK"; print "\n"; print "" . lang("MemoryUsed") . "\n"; print ""; printf("%.2f\%", 100*$1/($1+$2)); print "\n"; if ($1/($1+$2) >= 0.75) { $icon = "MemoryIconAlert"; $status = "StatusAlert"; } elsif ($1/($1+$2) >= 0.5) { $icon = "MemoryIconWarning"; $status = "StatusWarning"; } print "\""\n"; print "\n"; last; } } } elsif (/^\s*['"]?\s*swap\s*['"]?\s*$/i) { my @free = `/usr/bin/free`; foreach my $line (@free) { if ($line =~ /^Swap:\s+(\d+)\s+(\d+)/) { my $icon = "SwapIconOK"; my $status = "StatusOK"; print "\n"; print "" . lang("SwapUsed") . "\n"; print ""; printf("%.2f\%", 100*$2/$1); print "\n"; if ($2/$1 >= 0.8) { $icon = "SwapIconAlert"; $status = "StatusAlert"; } elsif ($2/$1 >= 0.5) { $icon = "SwapIconWarning"; $status = "StatusWarning"; } print "\""\n"; print "\n"; last; } } } elsif (/^\s*['"]?\s*load\s*['"]?\s*$/i) { my $load = `cat /proc/loadavg`; my $icon = "LoadIconOK"; my $status = "StatusOK"; if ($load =~ /^(\S+)/) { print "\n"; print "" . lang("ServerLoad") . "\n"; print ""; printf("%.2f", $1); print "\n"; if ($1 >= 1) { $icon = "LoadIconAlert"; $status = "StatusAlert"; } elsif ($1 >= 0.8) { $icon = "LoadIconWarning"; $status = "StatusWarning"; } print "\""\n"; print "\n"; } } elsif (/^\s*['"]?\s*partitions\s*['"]?\s*$/i) { my @df = `/bin/df`; my $icon = "PartitionIconOK"; my $status = "StatusOK"; foreach my $line (@df) { if ($line =~ /\/dev\/(\S+)\s+\d+\s+\d+\s+\d+\s+([^\%]+)\%\s+(\S+)/) { print "\n"; print "" . lang("HCCPartition") . " $1 ($3)\n"; print ""; print "$2\%\n"; if ($2 >= 90) { $icon = "PartitionIconAlert"; $status = "StatusAlert"; } elsif ($2 >= 80) { $icon = "PartitionIconWarning"; $status = "StatusWarning"; } print "\""\n"; print "\n"; } } } } } sub lang { my ($key) = @_; return $Cpanel::Lang::LANG{$Cpanel::CPDATA{LANG}}{"${prefix}_${key}"}; } 1;