Some changes to Machines and Rexe
[clearscm.git] / lib / machines.sql
1 system-- -----------------------------------------------------------------------------
2 --
3 -- File:        $RCSfile: machines.sql,v $
4 -- Revision:    $Revision: 1.0 $
5 -- Description: Create the machines database
6 -- Author:      Andrew@DeFaria.com
7 -- Created:     Fri Apr  4 10:31:11 PDT 2014
8 -- Modified:    $Date: $
9 -- Language:    SQL
10 --
11 -- Copyright (c) 2014, ClearSCM, Inc., all rights reserved
12 --
13 -- -----------------------------------------------------------------------------
14 -- Warning: The following line will delete the old database!
15 drop database if exists machines;
16
17 -- Create a new database
18 create database machines;
19
20 -- Now let's focus on this new database
21 use machines;
22
23 -- system: Define what makes up a system or machine
24 create table system (
25   name             varchar (255) not null,
26   alias            varchar (255),
27   active           enum (
28                      'true',
29                      'false'
30                    ) not null default 'true',
31   admin            tinytext,
32   email            tinytext,
33   os               tinytext,
34   type             enum (
35                      'Linux',
36                      'Unix',
37                      'Windows'
38                    ) not null,
39   region           tinytext,
40   lastheardfrom    datetime,
41   description      text,
42   loadavgHist      enum (
43                      '1 month',
44                      '2 months',
45                      '3 months',
46                      '4 months',
47                      '5 months',
48                      '6 months',
49                      '7 months',
50                      '8 months',
51                      '9 months',
52                      '10 months',
53                      '11 months',
54                      '1 year'
55                    ) not null default '6 months',
56   loadavgThreshold float (4,2) default 5.00,
57
58   primary key (name)
59 ) engine=innodb; -- system
60
61 -- package: A package is any software package that we wish to keep track of
62 create table package (
63   system      varchar (255) not null,
64   name        varchar (255) not null,
65   version     tinytext not null,
66   vendor      tinytext,
67   description text,
68
69   key packageIndex (name),
70   key systemIndex (system),
71   foreign key systemLink (system) references system (name)
72     on delete cascade
73     on update cascade,
74   primary key (system, name)
75 ) engine=innodb; -- package
76   
77 -- filesystem: A systems file systems that we are monitoring 
78 create table filesystem (
79   system         varchar (255) not null,
80   filesystem     varchar (255) not null,
81   fstype         tinytext not null,
82   mount          tinytext,
83   threshold      int default 90,
84   notification   varchar (255),
85   filesystemHist enum (
86                    '1 month',
87                    '2 months',
88                    '3 months',
89                    '4 months',
90                    '5 months',
91                    '6 months',
92                    '7 months',
93                    '8 months',
94                    '9 months',
95                    '10 months',
96                    '11 months',
97                    '1 year'
98                  ) not null default '6 months',
99   
100   key filesystemIndex (filesystem),
101   foreign key systemLink (system) references system (name)
102     on delete cascade
103     on update cascade,
104   primary key (system, filesystem)
105 ) engine=innodb; -- filesystem
106
107 -- fs: Contains a snapshot reading of a filesystem at a given date and time
108 create table fs (
109   system         varchar(255) not null,
110   filesystem     varchar(255) not null,
111   mount          varchar(255) not null,
112   timestamp      datetime     not null,
113   size           bigint,
114   used           bigint,
115   free           bigint,
116   reserve        bigint,
117
118   key mountIndex (mount), 
119   primary key   (system, filesystem, timestamp),
120   foreign key   filesystemLink (system, filesystem)
121     references filesystem (system, filesystem)
122       on delete cascade
123       on update cascade
124 ) engine=innodb; -- fs
125
126 -- loadavg: Contains a snapshot reading of a system's load average
127 create table loadavg (
128   system        varchar(255)    not null,
129   timestamp     datetime        not null,
130   uptime        tinytext,
131   users         int,
132   loadavg       float (4,2),
133
134   primary key   (system, timestamp),
135   foreign key systemLink (system) references system (name)
136     on delete cascade
137     on update cascade
138 ) engine=innodb; -- loadavg