Koozali.org: home of the SME Server

monitoring status of disk redundacy and server uptime more simply

Offline electroman00

  • ****
  • 491
  • +0/-0
Re: monitoring status of disk redundacy and server uptime more simply
« Reply #30 on: June 11, 2009, 01:34:26 AM »
Ok this is pretty basic on the fly.

Code: [Select]
#!/bin/bash

# System Status web page generator

##### Initialize variables
f_path=/home/e-smith/files/primary/html/serverstatus/
RIGHT_NOW=$(date +"%x %r %Z")
TIME_STAMP="Updated on $RIGHT_NOW by $USER"

##### Functions (all must preceed Main program code)

function system_info
{
    echo "<h2>System release info</h2>"
    echo "<p>Function not yet implemented</p>"

}   # end of system_info


function show_uptime
{
    echo "<h2>System uptime</h2>"
    echo "<pre>"
    uptime
    echo "</pre>"

}   # end of show_uptime

function show_raid
{
    echo "<h2>Raid Status</h2>"
    echo "<pre>"
    cat /proc/mdstat
    echo "</pre>"

}   # end of show_uptime


function drive_space
{
    echo "<h2>Filesystem space</h2>"
    echo "<pre>"
    df
    echo "</pre>"

}   # end of drive_space


function write_page1
# Write page in HTML format
{
TITLE="System Information for $HOSTNAME"
    cat <<- _EOF_
    <html>
        <head>
        <title>$TITLE</title>
        </head>
        <body>
        <h1>$TITLE</h1>
        <p>$TIME_STAMP</p>
        $(system_info)
        $(show_uptime)
        $(drive_space)
$(show_raid)
        </body>
    </html>
_EOF_

}

function write_page2
{
# Write page in HTML format
TITLE="Raid Information for $HOSTNAME"

    cat <<- _EOF_
    <html>
        <head>
        <title>$TITLE</title>
        </head>
        <body>
        <h1>$TITLE</h1>
        <p>$TIME_STAMP</p>
        $(show_uptime)
$(show_raid)
        </body>
    </html>
_EOF_

}

function write_page3
{
# Write page in text format .prn
TITLE="Raid Information for $HOSTNAME"
echo $TITLE
cat /proc/mdstat

}

##### Main Program Code

 # create & change to status directory if not exist
 
 if [ ! -d $f_path ]; then
 echo "===== MKDIR >>" $f_path
 mkdir -p $f_path
 fi

# Write page (comment out until testing is complete)

filename=system_page.html
write_page1 > $fpath$filename
 
filename=raid_status.html
write_page2 > $fpath$filename
 
filename=raid_status.prn
write_page3 > $fpath$filename


Creates 3 files in f_path=/home/e-smith/files/primary/html/serverstatus/

system_page.html
 
raid_status.html
 
raid_status.prn

Could you imagine if I was good at this??



Offline electroman00

  • ****
  • 491
  • +0/-0
Re: monitoring status of disk redundacy and server uptime more simply
« Reply #31 on: June 11, 2009, 01:43:00 AM »
Now here's a problem with this, it's not dynamic data.

IOW the data is only relevant to the time stamp.

To make it dynamic you would need to change lang to Perl for example and write a wrapper to run the code on page load.

However this should get you started.

Offline electroman00

  • ****
  • 491
  • +0/-0
Re: monitoring status of disk redundacy and server uptime more simply
« Reply #32 on: June 11, 2009, 01:49:10 AM »
Well another way is javascript.

Whatever floats the boat. :smile:

Offline purvis

  • ****
  • 567
  • +0/-0
Re: monitoring status of disk redundacy and server uptime more simply
« Reply #33 on: June 11, 2009, 01:57:29 AM »
Thanks, i have lots of boats living in Louisiana, USA and i can swim when i need to. lol

Offline electroman00

  • ****
  • 491
  • +0/-0
Re: monitoring status of disk redundacy and server uptime more simply
« Reply #34 on: June 11, 2009, 02:02:21 AM »
If you find yourself taking on water give a holler, we'll through you a life persevere.

Anyway did it work for ya?

Offline electroman00

  • ****
  • 491
  • +0/-0
Re: monitoring status of disk redundacy and server uptime more simply
« Reply #35 on: June 11, 2009, 02:27:31 AM »
Hey just found a booboo, last few lines.....

Code: [Select]
filename=system_page.html
write_page1 > $fpath$filename
 
filename=raid_status.html
write_page2 > $fpath$filename
 
filename=raid_status.prn
write_page3 > $fpath$filename

change to

Code: [Select]
filename=system_page.html
write_page1 > $f_path$filename
 
filename=raid_status.html
write_page2 > $f_path$filename
 
filename=raid_status.prn
write_page3 > $f_path$filename

Typing fast I missed the underscore in $fpath
Sorry bout that!!

Might just work now.

Also copy & paste this  over the system_info function

Code: [Select]
function system_info
{
    if ls /etc/redhat-release 1>/dev/null 2>&1; then
        echo "<h2>System release info</h2>"
        echo "<pre>"
        for i in /etc/redhat-release; do
            head -n 1 $i
        done
        uname -orp
        echo "</pre>"
    fi

}   # end of system_info


