| 1 | -- |
|---|
| 2 | -- PostgreSQL create schema for CRCnet Configuration Systems billing module |
|---|
| 3 | -- |
|---|
| 4 | -- All prices in these tables should be sales tax exclusive |
|---|
| 5 | -- |
|---|
| 6 | -- Author: Chris Browning <ckb6@cs.waikato.ac.nz> |
|---|
| 7 | -- Matt Brown <matt@crc.net.nz> |
|---|
| 8 | -- Version: $Id$ |
|---|
| 9 | -- |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | CREATE TABLE rrdbot_class ( |
|---|
| 13 | class_id SERIAL PRIMARY KEY, |
|---|
| 14 | class_name varchar(64) UNIQUE NOT NULL, |
|---|
| 15 | poll varchar(64), |
|---|
| 16 | interval integer, |
|---|
| 17 | cf varchar(8), |
|---|
| 18 | archive varchar(256), |
|---|
| 19 | depends integer DEFAULT 0, |
|---|
| 20 | ipfromoid integer, |
|---|
| 21 | skip_software_loop integer, |
|---|
| 22 | key varchar(64) |
|---|
| 23 | ); |
|---|
| 24 | |
|---|
| 25 | CREATE TABLE rrdbot_class_parts ( |
|---|
| 26 | part_id SERIAL PRIMARY KEY, |
|---|
| 27 | class_id integer, |
|---|
| 28 | name varchar(64), |
|---|
| 29 | poll varchar(64), |
|---|
| 30 | type varchar(64), |
|---|
| 31 | min integer DEFAULT NULL, |
|---|
| 32 | max integer DEFAULT NULL |
|---|
| 33 | ); |
|---|
| 34 | |
|---|
| 35 | -- Graph classes that we know about |
|---|
| 36 | CREATE TABLE graph_group ( |
|---|
| 37 | group_id SERIAL PRIMARY KEY, |
|---|
| 38 | group_name varchar(64) |
|---|
| 39 | ); |
|---|
| 40 | |
|---|
| 41 | -- Graphs that we know about |
|---|
| 42 | CREATE TABLE graph_type ( |
|---|
| 43 | graph_id SERIAL PRIMARY KEY, |
|---|
| 44 | group_id integer NOT NULL REFERENCES graph_group (group_id) ON DELETE CASCADE, |
|---|
| 45 | class_id integer NOT NULL REFERENCES rrdbot_class (class_id) ON DELETE CASCADE, |
|---|
| 46 | title varchar(64), |
|---|
| 47 | filename varchar(64), |
|---|
| 48 | virtical_label varchar(64) |
|---|
| 49 | ); |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | -- All the graph parts, relate to a graph by graph_id |
|---|
| 53 | -- ie, LINE, AREA etc |
|---|
| 54 | CREATE TABLE graph_parts ( |
|---|
| 55 | part_id SERIAL PRIMARY KEY, |
|---|
| 56 | graph_id integer NOT NULL REFERENCES graph_type (graph_id) ON DELETE CASCADE, |
|---|
| 57 | graph_order integer, |
|---|
| 58 | type varchar(10), |
|---|
| 59 | colour varchar(20), |
|---|
| 60 | text varchar(64), |
|---|
| 61 | varname varchar(64), |
|---|
| 62 | cf varchar(8), |
|---|
| 63 | filename varchar(128) |
|---|
| 64 | ); |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | CREATE TABLE graph_time ( |
|---|
| 69 | time_id SERIAL PRIMARY KEY, |
|---|
| 70 | start_time varchar(10), |
|---|
| 71 | end_time varchar(10), |
|---|
| 72 | name varchar(20) NOT NULL |
|---|
| 73 | ); |
|---|
| 74 | |
|---|
| 75 | -- rrdbot-script discoveries |
|---|
| 76 | CREATE TABLE snmp_discovery ( |
|---|
| 77 | host_id integer NOT NULL REFERENCES host (host_id) ON DELETE CASCADE, |
|---|
| 78 | --name of class found |
|---|
| 79 | class_id integer NOT NULL REFERENCES rrdbot_class (class_id) ON DELETE CASCADE, |
|---|
| 80 | num varchar(8) NOT NULL, |
|---|
| 81 | ip_address varchar(20), |
|---|
| 82 | link_id integer, |
|---|
| 83 | --Time of last discovery of this class |
|---|
| 84 | timestamp timestamp with time zone NOT NULL DEFAULT NOW() |
|---|
| 85 | ); |
|---|
| 86 | CREATE TABLE snmp_instructions ( |
|---|
| 87 | host_id integer NOT NULL REFERENCES host (host_id) ON DELETE CASCADE, |
|---|
| 88 | instr integer, |
|---|
| 89 | param1 varchar(64), |
|---|
| 90 | param2 varchar(64), |
|---|
| 91 | param3 varchar(64) |
|---|
| 92 | ); |
|---|
| 93 | |
|---|
| 94 | CREATE TABLE snmp_state ( |
|---|
| 95 | state integer NOT NULL |
|---|
| 96 | ); |
|---|
| 97 | |
|---|
| 98 | CREATE VIEW graphview as SELECT a.title, a.group_id, f.group_name, b.link_id, b.ip_address, b.num, a.graph_id, d.host_name, d.host_id, e.description from graph_type a, snmp_discovery b LEFT JOIN link e ON e.link_id=b.link_id, rrdbot_class c, host d, graph_group f WHERE c.class_id=b.class_id AND a.class_id = c.class_id AND d.host_id=b.host_id AND f.group_id=a.group_id; |
|---|
| 99 | |
|---|
| 100 | CREATE VIEW mirrortmp as select a.*, b.host_id as host_id2, b.link_id as link_id2, b.host_name as host_name2, b.graph_id as graph_id2, b.ip_address as ip_address2, b.num as num2 from graphview a, graphview b where b.host_id!=a.host_id AND b.link_id=a.link_id AND b.graph_id=a.graph_id AND a.link_id!=0; |
|---|
| 101 | |
|---|
| 102 | CREATE VIEW mirrorview as SELECT a.*, b.host_id2, b.host_name2, b.ip_address2, b.num2 from graphview a LEFT JOIN mirrortmp b on a.host_id=b.host_id AND a.link_id=b.link_id AND a.graph_id=b.graph_id; |
|---|
| 103 | |
|---|
| 104 | create view rrdbotlog as select a.host_id, a.class_id, c.class_name, b.host_name, a.num, a.ip_address, a.timestamp, a.link_id, d.description from snmp_discovery a LEFT JOIN link d on a.link_id=d.link_id, host b, rrdbot_class c where b.host_id=a.host_id and c.class_id=a.class_id; |
|---|
| 105 | |
|---|
| 106 | -- Required values for graphs |
|---|
| 107 | INSERT INTO graph_time VALUES ( DEFAULT, '-1h', 'now', 'Hour'); |
|---|
| 108 | INSERT INTO graph_time VALUES ( DEFAULT, '-1d', 'now', 'Day'); |
|---|
| 109 | INSERT INTO graph_time VALUES ( DEFAULT, '-1w', 'now', 'Week'); |
|---|
| 110 | INSERT INTO graph_time VALUES ( DEFAULT, '-1m', 'now', 'Month'); |
|---|
| 111 | INSERT INTO graph_time VALUES ( DEFAULT, '-1y', 'now', 'Year'); |
|---|
| 112 | |
|---|
| 113 | INSERT INTO graph_time VALUES ( DEFAULT, '-2h', '-1h', 'Last Hour'); |
|---|
| 114 | INSERT INTO graph_time VALUES ( DEFAULT, '-2d', '-1d', 'Yesturday'); |
|---|
| 115 | INSERT INTO graph_time VALUES ( DEFAULT, '-2w', '-1w', 'Last Week'); |
|---|
| 116 | INSERT INTO graph_time VALUES ( DEFAULT, '-2m', '-1m', 'Last Month'); |
|---|
| 117 | INSERT INTO graph_time VALUES ( DEFAULT, '-2y', '-1y', 'Last Year'); |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | -- Set the initial state |
|---|
| 121 | INSERT INTO snmp_state VALUES ( 0); |
|---|
| 122 | -- vim: ft=sql |
|---|