Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: n7ekb/chkhosts
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.4.0
Choose a base ref
...
head repository: n7ekb/chkhosts
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: production
Choose a head ref
  • 10 commits
  • 6 files changed
  • 4 contributors

Commits on Jun 16, 2015

  1. Changed color of offlined systems from white to silver. This

    works better with the white borders (the cells are then defined).
    Ed Braaten committed Jun 16, 2015

    Verified

    This commit was signed with the committer’s verified signature.
    ihipop ihipop
    Copy the full SHA
    5d864b5 View commit details

Commits on Jun 30, 2015

  1. Filled out the README.md file with basic description of chkhosts.

    Eliminated "description" line and "description" line log file to
    streamline/simplify status page.  Lines 3-8 in each cell are now
    governed by existence of files in system-lineX directories.
    Ed Braaten committed Jun 30, 2015

    Verified

    This commit was signed with the committer’s verified signature.
    ihipop ihipop
    Copy the full SHA
    6dc9d93 View commit details
  2. 1

    Verified

    This commit was signed with the committer’s verified signature.
    ihipop ihipop
    Copy the full SHA
    0263502 View commit details
  3. Verified

    This commit was signed with the committer’s verified signature.
    ihipop ihipop
    Copy the full SHA
    1093351 View commit details

Commits on Jul 1, 2015

  1. Changed directory name to "system-color" for color feature

    and added creation of the subdirectory if it doesn't exist.
    Ed Braaten committed Jul 1, 2015

    Verified

    This commit was signed with the committer’s verified signature.
    ihipop ihipop
    Copy the full SHA
    48a288c View commit details
  2. Fixed syntax error on $contents variable (needed to be

    exposed as output for the HTML page).
    Ed Braaten committed Jul 1, 2015

    Verified

    This commit was signed with the committer’s verified signature.
    ihipop ihipop
    Copy the full SHA
    a6a9449 View commit details
  3. Fix for $contents variable that actually works. :)

    Ed Braaten committed Jul 1, 2015

    Verified

    This commit was signed with the committer’s verified signature.
    ihipop ihipop
    Copy the full SHA
    2c8ac59 View commit details

Commits on Jul 4, 2015

  1. Initial commit of INSTALL.md file. Rough build info completed,

    still needs installation instructions.
    Ed Braaten committed Jul 4, 2015

    Verified

    This commit was signed with the committer’s verified signature.
    ihipop ihipop
    Copy the full SHA
    9883ba1 View commit details

Commits on Jul 5, 2015

  1. Interim commit of INSTALL.md. Configuration section still

    blank.
    Ed Braaten committed Jul 5, 2015

    Verified

    This commit was signed with the committer’s verified signature.
    ihipop ihipop
    Copy the full SHA
    9107305 View commit details

Commits on Dec 14, 2020

  1. Copy the full SHA
    146a11b View commit details
55 changes: 55 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
chkhosts Build
==============

Obtain the latest copy of chkhosts from here:

https://github.com/n7ekb/chkhosts

Change to the directory where you have cloned/unpacked the chkhosts
source. You'll find several directories including the "install-pkg"
sub-directory. If you change into the "install-pkg" directory
and execute the "make" command, it will build a fresh, self-extracting
bash shell archive called "install-chkhosts.sh". This file is all
you need to install chkhosts on a system.

The Makefile provided also has a "clean" target which will remove the
build directory and related files.


chkhosts Installation
=====================

Chkhosts was developed on a CentOS Linux system running an Apache
web server with PHP installed. It should run on any modern Linux
distribution - feedback to the development team would be greatly
appreciated if you find a system it won't run on.

Before installing, you should identify the system that will be hosting
the dynamic chkhosts web status page. In the simplest configuration,
this web server system will host the chkhosts web status page and also
run the chkhosts "ping" script from a crontab entry.

The install script ("install-chkhosts.sh") requires one argument
when executed - the name of the directory where the executable
chkhosts scripts should be installed. When the install script runs,
it will create a "chkhosts-sample.d" sub-directory in its current
working directory. This sub-directory contains all of the data and
configuration files associated with chkhosts.


Installation Example
====================

In this example, the web server's root directory is "/var/www/html"
and the chkhosts executable scripts are going to be installed in
"/usr/local/bin". It's assumed that the "install-chkhosts.sh" script
has been placed in the "/var/www/html" directory.

cd /var/www/html
sudo ./install-chkhosts.sh /usr/local/bin


chkhosts Configuration
======================