Offline electroman00

  • ****
  • 491
  • +0/-0
Re: monitoring status of disk redundacy and server uptime more simply
« Reply #36 on: June 11, 2009, 07:41:43 AM »
I might add, the extension .prn is a windows print file extension, it is not a plain text file.

Therefore the code line

Code: [Select]
filename=raid_status.prn
should be changed to

Code: [Select]
filename=raid_status.txt
hth

Offline purvis

  • ****
  • 567
  • +0/-0
Re: monitoring status of disk redundacy and server uptime more simply
« Reply #37 on: June 12, 2009, 12:45:44 AM »
ok  here is what i have as far as a dynamic webpage using php

but i need a few more helpful jump starts from others.
i place some linux commands in here that are not necessary for a short webpage because i am so far playing around with it.
before i get myself in trouble, i could use some other useful commands to gather information but i have come a long way.


i would like to get some information such as the actual server name. if this php is run local(intranet), it does retrieve the server name but not if it is run from the internet.   
my server's name is "server0" not "www.servername.com"




create your webpage file
maybe "serverstatus.php" in a web directory and point your browser to it from both the intranet and internet.
 
and i still like the cron program as well, i have not had time to try other programs placed into this thread because i am slow.


Code: [Select]
<!--DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"-->

<html>

<head><title>Server Status</title></head>

<body>
<b>
<tt>
<div>
<?php
print "<pre>";
print 
"Server Status Report\n";
print 
"Location: Management office\n";
print 
"URL name: ";
print  (
$_SERVER['SERVER_NAME']);
print 
"\n";
system("date | col -b",$return);
print 
"\n";
print 
"***** UPTIME ***************\n";
system("uptime | col -b",$return);
print 
"\n";
print 
"***** RAID STATUS **********\n";
system("cat /proc/mdstat | col -b",$return);
print 
"\n";
print 
"***** DISK STATUS **********\n";
system("df -h | col -b",$return);
print 
"\n";
print 
"***** ETHERNET PORT STATUS ******\n";
system("ifconfig | col -b",$return);
print 
"\n";
print 
"*********************************\n";
system("uname -a | col -b",$return);
print 
"\n";
//print "***** RPM PACKAGES INSTALLED ****\n";
//system("rpm -qa --last | col -b",$return);
//print "\n";
//print "***** UPDATES FOR INSTALLED PACKAGES ****\n";
//system("yum list updates | col -b",$return);
//print "\n";
//print "*****************************\n";
//system("printenv  | col -b",$return);
//print "\n";
print "\n---end of report---\n";
print 
"</pre>";
?>

</div>
</body>
</html>


« Last Edit: June 12, 2009, 12:57:04 AM by purvis »

Offline electroman00

  • ****
  • 491
  • +0/-0
Re: monitoring status of disk redundacy and server uptime more simply
« Reply #38 on: June 12, 2009, 12:58:20 AM »
OK...that's interesting.

Questions

Where is that page located on the server?

Code: [Select]
/home/e-smith/files/ibays/Primary/html/serverstatus
That page should not work located there.

If it does, then we have a major security problem with SME or you have foobar'ed SME security somehow.

Offline electroman00

  • ****
  • 491
  • +0/-0
Re: monitoring status of disk redundacy and server uptime more simply
« Reply #39 on: June 12, 2009, 01:13:14 AM »
Apparently you posted the code then the text as the edit, I saw the code stand alone.

Did you change any permissions on the system?

Offline electroman00

  • ****
  • 491
  • +0/-0
Re: monitoring status of disk redundacy and server uptime more simply
« Reply #40 on: June 12, 2009, 01:18:27 AM »
Quote
if this php is run local(intranet), it does retrieve the server name but not if it is run from the internet.

It shouldn't run any of the commands on that page from the internet.

If it does and you didn't make changes to SME permissions then there is a problem somewhere.

Have you changed any permissions on SME???

Offline purvis

  • ****
  • 567
  • +0/-0
Re: monitoring status of disk redundacy and server uptime more simply
« Reply #41 on: June 12, 2009, 01:35:37 AM »
yes i did a chmod 777


i created a directory "/home/e-smith/files/primary/html/serverstatus"
then i did a chmod 777 to that directory
 
and yes i did post the code then the text prior to the code
i was learning the forum software to post correctly
« Last Edit: June 12, 2009, 01:38:53 AM by purvis »

Offline electroman00

  • ****
  • 491
  • +0/-0
Re: monitoring status of disk redundacy and server uptime more simply
« Reply #42 on: June 12, 2009, 02:15:17 AM »
OK I missed

Quote
create your webpage file
maybe "serverstatus.php" in a web directory and point your browser to it from both the intranet and internet.

When I opened it in my editor I saw the php tags.....da

Make sure that it has a .php and not .html (edit here >>) for the extension

I was very concerned if it ran externally with .html, then I tested it and .html doesn't work so all is ok.

Yea I forgot about running it php, you geared us to a local script from the start, so I went with the flow.

The php works fine.

Quote
i would like to get some information such as the actual server name.

HOSTNAME

