Added caching to clearadm
[clearscm.git] / clearadm / lib / clearadm.sql
1 -- -----------------------------------------------------------------------------
2 --
3 -- File:        $RCSfile: clearadm.sql,v $
4 -- Revision:    $Revision: 1.23 $
5 -- Description: Create the clearadm database
6 -- Author:      Andrew@DeFaria.com
7 -- Created:     Tue Nov 30 08:46:42 EST 2010
8 -- Modified:    $Date: 2011/02/09 13:28:33 $
9 -- Language:    SQL
10 --
11 -- Copyright (c) 2010, ClearSCM, Inc., all rights reserved
12 --
13 -- -----------------------------------------------------------------------------
14 -- Warning: The following line will delete the old database!
15 -- drop database if exists clearadm;
16
17 -- Create a new database
18 create database clearadm;
19
20 -- Now let's focus on this new database
21 use clearadm;
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   port             int default 25327,
41   lastheardfrom    datetime,
42   notification     varchar (255),
43   description        text,
44   loadavgHist      enum (
45                      '1 month',
46                      '2 months',
47                      '3 months',
48                      '4 months',
49                      '5 months',
50                      '6 months',
51                      '7 months',
52                      '8 months',
53                      '9 months',
54                      '10 months',
55                      '11 months',
56                      '1 year'
57                    ) not null default '6 months',
58   loadavgThreshold float (4,2) default 5.00,
59   loadavgsmall     blob,
60   loadavg          blob,
61
62   primary key (name)
63 ) engine=innodb; -- system
64
65 -- clearcase: Information about a Clearcase system
66 create table clearcase (
67   system                    varchar (255) not null,
68   ccver                     tinytext,
69   hardware                  tinytext,
70   licenseHost               tinytext,
71   registryHost              tinytext,
72   mvfsBlocksPerDirectory    int,
73   mvfsCleartextMnodes       int,
74   mvfsDirectoryNames        int,
75   mvfsFileNames             int,
76   mvfsFreeMnodes            int,
77   mvfsInitialMnodeTableSize int,
78   mvfsMinCleartextMnodes    int,
79   mvfsMinFreeMnodes         int,
80   mvfsNamesNotFound         int,
81   mvfsRPCHandles            int,
82   interopRegion             int,
83   scalingFactor             int,
84   cleartextIdleLifetime     int,
85   vobHashTableSize          int,
86   cleartextHashTableSize    int,
87   dncHashTableSize          int,
88   threadHashTableSize       int,
89   processHashTableSize      int,
90
91   foreign key systemLink (system) references system (name) 
92     on delete cascade
93     on update cascade,
94   primary key (system)
95 ) engine=innodb; -- clearcase
96
97 -- package: A package is any software package that we wish to keep track of
98 create table package (
99   system      varchar (255) not null,
100   name        varchar (255) not null,
101   version     tinytext not null,
102   vendor      tinytext,
103   description text,
104
105   key packageIndex (name),
106   key systemIndex (system),
107   foreign key systemLink (system) references system (name)
108     on delete cascade
109     on update cascade,
110   primary key (system, name)
111 ) engine=innodb; -- package
112   
113 -- filesystem: A systems file systems that we are monitoring 
114 create table filesystem (
115   system         varchar (255) not null,
116   filesystem     varchar (255) not null,
117   fstype         tinytext not null,
118   mount          tinytext,
119   threshold      int default 90,
120   notification   varchar (255),
121   filesystemHist enum (
122                    '1 month',
123                    '2 months',
124                    '3 months',
125                    '4 months',
126                    '5 months',
127                    '6 months',
128                    '7 months',
129                    '8 months',
130                    '9 months',
131                    '10 months',
132                    '11 months',
133                    '1 year'
134                  ) not null default '6 months',
135   fssmall        blob,
136   fslarge        blob,
137   
138   key filesystemIndex (filesystem),
139   foreign key systemLink (system) references system (name)
140     on delete cascade
141     on update cascade,
142   primary key (system, filesystem)
143 ) engine=innodb; -- filesystem
144
145 -- fs: Contains a snapshot reading of a filesystem at a given date and time
146 create table fs (
147   system         varchar(255) not null,
148   filesystem     varchar(255) not null,
149   mount          varchar(255) not null,
150   timestamp      datetime     not null,
151   size           bigint,
152   used           bigint,
153   free           bigint,
154   reserve        bigint,
155
156   key mountIndex (mount), 
157   primary key   (system, filesystem, timestamp),
158   foreign key   filesystemLink (system, filesystem)
159     references filesystem (system, filesystem)
160       on delete cascade
161       on update cascade
162 ) engine=innodb; -- fs
163
164 -- vobstorage: Contains a snapshot of a vob's storage pools at a given date
165 -- and time
166 create table vobstorage (
167   tag             varchar(255) not null,
168   region          varchar(255) not null,
169   timestamp       datetime     not null,
170   admin           decimal(10,1),
171   db              decimal(10,1),
172   cleartext       decimal(10,1),
173   derivedobj      decimal(10,1),
174   source          decimal(10,1),
175   total           decimal(10,1),
176
177   key vobtagIndex (tag),
178   primary key  (tag, region, timestamp)
179   foreign key vobLink (tag, region)
180     references vob (tag, region)
181       on delete cascade
182       on update cascade
183 ) engine=innodb; -- vobstorage
184
185 -- viewstorage: Contains a snapshot of a view's storage pools at a given date
186 -- and time
187 create table viewstorage (
188   tag           varchar(255) not null,
189   region        varchar(255) not null,
190   timestamp     datetime     not null,
191   private       decimal(10,1),
192   db            decimal(10,1),
193   admin         decimal(10,1),
194   total         decimal(10,1),
195
196   key viewtagIndex (tag),
197   primary key (tag, region, timestamp)
198 ) engine=innodb; -- viewstorage
199
200 -- loadavg: Contains a snapshot reading of a system's load average
201 create table loadavg (
202   system        varchar(255)    not null,
203   timestamp     datetime        not null,
204   uptime        tinytext,
205   users         int,
206   loadavg       float (4,2),
207
208   primary key   (system, timestamp),
209   foreign key systemLink (system) references system (name)
210     on delete cascade
211     on update cascade
212 ) engine=innodb; -- loadavg
213
214 -- vob: Describe a system's vobs
215 create table vob (
216   tag             varchar (255) not null,
217   region          varchar (255) not null,
218   adminsmall      blob,
219   dbsmall         blob,
220   cleartextsmall  blob,
221   derivedobjsmall blob,
222   sourcesmall     blob,
223   totalsmall      blob,
224   adminlarge      blob,
225   dblarge         blob,
226   cleartextlarge  blob,
227   derivedobjlarge blob,
228   sourcelarge     blob,
229   totallarge      blob,
230   
231   key vobTagIndex (tag),
232   primary key (tag, region)
233 ) engine=innodb; -- vob 
234
235 -- view: Describe views
236 create table view (
237   tag          varchar (255) not null,
238   region       varchar (255) not null,
239   owner        tinytext,
240   ownerName    tinytext,
241   email        tinytext,
242   type         enum (
243                  'dynamic',
244                  'snapshot',
245                  'web'
246                ) not null default 'dynamic',
247   gpath        tinytext,
248   modified     datetime,
249   timestamp    datetime,
250   age          tinytext,
251   ageSuffix    tinytext,
252   privatesmall blob,
253   dbsmall      blob,
254   adminsmall   blob,
255   totalsmall   blob,
256   privatelarge blob,
257   dblarge      blob,
258   adminlarge   blob,
259   totallarge   blob,
260   
261   key viewTagIndex (tag),
262   primary key (tag, region)
263 ) engine=innodb; -- view
264
265 create table task (
266   name          varchar (255) not null,
267   system        varchar (255),
268   description   text,
269   command       text not null,
270   restartable   enum (
271                   'true',
272                   'false'
273                 ) not null default 'true',
274   
275   primary key (name)
276 --  primary key (name),
277 --  foreign key systemLink (system) references system (name)
278 --    on delete cascade
279 --    on update cascade
280 ) engine=innodb; -- task
281
282 create table runlog (
283   id            int not null auto_increment,
284   task          varchar (255) not null,
285   system        varchar (255),
286   started       datetime,
287   ended         datetime,
288   alerted       enum (
289                   'true',
290                   'false'
291                 ) not null default 'false',
292   status        int,
293   message       text,
294   
295   primary key (id, task, system),
296   foreign key taskLink (task) references task (name)
297     on delete cascade
298     on update cascade,
299   foreign key systemLink (system) references system (name)
300     on delete cascade
301     on update cascade
302 ) engine=innodb; -- runlog
303   
304 create table alert (
305   name varchar (255) not null,
306   type enum (
307          'email',
308          'page',
309          'im'
310        ) not null default 'email',
311   who  tinytext,
312   
313   primary key (name)
314 ) engine=innodb; -- alert
315
316 create table notification (
317   name         varchar (255) not null,
318   alert        varchar (255) not null,
319   cond         tinytext not null,
320   nomorethan   enum (
321                  'Once an hour',
322                  'Once a day',
323                  'Once a week',
324                  'Once a month'
325                ) not null default 'Once a day',
326   
327   primary key (name),
328   foreign key alertLink (alert) references alert (name)
329     on delete cascade
330     on update cascade
331  ) engine=innodb; -- notification
332  
333 create table schedule (
334   name          varchar (255) not null,
335   task          varchar (255) not null,
336   notification  varchar (255) not null,
337   frequency     tinytext,
338   active        enum (
339                   'true',
340                   'false'
341                 ) not null default 'true',
342   lastrunid     int,
343   
344   primary key (name),
345   foreign key taskLink (task) references task (name)
346     on delete cascade
347     on update cascade,
348   foreign key notificationLink (notification) references notification (name)
349     on delete cascade
350     on update cascade
351 ) engine=innodb; -- schedule
352
353 create table alertlog (
354   id           int not null auto_increment,
355   alert        varchar (255) not null,
356   system       varchar (255) not null,
357   notification varchar (255) not null,
358   runlog       int not null,
359   timestamp    datetime,
360   message      text,
361   
362   primary key (id, alert),
363   key         (system),
364   foreign key alertLink (alert) references alert (name)
365     on delete cascade
366     on update cascade,
367   foreign key notificationLink (notification) references notification (name)
368     on delete cascade
369     on update cascade,
370   foreign key runlogLink (runlog) references runlog (id)
371     on delete cascade
372     on update cascade
373 ) engine=innodb; -- alertlog