49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -2,3 +2,52 @@ chkhosts
========

Simple host monitoring

Chkhosts is a package designed to run on a PHP-enabled Linux/Unix web
server, providing visual status of a group of systems via a dynamic
web status page.

The chkhosts web status page displays a table with a cell for each
system that is being monitored. The cell for each system is labeled
by the system's hostname. If a text file named "hostname.txt" (replace
hostname with the corresponding system hostname) exists in the chkhosts
"system-info" sub-directory, the hostname label on the status page will
be a link to the file. The contents of this "hostname.txt" file can be
anything. Typically the corresponding hostname.txt file for a system
will contain detailed system information that the host generates itself
such as BIOS revision, memory configuration, etc. A system administrator
can configure the monitored host(s) to create this file and then copy it
to the chkhosts server at boot time or some periodic interval.

The chkhosts package includes a crontab-driven script that does periodic
network pings of the monitored systems. This "ping" script updates
status files used by the chkhosts system status web page to color the
background indicating status. Default is "red" for host down, "green"
for host up. If a host is up, the default background of green can
optionally be overriden with a different color by putting a valid
HTML color name (or hex value) in a "hostname".txt file in the chkhosts
"system-color" sub-directory. The web status page will then use this
background color for the cell representing the corresponding system in
its status table.

Changes in a system's status detected by the "ping" script are
logged (system up/system down) and a link to this log is provided
on the chkhosts web status page.

Additional lines are displayed in the cell for each monitored system.
The second line, referred to as the "comment" line, has an associated
web form page that allows web users to enter a display text for the line.
When a web user submits a change to the comment line, the text submitted
is logged along with the date and time in the corresponding "comment" log
file. A link to this log file is provided on the chkhosts web status page.
The comment line is typically used to help coordinate the usage of shared
systems in a workgroup or to log changes being made to the systems being
monitored.

The remaining lines in the cell for each monitored system, lines 3
through 8, are optional, and only appear if there is a text file
"hostname.txt" corresponding to the monitored host name in the
chkhosts "system-lineX" sub-directories. The contents of the
hostname.txt file is displayed for the corresponding line for a
system if it is present.

1 change: 1 addition & 0 deletions chkhosts-sample.d/webstat/system-line3/host1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sample line 3
1 change: 1 addition & 0 deletions chkhosts-sample.d/webstat/system-line3/host2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sample line 3
1 change: 1 addition & 0 deletions chkhosts-sample.d/webstat/system-line3/host3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sample line 3
179 changes: 32 additions & 147 deletions scripts/chkhosts-gen-webstat.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
#
# Script to generate host status php web page and
# the description & comment update form pages.
# the comment update form page.
#
# usage: chkhosts-gen-webstat.sh chkhosts_directory

@@ -40,9 +40,10 @@ DOWNHOSTSTATUSDIR=$WORKDIR/status-down
CHKHOSTLOGDIR=$WORKDIR/log
CHKHOSTLOG=$CHKHOSTLOGDIR/chkhosts.log
WEBSTATDIR=$WORKDIR/webstat
WEBDESCRIPTIONDIR=$WEBSTATDIR/system-description
WEBCOMMENTDIR=$WEBSTATDIR/system-comment
WEBSYSTEMINFODIR=$WEBSTATDIR/system-info
WEBSYSTEMCOLORDIR=$WEBSTATDIR/system-color
WEBSYSTEMLINE3DIR=$WEBSTATDIR/system-line3
WEBSYSTEMLINE4DIR=$WEBSTATDIR/system-line4
WEBSYSTEMLINE5DIR=$WEBSTATDIR/system-line5
WEBSYSTEMLINE6DIR=$WEBSTATDIR/system-line6
@@ -180,128 +181,6 @@ sed -i "s/_CHKHOSTS_CONTACTNAME_/${_CHKHOSTS_CONTACTNAME_}/g" $COMMENTFORM
sed -i "s/_CHKHOSTS_CONTACTEMAIL_/${_CHKHOSTS_CONTACTEMAIL_}/g" $COMMENTFORM


#
# Create the Description Form page next
#######################################

echo "Generating $DESCFORM..."
echo '<!DOCTYPE html>' >$DESCFORM
echo '<html>' >>$DESCFORM
echo '<head>' >>$DESCFORM
echo ' <meta charset="UTF-8">' >>$DESCFORM
echo ' <meta name="generator" content="gen-webstat.sh MY_VERSION_STRING">' \
>>$DESCFORM
echo ' <link rel="stylesheet" type="text/css" href="style.css">' >>$DESCFORM
echo " <title>${_CHKHOSTS_DESCFORM_TITLE_}</title>" >>$DESCFORM
echo '</head>' >>$DESCFORM
echo ' ' >>$DESCFORM