Should be 755 or lower, 777 never used for externally facing pages.

Anyway it looks good....and works here.

« Last Edit: June 12, 2009, 03:22:10 AM by electroman00 »

Offline electroman00

  • ****
  • 491
  • +0/-0
Re: monitoring status of disk redundacy and server uptime more simply
« Reply #43 on: June 12, 2009, 02:23:28 AM »
Quote
my server's name is "server0" not "www.servername.com"

hostname = server0 (user defined name)

domain name = servername.com (requires external dns A record) for external access.

localhost = qualified default system name, qualified to the machine your working on.

hth


JFYI

The www tells your browser to start it's search externally and may or may not be required depending on the A record setup.

*.servername.com, A record will find www.servername.com or servername.com

www.servername.com, A record will find www.servername.com not servername.com, without an additional A record entry.

* = limited wildcard

« Last Edit: June 12, 2009, 03:10:51 AM by electroman00 »

Offline purvis

  • ****
  • 567
  • +0/-0
Re: monitoring status of disk redundacy and server uptime more simply
« Reply #44 on: June 12, 2009, 03:47:17 AM »
ok try this

both a short report and a longer report

I tried to retain as much linux commands as possible because i wanted to learn linux commands such as "date" and not the php date functions. Later i will update my cron scripts that do something similiar and create a text file in the "serverstatus" directory.

It looks like i have the server name worked out too using the "uname -n" command.

my short report file name is "index.php"
this makes it easy to just go to "www.servername.com/serverstatus" for info


Code: [Select]


<!--DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"-->

<html>

<head><title>Server Status</title></head>

<body>
<tt>
<b>
<div>
<?php
print "<pre>";
echo  
'<font size="4">';
print 
"Server Status Report\n";
print 
"\n";
print 
"Current date : ";
system("date +'%m-%d-%Y  %T %Z' | col -b",$return);
print 
"    Location : Management office\n";
print 
"    URL name : ";
print  (
$_SERVER['SERVER_NAME']);
print 
"\n";
print 
" Server name : ";
system("uname -n | col -b",$return);

$data shell_exec('uptime');
  
$uptime explode(' up '$data);
  
$uptime explode(','$uptime[1]);
  
$uptime $uptime[0].', '.$uptime[1];
  
$uptime explode(','$uptime);
  print  (
'Hours uptime :  '.$uptime[0].'');
print 
"\n";
  print  (
'Active users :  '.$uptime[1].'');
print 
"\n";

// print "***** UPTIME ***************\n";
// system("uptime | col -b",$return);
// print "\n";

print "\n";
print 
"***** RAID STATUS **********\n";
system("cat /proc/mdstat | col -b",$return);
print 
"\n";

print 
"***** DISK STATUS **********\n";
system("df -h | col -b",$return);
//system("df  | col -b",$return);
print "\n";


print 
"\n---end of report---\n";
print 
"</pre>";
?>


<p>A more detailed report is <a href="longreport.php">available here</a>.</p>
</div>
</body>
</html>

the long version needs to be named "longreport.php" on your server in the same directory as the above.
Code: [Select]

<!--DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"-->

<html>

<head><title>Server Status</title></head>

<body>
<tt>
<b>
<div>
<?php
print "<pre>";
echo  
'<font size="4">';
print 
"Server Status Report\n";
print 
"\n";
print 
"Current date : ";
system("date +'%m-%d-%Y  %T %Z' | col -b",$return);
print 
"    Location : Management office\n";
print 
"    URL name : ";
print  (
$_SERVER['SERVER_NAME']);
print 
"\n";
print 
" Server name : ";
system("uname -n | col -b",$return);

$data shell_exec('uptime');
  
$uptime explode(' up '$data);
  
$uptime explode(','$uptime[1]);
  
$uptime $uptime[0].', '.$uptime[1];
  
$uptime explode(','$uptime);
  print  (
'Hours uptime :  '.$uptime[0].'');
print 
"\n";
  print  (
'Active users :  '.$uptime[1].'');
print 
"\n";

// print "***** UPTIME ***************\n";
// system("uptime | col -b",$return);
// print "\n";

print "\n";
print 
"***** RAID STATUS **********\n";
system("cat /proc/mdstat | col -b",$return);
print 
"\n";

print 
"***** DISK STATUS **********\n";
// system("df -h | col -b",$return);
system("df  | col -b",$return);
print 
"\n";


print 
"***** ETHERNET PORT STATUS ******\n";
system("ifconfig | col -b",$return);
print 
"\n";

print 
"***** SERVER TYPE ***************\n";
system("uname -a | col -b",$return);
print 
"\n";

//print "***** RPM PACKAGES INSTALLED ****\n";
//system("rpm -qa --last | col -b",$return);
//print "\n";
//print "***** UPDATES FOR INSTALLED PACKAGES ****\n";
//system("yum list updates | col -b",$return);
//print "\n";
//print "*****************************\n";
//system("printenv  | col -b",$return);
//print "\n";
print "\n---end of report---\n";
print 
"</pre>";
?>

</div>
</body>
</html>

« Last Edit: June 12, 2009, 04:02:51 AM by purvis »