Updated rexec and Rexec.pm to use Clearadm's database instead.
-#!/usr/local/bin/perl
-################################################################################
-#
-# File: $RCSfile: rexec,v $
-# Revision: $Revision: 1.1 $
-# Description: Remotely run processes on other machines
-# Author: Andrew@ClearSCM.com
-# Created: Tue Jan 8 15:57:27 MST 2008
-# Modified: $Date: 2008/02/29 15:09:15 $
-# Language: perl
-#
-# (c) Copyright 2008, ClearSCM, Inc., all rights reserved
-#
-################################################################################
+#!/usr/bin/perl
use strict;
use warnings;
-use FindBin;
-use Getopt::Long;
-use Term::ANSIColor qw(:constants);
-use POSIX ":sys_wait_h";
+=pod
-my $libs;
+=head1 NAME $RCSfile: rexec,v $
-BEGIN {
- $libs = $ENV{SITE_PERLLIB} ? $ENV{SITE_PERLLIB} : "$FindBin::Bin/lib";
+Run arbitrary command on a set of machines
- die "Unable to find libraries\n" if !$libs and !-d $libs;
-}
+=head1 VERSION
-use lib $libs;
+=over
-use Display;
-use Logger;
-use Machines;
-use Rexec;
-use Utils;
+=item Author
+
+Andrew DeFaria <Andrew@ClearSCM.com>
-our $_host;
-our $_skip = 0;
-our $_currentHost;
+=item Revision
-my $_log = 0;
-my $_quiet = 0;
-my $_alternateFile;
-my $_parallel = 0;
+$Revision: 1.0 $
-my $_totalMachines = 0;
-my $_totalExecutions = 0;
-my $_totalFailures = 0;
-my $_totalConnectFailures = 0;
-my $_totalSkips = 0;
+=item Created:
-my (%_workerStatuses, %_workerNames);
+Tue Jan 8 15:57:27 MST 2008
-sub Usage {
- my $msg = shift;
+=item Modified:
- display "ERROR: $msg\n" if defined $msg;
+$Date: 2008/02/29 15:09:15 $
- display "rexec\t[-v] [-d] [-u] <cmd>";
- display "\t-v\tTurn on verbose mode";
- display "\t-d\tTurn on debug mode";
- display "\t-u\tThis usage message";
- display "<cmd>\tCommand to execute remotely";
+=back
- exit 1;
-} # Usage
+=head1 SYNOPSIS
-sub printStats {
- display YELLOW . "Machines: " . RESET . "$_totalMachines " .
- MAGENTA . "Executions/Failures: " . RESET . "($_totalExecutions/$_totalFailures) " .
- BLUE . "Connect Failures/Skips: " . RESET . "($_totalConnectFailures/$_totalSkips)";
-} # printStats
+ Usage: rexec [-u|sage] [-v|erbose] [-d|ebug] [-t|ype <machine type>]
+ <command>
+
+ Where:
+ -u|sage Print this usage
+ -v|erbose: Verbose mode
+ -d|ebug: Print debug messages
+ -t|ype: Machine type (Linux, Windows)
+ <command>: Command to execute
+
+=head1 DESCRIPTION
+
+This script will perform and arbitrary command on a set of machines.
+
+=cut
+
+use FindBin;
+use Getopt::Long;
+use Pod::Usage;
+use Term::ANSIColor qw(:constants);
+use POSIX ":sys_wait_h";
+
+use lib "$FindBin::Bin/../lib", "$FindBin::Bin/../clearadm/lib";
+
+use Display;
+use Clearadm;
+use Logger;
+use Rexec;
+use Utils;
+
+my %total;
+my ($currentHost, $skip, $log);
+
+my %opts = (
+ usage => sub { pod2usage },
+ help => sub { pod2usage (-verbose => 2)},
+ verbose => sub { set_verbose },
+ debug => sub { set_debug },
+ parallel => 0,
+);
+
+my (%workerStatuses, %workerNames);
sub Interrupted {
use Term::ReadKey;
- display BLUE . "\nInterrupted execution on $_host" . RESET;
+ display BLUE . "\nInterrupted execution on $currentHost" . RESET;
- printStats;
+ Stats \%total, $log;
- display_nolf "Executing on " . YELLOW . $_host . RESET . " - "
+ display_nolf "Executing on " . YELLOW . $currentHost . RESET . " - "
. GREEN . BOLD . "S" . RESET . GREEN . "kip" . RESET . ", "
. CYAN . BOLD . "C" . RESET . CYAN . "ontinue" . RESET . " or "
. MAGENTA . BOLD . "A" . RESET . MAGENTA . "bort run" . RESET . " ("
if ($answer eq "s") {
*STDOUT->flush;
- display "Skipping $_host";
- $_skip = 1;
- $_totalSkips++;
+ display "Skipping $currentHost";
+ $skip = 1;
+ $total{Skips}++;
} elsif ($answer eq "a") {
display RED . "Aborting run". RESET;
- printStats;
+ Stats \%total, $log;
exit;
} else {
display "Continuing...";
- $_skip = 0;
+ $skip = 0;
} # if
+
+ return;
} # Interrupted
sub workerDeath {
my $status = $?;
# Ignore all child deaths except for processes we started
- next if !exists $_workerStatuses{$worker};
+ next if !exists $workerStatuses{$worker};
- $_workerStatuses{$worker} = $status;
+ $workerStatuses{$worker} = $status;
} # while
$SIG{CHLD} = \&workerDeath;
+
+ return;
} # workerDeath
-sub execute ($$$) {
+sub execute ($$;$) {
my ($cmd, $host, $prompt) = @_;
- my @lines;
+ my ($remoteHost, @lines);
+ # Mark $currentHost for interrupt
+ $currentHost = $host;
+
+ # Start a log...
+ $log = Logger->new (name => $host) if $opts{log};
+
verbose_nolf "Connecting to machine $host...";
+ display_nolf YELLOW . "$host:" . RESET;
+
eval {
- $_currentHost = new Rexec (
- host => $host,
- prompt => $prompt,
+ $remoteHost = Rexec->new (
+ host => $host,
+ prompt => $prompt,
);
};
# Problem with creating Rexec object. Log error if logging and return.
- if ($@ or !$_currentHost) {
- if ($_log) {
- my $log = new Logger (name => $_host);
-
- $log->err ("Unable to connect to $host to execute command\n$cmd");
+ if ($@ || !$remoteHost) {
+ if ($opts{log}) {
+ $log->err ("Unable to connect to $host to execute command: $cmd") if $opts{log};
+ } else {
+ display RED . 'ERROR:' . RESET . " Unable to connect to $host to execute command: $cmd";
} # if
- $_totalConnectFailures++;
+ $total{ConnectFailures}++;
return (1, ());
} # if
verbose " connected";
- display YELLOW . "$host:" . RESET . UNDERLINE . "$cmd" . RESET unless $_quiet;
+ display UNDERLINE . "$cmd" . RESET unless $opts{quiet};
- @lines = $_currentHost->exec ($cmd);
+ @lines = $remoteHost->execute ($cmd);
- if ($_skip) {
+ if ($skip) {
# Kick current connection
- kill INT => $_currentHost->{handle}->pid;
+ kill INT => $remoteHost->{handle}->pid;
} # if
- if ($_parallel != 0) {
- if ($_log) {
- my $log = new Logger (name => $_host);
-
- $log->err ("Unable to connect to $host to execute command\n$cmd");
- } # if
-
- $_totalConnectFailures++;
- } # if
+# if ($opts{parallel} != 0) {
+# $log->err ("Unable to connect to $host to execute command\n$cmd") if $opts{log};
+#
+# $total{ConnectFailures}++;
+# } # if
verbose "Disconnected from $host";
- my $status = $_currentHost->status;
-
- undef $_currentHost;
+ my $status = $remoteHost->status;
return ($status, @lines);
} # execute
my $thread_count = 1;
- foreach $_host (sort keys %machines) {
- if ($thread_count <= $_parallel) {
- debug "Processing $_host ($thread_count)";
+ foreach my $host (sort keys %machines) {
+ if ($thread_count <= $opts{parallel}) {
+ debug "Processing $host ($thread_count)";
$thread_count++;
if (my $pid = fork) {
# In parent process - record this host and its status
- $_workerNames{$pid} = $_host;
+ $workerNames{$pid} = $host;
} else {
# In spawned child...
$pid = $$;
- debug "Starting process for $_host [$pid]";
+ debug "Starting process for $host [$pid]";
- $_workerNames{$pid} = $_host;
+ $workerNames{$pid} = $host;
+
+ # Mark currentHost for interrupt (How does this work in the presence
+ # of parallelization?).
+ $currentHost = $host;
- my ($status, @lines) = execute $cmd, $_host, $machines{$_host};
+ my ($status, @lines) = execute $cmd, $host, $machines{$host};
- my $log = new Logger (name => $_host);
+ $log = Logger->new (name => $host);
$log->log ($_) foreach (@lines);
debug "Waiting for somebody to exit...";
my $reaped = wait;
- debug "Reaped $_workerNames{$reaped} [$reaped] (Status: $?)";
- $_workerStatuses{$reaped} = $? >> 8 if $reaped != -1;
+ debug "Reaped $workerNames{$reaped} [$reaped] (Status: $?)";
+ $workerStatuses{$reaped} = $? >> 8 if $reaped != -1;
$thread_count--;
} # if
} # foreach
# Wait for all kids
- my %threads = %_workerNames;
+ my %threads = %workerNames;
foreach (keys %threads) {
if (waitpid ($_, 0) == -1) {
delete $threads{$_};
} else {
- $_workerStatuses{$_} = $? >> 8;
- debug "$threads{$_} [$_] exited with a status of $_workerStatuses{$_}";
+ $workerStatuses{$_} = $? >> 8;
+ debug "$threads{$_} [$_] exited with a status of $workerStatuses{$_}";
} # if
} # foreach
debug "All processed completed - Status:";
if (get_debug) {
- foreach (sort keys %_workerStatuses) {
- debug "$_workerNames{$_}\t[$_]:\tStatus: $_workerStatuses{$_}";
+ foreach (sort keys %workerStatuses) {
+ debug "$workerNames{$_}\t[$_]:\tStatus: $workerStatuses{$_}";
} # foreach
} # if
# Gather output...
display "Output of all executions";
- foreach $_host (sort keys %machines) {
- if (-f "$_host.log") {
- display "$_host:$_" foreach (ReadFile ("$_host.log"));
+ foreach my $host (sort keys %machines) {
+ if (-f "$host.log") {
+ display "$host:$_" foreach (ReadFile ("$host.log"));
#unlink "$_host.log";
} else {
- warning "Unable to find output for $_host ($_host.log missing)";
+ warning "Unable to find output for $host ($host.log missing)";
} # if
} # foreach
+
+ return;
} # parallelize
# Print the totals if interrupted
# Get our options
GetOptions (
- "usage" => sub { Usage "" },
- "verbose" => sub { set_verbose },
- "debug" => sub { set_debug },
- "log" => \$_log,
- "quiet" => \$_quiet,
- "file=s" => \$_alternateFile,
- "parallel:i" => \$_parallel,
-) || Usage "Unknown parameter";
-
-my $cmd = join " ", @ARGV;
-
-error "No command specified", 1 if !$cmd;
-
-my $machines = Machines->new (file => $_alternateFile);
-my %machines = $machines->all ();
-
-if ($_parallel > 0) {
- parallelize ($cmd, %machines);
- printStats;
+ \%opts,
+ 'usage',
+ 'help',
+ 'verbose',
+ 'debug',
+ 'log',
+ 'quiet',
+ 'type=s',
+ 'parallel=i',
+);
+
+my $cmd = join ' ', @ARGV;
+
+pod2usage ('No command specified') unless $cmd;
+
+my $machines = Clearadm->new;
+
+if ($opts{parallel} > 0) {
+ #parallelize ($cmd, %machines);
+ Stats \%total, $log;
exit;
} # if
-display "NOTE: Logging output to <host>.log" if $_log;
+display "NOTE: Logging outputs to <host>.log" if $opts{log};
-foreach $_host (sort keys (%machines)) {
- $_totalMachines++;
+foreach ($machines->SearchSystem ("type='$opts{type}'")) {
+ my %system = %$_;
+ $total{Machines}++;
- my ($status, @lines) = execute $cmd, $_host, $machines{$_host};
+ my ($status, @lines) = execute $cmd, $system{name};
- if ($_skip) {
- $_skip = 0;
+ if ($skip) {
+ $skip = 0;
next;
} # if
if (defined $status) {
if ($status == 0) {
- $_totalExecutions++;
+ $total{Executions}++;
} else {
- if ($_log) {
- my $log = new Logger (name => $_host);
-
- $log->err ("Unable to execute command on $_host\n$cmd");
- } # if
-
- $_totalFailures++;
+ $total{Failures}++;
next;
} # if
} # if
- if ($_log) {
- my $log = new Logger (name => $_host);
-
+ if ($opts{log}) {
$log->log ($_) foreach (@lines);
} else {
display $_ foreach (@lines);
} # if
} # foreach
-printStats;
\ No newline at end of file
+Stats \%total, $log;
\ No newline at end of file
use Carp;
use DBI;
+use File::Basename;
use Net::Domain qw(hostdomain);
use FindBin;
use GetConfig;
use Mail;
-our %CLEAROPTS = GetConfig ("$FindBin::Bin/etc/clearadm.conf");
+my $conf = dirname (__FILE__) . '/../etc/clearadm.conf';
+
+our %CLEAROPTS = GetConfig ($conf);
# Globals
our $VERSION = '$Revision: 1.54 $';
return $self->_getRecords ('system', $condition);
} # FindSystem
+sub SearchSystem (;$) {\r
+ my ($self, $condition) = @_;
+
+ $condition = "name like '%'" unless $condition;
+
+ return $self->_getRecords ('system', $condition); \r
+} # SearchSystem
+
sub AddPackage (%) {
my ($self, %package) = @_;
+++ /dev/null
-###############################################################################
-#
-# File: $RCSfile: machines.conf,v $
-# Revision: $Revision: 1.0 $
-# Description: Config file for Machines
-# Author: Andrew@ClearSCM.com
-# Created: Fri Apr 4 14:29:21 PDT 2014
-# Modified: $Date: $
-# Language: conf
-#
-# (c) Copyright 2014, ClearSCM, Inc., all rights reserved
-#
-###############################################################################
-MACHINES_SERVER: adefaria-lt
-MACHINES_USERNAME: machines
-MACHINES_PASSWORD: machines
+++ /dev/null
-=pod
-
-=head1 NAME $RCSfile: Machines.pm,v $
-
-Abstraction of machines.
-
-=head1 VERSION
-
-=over
-
-=item Author
-
-Andrew DeFaria <Andrew@ClearSCM.com>
-
-=item Revision
-
-$Revision: 1.4 $
-
-=item Created
-
-Tue Jan 8 17:24:16 MST 2008
-
-=item Modified
-
-$Date: 2011/11/16 19:46:13 $
-
-=back
-
-=head1 SYNOPSIS
-
-This module handles the details of providing information about
-machines while obscuring the mechanism for storing such information.
-
- my $machines = Machines->new;
-
- foreach ($machine->all) {
- my %machine = %{$_};
- display "Machine: $machine{name}";
- disp.ay "Owner: $machine{owner}"
- } # if
-
-=head1 DESCRIPTION
-
-This module provides information about machines
-
-=head1 ROUTINES
-
-The following routines are exported:
-
-=cut
-
-package Machines;
-
-use strict;
-use warnings;
-
-use Carp;
-use DBI;
-use FindBin;
-
-use DateUtils;
-use Display;
-use GetConfig;
-
-our %MACHINESOPTS = GetConfig ("$FindBin::Bin/../etc/machines.conf");
-
-my $defaultFilesystemThreshold = 90;
-my $defaultFilesystemHist = '6 months';
-my $defaultLoadavgHist = '6 months';
-
-# Internal methods
-sub _dberror ($$) {
- my ($self, $msg, $statement) = @_;
-
- my $dberr = $self->{db}->err;
- my $dberrmsg = $self->{db}->errstr;
-
- $dberr ||= 0;
- $dberrmsg ||= 'Success';
-
- my $message = '';
-
- if ($dberr) {
- my $function = (caller (1)) [3];
-
- $message = "$function: $msg\nError #$dberr: $dberrmsg\n"
- . "SQL Statement: $statement";
- } # if
-
- return $dberr, $message;
-} # _dberror
-
-sub _formatValues (@) {
- my ($self, @values) = @_;
-
- my @returnValues;
-
- # Quote data values
- push @returnValues, $_ eq '' ? 'null' : $self->{db}->quote ($_)
- foreach (@values);
-
- return @returnValues;
-} # _formatValues
-
-sub _formatNameValues (%) {
- my ($self, %rec) = @_;
-
- my @nameValueStrs;
-
- push @nameValueStrs, "$_=" . $self->{db}->quote ($rec{$_})
- foreach (keys %rec);
-
- return @nameValueStrs;
-} # _formatNameValues
-
-sub _error () {\r
- my ($self) = @_;
-
- if ($self->{msg}) {
- if ($self->{errno}) {
- carp $self->{msg};
- } else {
- cluck $self->{msg};
- } # if
- } # if\r
-} # _error
-
-sub _addRecord ($%) {
- my ($self, $table, %rec) = @_;
-
- my $statement = "insert into $table (";
- $statement .= join ',', keys %rec;
- $statement .= ') values (';
- $statement .= join ',', $self->_formatValues (values %rec);
- $statement .= ')';
-
- my ($err, $msg);
-
- $self->{db}->do ($statement);
-
- return $self->_dberror ("Unable to add record to $table", $statement);
-} # _addRecord
-
-sub _checkRequiredFields ($$) {
- my ($fields, $rec) = @_;
-
- foreach my $fieldname (@$fields) {
- my $found = 0;
-
- foreach (keys %$rec) {
- if ($fieldname eq $_) {
- $found = 1;
- last;
- } # if
- } # foreach
-
- return "$fieldname is required"
- unless $found;
- } # foreach
-
- return;
-} # _checkRequiredFields
-
-sub _connect (;$) {
- my ($self, $dbserver) = @_;
-
- $dbserver ||= $MACHINESOPTS{MACHINES_SERVER};
-
- my $dbname = 'machines';
- my $dbdriver = 'mysql';
-
- $self->{db} = DBI->connect (
- "DBI:$dbdriver:$dbname:$dbserver",
- $MACHINESOPTS{MACHINES_USERNAME},
- $MACHINESOPTS{MACHINES_PASSWORD},
- {PrintError => 0},
- ) or croak (
- "Couldn't connect to $dbname database "
- . "as $MACHINESOPTS{MACHINESADM_USERNAME}\@$MACHINESOPTS{MACHINESADM_SERVER}"
- );
-
- $self->{dbserver} = $dbserver;
-
- return;
-} # _connect
-
-sub _getRecords ($$) {
- my ($self, $table, $condition) = @_;
-
- my ($err, $msg);
-
- my $statement = "select * from $table where $condition";
-
- my $sth = $self->{db}->prepare ($statement);
-
- unless ($sth) {
- ($err, $msg) = $self->_dberror ('Unable to prepare statement', $statement);
-
- croak $msg;
- } # if
-
- my $attempts = 0;
- my $maxAttempts = 3;
- my $sleepTime = 30;
- my $status;
-
- # We've been having the server going away. Supposedly it should reconnect so
- # here we simply retry up to $maxAttempts times to re-execute the statement.
- # (Are there other places where we need to do this?)
- $err = 2006;
-
- while ($err == 2006 and $attempts++ < $maxAttempts) {
- $status = $sth->execute;
-
- if ($status) {
- $err = 0;
- last;
- } else {
- ($err, $msg) = $self->_dberror ('Unable to execute statement',
- $statement);
- } # if
-
- last if $err == 0;
-
- croak $msg unless $err == 2006;
-
- my $timestamp = YMDHMS;
-
- $self->Error ("$timestamp: Unable to talk to DB server.\n\n$msg\n\n"
- . "Will try again in $sleepTime seconds", -1);
-
- # Try to reconnect
- $self->_connect ($self->{dbserver});
-
- sleep $sleepTime;
- } # while
-
- $self->Error ("After $maxAttempts attempts I could not connect to the database", $err)
- if ($err == 2006 and $attempts > $maxAttempts);
-
- my @records;
-
- while (my $row = $sth->fetchrow_hashref) {
- push @records, $row;
- } # while
-
- return @records;
-} # _getRecord
-
-
-sub new {
- my ($class, %parms) = @_;
-
-=pod
-
-=head2 new ($server)
-
-Construct a new Machines object.
-
-=cut
-
- # Merge %parms with %MACHINEOPTS
- foreach (keys %parms) {
- $MACHINESOPTS{$_} = $parms{$_};
- } # foreach;
-
- my $self = bless {}, $class;
-
- $self->_connect ();
-
- return $self;
-} # new
-
-sub add (%) {
- my ($self, %system) = @_;
-
- my @requiredFields = qw(
- name
- admin
- type
- );
-
- my $result = _checkRequiredFields \@requiredFields, \%system;
-
- return -1, "add: $result" if $result;
-
- $system{loadavgHist} ||= $defaultLoadavgHist;
-
- return $self->_addRecord ('system', %system);
-} # add
-
-sub delete ($) {
- my ($self, $name) = @_;
-
- return $self->_deleteRecord ('system', "name='$name'");
-} # delete
-
-sub update ($%) {
- my ($self, $name, %update) = @_;
-
- return $self->_updateRecord ('system', "name='$name'", %update);
-} # update
-
-sub get ($) {
- my ($self, $system) = @_;
-
- return unless $system;
-
- my @records = $self->_getRecords (
- 'system',
- "name='$system' or alias like '%$system%'"
- );
-
- if ($records[0]) {
- return %{$records[0]};
- } else {
- return;
- } # if
-} # get
-
-sub find (;$) {
- my ($self, $condition) = @_;
-
- return $self->_getRecords ('system', $condition);
-} # find
-
-1;
-
-=pod
-
-=head1 CONFIGURATION AND ENVIRONMENT
-
-MACHINES: If set then points to a flat file containing machine
-names. Note this is providied as a way to quickly use an alternate
-"machine database". As such only minimal information is support.
-
-=head1 DEPENDENCIES
-
- Display
- Rexec
-
-=head1 INCOMPATABILITIES
-
-None yet...
-
-=head1 BUGS AND LIMITATIONS
-
-There are no known bugs in this module.
-
-Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
-
-=head1 LICENSE AND COPYRIGHT
-
-This Perl Module is freely available; 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 Perl Module 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 (L<http://www.gnu.org/copyleft/gpl.html>) for more
-details.
-
-You should have received a copy of the GNU General Public License
-along with this Perl Module; if not, write to the Free Software Foundation,
-Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-reserved.
-
-=cut
# Close any prior opened sessions
$self->logoff if ($self->{handle});
+ # Check to see if this machines is known in DNS. If not then the chance is
+ # good that we will not be able to log in
+ return unless gethostbyname $self->{host};
+
my $remote;
if ($self->{protocol}) {
+++ /dev/null
-system-- -----------------------------------------------------------------------------
---
--- File: $RCSfile: machines.sql,v $
--- Revision: $Revision: 1.0 $
--- Description: Create the machines database
--- Author: Andrew@DeFaria.com
--- Created: Fri Apr 4 10:31:11 PDT 2014
--- Modified: $Date: $
--- Language: SQL
---
--- Copyright (c) 2014, ClearSCM, Inc., all rights reserved
---
--- -----------------------------------------------------------------------------
--- Warning: The following line will delete the old database!
-drop database if exists machines;
-
--- Create a new database
-create database machines;
-
--- Now let's focus on this new database
-use machines;
-
--- system: Define what makes up a system or machine
-create table system (
- name varchar (255) not null,
- alias varchar (255),
- active enum (
- 'true',
- 'false'
- ) not null default 'true',
- admin tinytext,
- email tinytext,
- os tinytext,
- type enum (
- 'Linux',
- 'Unix',
- 'Windows'
- ) not null,
- region tinytext,
- lastheardfrom datetime,
- description text,
- loadavgHist enum (
- '1 month',
- '2 months',
- '3 months',
- '4 months',
- '5 months',
- '6 months',
- '7 months',
- '8 months',
- '9 months',
- '10 months',
- '11 months',
- '1 year'
- ) not null default '6 months',
- loadavgThreshold float (4,2) default 5.00,
-
- primary key (name)
-) engine=innodb; -- system
-
--- package: A package is any software package that we wish to keep track of
-create table package (
- system varchar (255) not null,
- name varchar (255) not null,
- version tinytext not null,
- vendor tinytext,
- description text,
-
- key packageIndex (name),
- key systemIndex (system),
- foreign key systemLink (system) references system (name)
- on delete cascade
- on update cascade,
- primary key (system, name)
-) engine=innodb; -- package
-
--- filesystem: A systems file systems that we are monitoring
-create table filesystem (
- system varchar (255) not null,
- filesystem varchar (255) not null,
- fstype tinytext not null,
- mount tinytext,
- threshold int default 90,
- notification varchar (255),
- filesystemHist enum (
- '1 month',
- '2 months',
- '3 months',
- '4 months',
- '5 months',
- '6 months',
- '7 months',
- '8 months',
- '9 months',
- '10 months',
- '11 months',
- '1 year'
- ) not null default '6 months',
-
- key filesystemIndex (filesystem),
- foreign key systemLink (system) references system (name)
- on delete cascade
- on update cascade,
- primary key (system, filesystem)
-) engine=innodb; -- filesystem
-
--- fs: Contains a snapshot reading of a filesystem at a given date and time
-create table fs (
- system varchar(255) not null,
- filesystem varchar(255) not null,
- mount varchar(255) not null,
- timestamp datetime not null,
- size bigint,
- used bigint,
- free bigint,
- reserve bigint,
-
- key mountIndex (mount),
- primary key (system, filesystem, timestamp),
- foreign key filesystemLink (system, filesystem)
- references filesystem (system, filesystem)
- on delete cascade
- on update cascade
-) engine=innodb; -- fs
-
--- loadavg: Contains a snapshot reading of a system's load average
-create table loadavg (
- system varchar(255) not null,
- timestamp datetime not null,
- uptime tinytext,
- users int,
- loadavg float (4,2),
-
- primary key (system, timestamp),
- foreign key systemLink (system) references system (name)
- on delete cascade
- on update cascade
-) engine=innodb; -- loadavg
\ No newline at end of file