echo '<body>' >>$DESCFORM

# insert the php POST function and showstatus functions
cat >>$DESCFORM << "SUBMIT_FUNCTION_SECTION"
<?php
session_start();
if (isset($_SESSION['description_session'])) {
/* Don't do anything - already processed the submit... */
}
else {
if (isset($_POST['submit'])) {
$action_hostname = $_POST['DescriptionHostName'];
$action_description = $_POST['DescriptionText'];
file_put_contents(
"system-description/$action_hostname.txt",
$action_description);
$log_entry = strftime("%F %T: ") .
"$action_hostname, $action_description\n";
file_put_contents("description.log",$log_entry,
FILE_APPEND);
header('Location: status.php');
exit();
}
}
?>
SUBMIT_FUNCTION_SECTION

# insert the description section part 1
cat >>$DESCFORM << "DESCRIPTION_SECTION_1"
<h3>_CHKHOSTS_DESCFORM_TITLE_</h3>
<p>
This form allows you to update the <b>description</b> line of
the selected host. &nbsp;
</p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table align="center" style="border-spacing: 1px;border-style: solid;
border-color: #000000;border-width: 3px 3px 3px 3px">
<tr><td><b>Host:</b> &nbsp;
<select name="DescriptionHostName">
<option selected value="unknown">&lt;select host&gt;
DESCRIPTION_SECTION_1

# make sure the system-description directory, log file exist
mkdir -p $WEBDESCRIPTIONDIR
touch $WEBSTATDIR/description.log

# create the host list for drop down menu
for i in $( grep -v -e '^#' $HOSTLISTFILE ); do

# create short host name...
IPADDR="`echo $i | grep -e '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*'`"
if [[ "$IPADDR" == "" ]]; then
SHORTNAME="`echo $i | awk -F . '{ print $1}'`"
else
SHORTNAME="$IPADDR"
fi

# add to list in web page
echo " <option value=\"$SHORTNAME\">$SHORTNAME" >>$DESCFORM

# add initial description to description file for host
if [[ ! -e "$WEBDESCRIPTIONDIR/$SHORTNAME.txt" ]]; then
echo "description" >$WEBDESCRIPTIONDIR/$SHORTNAME.txt
fi
done

# set permissions to ensure web server can write the files
chmod ugo+w $WEBDESCRIPTIONDIR/* $WEBSTATDIR/description.log

cat >>$DESCFORM << "DESCRIPTION_SECTION_2"
</select>
</td></tr>
<tr><td><b>Description:</b> &nbsp;
<input type="text" name="DescriptionText" size=40 maxlength=512 /></td></tr>
<tr><td align="center"><input type="submit" name="submit" value="Update Description"></td></tr>
</table>
</form>
<p>&nbsp;</p>
<div class="footer">
<hr width="55%">
<p align="center">This page generated by
<a href="https://github.com/k6ekb/chkhosts">
gen-webstat.sh MY_VERSION_STRING</a><br>
This page last edited on
<?php echo strftime("%a, %d %b %Y at %H:%M %Z.",
filemtime("update-description.php")); ?><br>
You're logged in as '<?php print getenv("REMOTE_USER");?>'
from <?php print getenv("REMOTE_ADDR"); ?><br>
</div>
DESCRIPTION_SECTION_2

#
# Close out DESCFORM document
#############################

echo '</body>' >>$DESCFORM
echo '</html>' >>$DESCFORM

# now customize the Description Form page...
sed -i "s/_CHKHOSTS_DESCFORM_TITLE_/${_CHKHOSTS_DESCFORM_TITLE_}/g" $DESCFORM
sed -i "s/_CHKHOSTS_HOSTNAME_/${_CHKHOSTS_HOSTNAME_}/g" $DESCFORM
sed -i "s/_CHKHOSTS_POLL_INTERVAL_/${_CHKHOSTS_POLL_INTERVAL_}/g" $DESCFORM
sed -i "s/_CHKHOSTS_CONTACTNAME_/${_CHKHOSTS_CONTACTNAME_}/g" $DESCFORM
sed -i "s/_CHKHOSTS_CONTACTEMAIL_/${_CHKHOSTS_CONTACTEMAIL_}/g" $DESCFORM


#
# Generate the HTML header for status page
@@ -333,28 +212,36 @@ cat >>$WEBPAGE << "PHP_FUNCTIONS_SECTION"
function showstatus($pingname,$hostname)
{
if (file_exists("../status-up/$pingname")) {
echo '<td style="background-color:green; \
$file = "system-color/$hostname.txt";
if (file_exists($file)){
$contents = file_get_contents($file);
echo "<td style=\"background-color:$contents; \
border-color: #000000; \
border-width: 1px 1px 1px 1px\">";
} else {
echo '<td style="background-color:green; \
border-color: #00000; \
border-width: 1px 1px 1px 1px">';
}
if (file_exists("system-info/$hostname.txt")) {
echo "<b>";
echo "<a href=\"system-info/$hostname.txt\">";
echo "$hostname</a></b><br>";
} else {
echo "<b>$hostname</b><br>";
}
if (file_exists("system-description/$hostname.txt")) {
$description=rtrim(file_get_contents(
"system-description/$hostname.txt"));
echo $description;
echo "<br>";
}
if (file_exists("system-comment/$hostname.txt")) {
$comment=rtrim(file_get_contents(
"system-comment/$hostname.txt"));
echo $comment;
echo "<br>";
}
if (file_exists("system-line3/$hostname.txt")) {
$line3info=rtrim(file_get_contents(
"system-line3/$hostname.txt"));
echo $line3info;
echo "<br>";
}
if (file_exists("system-line4/$hostname.txt")) {
$line4info=rtrim(file_get_contents(
"system-line4/$hostname.txt"));
@@ -390,7 +277,7 @@ cat >>$WEBPAGE << "PHP_FUNCTIONS_SECTION"
echo '</td>';
} else {
if (file_exists("system-offline/$hostname.txt")) {
echo '<td style="background-color:white; \
echo '<td style="background-color:silver; \
border-color: #FFFFFF; \
border-width: 1px 1px 1px 1px">';
} else {
@@ -405,18 +292,18 @@ cat >>$WEBPAGE << "PHP_FUNCTIONS_SECTION"
} else {
echo "<b>$hostname</b><br>";
}
if (file_exists("system-description/$hostname.txt")) {
$description=rtrim(file_get_contents(
"system-description/$hostname.txt"));
echo $description;
echo "<br>";
}
if (file_exists("system-comment/$hostname.txt")) {
$comment=rtrim(file_get_contents(
"system-comment/$hostname.txt"));
echo $comment;
echo "<br>";
}
if (file_exists("system-line3/$hostname.txt")) {
$line3info=rtrim(file_get_contents(
"system-line3/$hostname.txt"));
echo $line3info;
echo "<br>";
}
if (file_exists("system-line4/$hostname.txt")) {
$line4info=rtrim(file_get_contents(
"system-line4/$hostname.txt"));
@@ -512,18 +399,14 @@ echo '</table></p>' >>$WEBPAGE
# insert the Log links section
cat >>$WEBPAGE << "LOG_SECTION"
<p>
The description (line 2) and comment (line 3) for each host in
the system status table above can be updated via the web. &nbsp;
The comment (line 2) for each host in the system status table
above can be updated via the web. &nbsp;
All changes are logged with the date and time the change was
made. &nbsp;
Use these links to make updates or to review changes:
Use these links to make updates or to review the comments log:
<ul>
<li><a href="update-description.php">
<b>Update Description (line 2)</b></a>
&nbsp;&nbsp;(<a href="description.log">
Review Description Change Log</a>)</li>
<li><a href="update-comment.php">
<b>Update Comment (line 3)</b></a>
<b>Update Comment (line 2)</b></a>
&nbsp;&nbsp;(<a href="comment.log">
Review Comment Change Log</a>)</li>
</ul>
@@ -583,9 +466,11 @@ touch $CHKHOSTLOG
mkdir -p $UPHOSTSTATUSDIR
mkdir -p $DOWNHOSTSTATUSDIR

# make sure the system-info, and system-line[4-8]
# make sure the system-info, and system-line[3-8]
# directories exist
mkdir -p $WEBSYSTEMINFODIR
mkdir -p $WEBSYSTEMCOLORDIR
mkdir -p $WEBSYSTEMLINE3DIR
mkdir -p $WEBSYSTEMLINE4DIR
mkdir -p $WEBSYSTEMLINE5DIR
mkdir -p $WEBSYSTEMLINE6DIR