1 |
rodolico |
1 |
/*
|
|
|
2 |
SQL information for the sysinfo module of CAMP
|
|
|
3 |
Same conventions as in the root SQL, ie
|
|
|
4 |
tablename_id - Primary key for table
|
|
|
5 |
added_date - Date the record was added
|
|
|
6 |
removed_date - Date record was removed/superceded
|
|
|
7 |
*/
|
|
|
8 |
|
|
|
9 |
drop table if exists unknown_entry;
|
|
|
10 |
create table unknown_entry (
|
|
|
11 |
unknown_entry_id int(10) unsigned not null auto_increment,
|
|
|
12 |
client_name varchar(64) not null comment 'Name of the client from the report',
|
|
|
13 |
device_name varchar(64) not null comment 'Name of a device from the report',
|
|
|
14 |
report_date datetime not null comment 'The date of the report that found this entry',
|
|
|
15 |
processed_date datetime default null comment 'When set the entry has been taken care of by a user',
|
|
|
16 |
processed_by int unsigned comment 'The user who processed this entry' references login(login_id),
|
|
|
17 |
primary key (unknown_entry_id)
|
|
|
18 |
) comment='Used to store information on equipment and clients if it is not in the database';
|
|
|
19 |
|
|
|
20 |
DROP TABLE IF EXISTS device_alias;
|
|
|
21 |
CREATE TABLE device_alias (
|
|
|
22 |
device_alias_id int(10) unsigned NOT NULL auto_increment,
|
|
|
23 |
device_id int(10) unsigned NOT NULL REFERENCES device(device_id),
|
|
|
24 |
alias varchar(64) comment 'Name found on report',
|
|
|
25 |
added_date datetime not null,
|
|
|
26 |
removed_date datetime default null,
|
|
|
27 |
PRIMARY KEY (device_alias_id)
|
|
|
28 |
) comment='If the same device has a name change this will track that';
|
|
|
29 |
|
|
|
30 |
alter table device_alias add index (device_id);
|
|
|
31 |
alter table device_alias add index (added_date,removed_date);
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
DROP TABLE IF EXISTS client_alias;
|
|
|
35 |
CREATE TABLE client_alias (
|
|
|
36 |
client_alias_id int(10) unsigned NOT NULL auto_increment,
|
|
|
37 |
client_id int(10) unsigned NOT NULL REFERENCES client(client_id),
|
|
|
38 |
alias varchar(64) comment 'Name found on report',
|
|
|
39 |
added_date datetime not null,
|
|
|
40 |
removed_date datetime default null,
|
|
|
41 |
PRIMARY KEY (client_alias_id)
|
|
|
42 |
) comment='If the same client has a name change this will track that';
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
DROP TABLE IF EXISTS computer_uptime;
|
|
|
46 |
CREATE TABLE computer_uptime (
|
|
|
47 |
computer_uptime_id int(10) unsigned NOT NULL auto_increment,
|
|
|
48 |
device_id int(10) unsigned NOT NULL REFERENCES device(device_id),
|
|
|
49 |
last_reboot datetime default NULL COMMENT 'date and time of last reboot',
|
|
|
50 |
added_date datetime default NULL COMMENT 'date record was added',
|
|
|
51 |
removed_date datetime default NULL COMMENT 'date record was deleted/supserceded',
|
|
|
52 |
PRIMARY KEY (computer_uptime_id)
|
|
|
53 |
) COMMENT='Tracks the computer uptime by storing the last reboot';
|
|
|
54 |
|
|
|
55 |
alter table computer_uptime add index (device_id);
|
|
|
56 |
alter table computer_uptime add index (added_date,removed_date);
|
|
|
57 |
|
|
|
58 |
|
|
|
59 |
DROP TABLE IF EXISTS device_operating_system;
|
|
|
60 |
CREATE TABLE device_operating_system (
|
|
|
61 |
device_id int(10) unsigned NOT NULL REFERENCES device(device_id),
|
|
|
62 |
operating_system_id int(10) unsigned NOT NULL COMMENT 'a link to the operating_system table',
|
|
|
63 |
added_date datetime default NULL COMMENT 'date record was added',
|
|
|
64 |
removed_date datetime default null COMMENT 'date record was deleted/supserceded',
|
|
|
65 |
PRIMARY KEY (device_id,operating_system_id,removed_date)
|
|
|
66 |
) COMMENT='links devices and their operating systems together';
|
|
|
67 |
|
|
|
68 |
DROP TABLE IF EXISTS disk_info;
|
|
|
69 |
CREATE TABLE disk_info (
|
|
|
70 |
disk_info_id int(10) unsigned NOT NULL auto_increment,
|
|
|
71 |
device_id int(10) unsigned NOT NULL REFERENCES device(device_id),
|
|
|
72 |
disk_device varchar(64) default NULL COMMENT 'actual device name generally partition name',
|
|
|
73 |
filesystem varchar(32) default NULL COMMENT 'the file system ext3 ntfs with which this if formatted',
|
|
|
74 |
mount_point varchar(64) default NULL COMMENT 'place on file system where this is mounted or drive letter for Windows',
|
|
|
75 |
capacity decimal(12,0) default NULL COMMENT 'size in kilobytes of partition',
|
|
|
76 |
added_date datetime default NULL COMMENT 'date record was added',
|
|
|
77 |
removed_date datetime default NULL COMMENT 'date record was deleted/supserceded',
|
|
|
78 |
PRIMARY KEY (disk_info_id),
|
|
|
79 |
key (device_id),
|
|
|
80 |
key (added_date,removed_date)
|
|
|
81 |
) COMMENT='stores static information about a hard disk ie capacity';
|
|
|
82 |
|
|
|
83 |
|
|
|
84 |
DROP TABLE IF EXISTS disk_space;
|
|
|
85 |
CREATE TABLE disk_space (
|
|
|
86 |
disk_space_id int(10) unsigned NOT NULL auto_increment,
|
|
|
87 |
disk_info_id int(10) unsigned NOT NULL references disk_info(disk_info_id),
|
|
|
88 |
space_used decimal(12,0) default NULL COMMENT 'space used in kilobytes',
|
|
|
89 |
added_date datetime default NULL COMMENT 'date record was added',
|
|
|
90 |
removed_date datetime default NULL COMMENT 'date record was deleted/supserceded',
|
|
|
91 |
PRIMARY KEY (disk_space_id),
|
|
|
92 |
KEY (disk_info_id,added_date)
|
|
|
93 |
) COMMENT='stores dynamic information about a partition ie amount of u';
|
|
|
94 |
|
|
|
95 |
|
|
|
96 |
DROP TABLE IF EXISTS installed_packages;
|
|
|
97 |
CREATE TABLE installed_packages (
|
|
|
98 |
installed_packages_id int(10) unsigned NOT NULL auto_increment,
|
|
|
99 |
device_id int(10) unsigned NOT NULL REFERENCES device(device_id),
|
|
|
100 |
software_id int(10) unsigned NOT NULL COMMENT 'link into software table',
|
|
|
101 |
software_version_id int(10) unsigned NOT NULL COMMENT 'link into software_version table',
|
|
|
102 |
added_date datetime default NULL COMMENT 'date record was added',
|
|
|
103 |
removed_date datetime default NULL COMMENT 'date record was deleted/supserceded',
|
|
|
104 |
PRIMARY KEY (installed_packages_id)
|
|
|
105 |
) COMMENT='tracks software packages installed on a computer';
|
|
|
106 |
|
|
|
107 |
DROP TABLE IF EXISTS network;
|
|
|
108 |
CREATE TABLE network (
|
|
|
109 |
network_id int(10) unsigned NOT NULL auto_increment,
|
|
|
110 |
device_id int(10) unsigned NOT NULL REFERENCES device(device_id),
|
|
|
111 |
interface varchar(32) default NULL comment 'the interface. eth0 whatever used. Note that some interface names can be long',
|
|
|
112 |
address char(15) default NULL comment 'The IP4 Address associated here',
|
|
|
113 |
netmask char(15) default NULL comment 'The subnet netmask',
|
|
|
114 |
ip6 varchar(32) default NULL comment 'If provided the IP6 address',
|
|
|
115 |
ip6net int(10) unsigned default NULL comment 'If provided the IP6 subnet mask',
|
|
|
116 |
mtu int(10) unsigned default NULL comment 'MTU value',
|
|
|
117 |
mac varchar(20) default NULL comment 'MAC hardware address',
|
|
|
118 |
added_date datetime default NULL,
|
|
|
119 |
removed_date datetime default NULL,
|
|
|
120 |
PRIMARY KEY (network_id),
|
|
|
121 |
KEY device_id (device_id,added_date)
|
|
|
122 |
) comment='Tracks multiple physical and virtual network interfaces on a machine';
|
|
|
123 |
|
|
|
124 |
DROP TABLE IF EXISTS operating_system;
|
|
|
125 |
CREATE TABLE operating_system (
|
|
|
126 |
operating_system_id int(10) unsigned NOT NULL auto_increment,
|
|
|
127 |
name varchar(255) default NULL COMMENT 'Name of the OS',
|
|
|
128 |
version text COMMENT 'Version. Note this is a very large field in some cases',
|
|
|
129 |
kernel varchar(255) default NULL COMMENT 'kernel information',
|
|
|
130 |
distro varchar(255) default NULL COMMENT 'For Linux the distribution name',
|
|
|
131 |
distro_description varchar(255) default NULL COMMENT 'For Linux the distribution description',
|
|
|
132 |
distro_release varchar(255) default NULL COMMENT 'For Linux the distribution release',
|
|
|
133 |
distro_codename varchar(255) default NULL COMMENT 'For Linux the distribution code name',
|
|
|
134 |
added_date datetime default NULL COMMENT 'date record was added',
|
|
|
135 |
removed_date datetime default NULL COMMENT 'date record was closed',
|
|
|
136 |
PRIMARY KEY (operating_system_id)
|
|
|
137 |
) COMMENT='used to track the operating system version on computers';
|
|
|
138 |
|
|
|
139 |
DROP TABLE IF EXISTS software;
|
|
|
140 |
CREATE TABLE software (
|
|
|
141 |
software_id int(10) unsigned NOT NULL auto_increment,
|
|
|
142 |
package_name varchar(64) default NULL COMMENT 'actual name of software package',
|
|
|
143 |
description varchar(64) default NULL COMMENT 'any additional description',
|
|
|
144 |
added_date datetime default NULL COMMENT 'date record was added',
|
|
|
145 |
removed_date datetime default NULL COMMENT 'date record was deleted/supserceded',
|
|
|
146 |
PRIMARY KEY (software_id)
|
|
|
147 |
) COMMENT='master table containing information about various software p';
|
|
|
148 |
|
|
|
149 |
DROP TABLE IF EXISTS software_version;
|
|
|
150 |
CREATE TABLE software_version (
|
|
|
151 |
software_version_id int(10) unsigned NOT NULL auto_increment,
|
|
|
152 |
version varchar(64) default NULL COMMENT 'version number',
|
|
|
153 |
added_date datetime default NULL COMMENT 'date record was added',
|
|
|
154 |
removed_date datetime default NULL COMMENT 'date record was deleted/supserceded',
|
|
|
155 |
PRIMARY KEY (software_version_id)
|
|
|
156 |
) COMMENT='Master table to simply track version numbers';
|
|
|
157 |
|
|
|
158 |
DROP TABLE IF EXISTS sysinfo_report;
|
|
|
159 |
CREATE TABLE sysinfo_report (
|
|
|
160 |
sysinfo_report_id int(10) unsigned NOT NULL auto_increment,
|
|
|
161 |
device_id int(10) unsigned NOT NULL REFERENCES device(device_id),
|
|
|
162 |
version varchar(5) not null default '1.0' comment 'The version of the client',
|
|
|
163 |
report_date datetime default NULL,
|
|
|
164 |
added_date datetime default NULL,
|
|
|
165 |
PRIMARY KEY (sysinfo_report_id),
|
|
|
166 |
KEY device_id (device_id,report_date)
|
|
|
167 |
) comment='Tracks when reports come in for each device';
|
|
|
168 |
|
|
|
169 |
/* Now, populate the tables */
|
|
|
170 |
insert into _system ( group_name,key_name,theValue,added_date) values ( 'Modules', 'Sysinfo', 'modules/sysinfo/', now() );
|
|
|
171 |
insert into menu (parent_id,caption,url) values (null,'SysInfo','/modules/sysinfo/index.html');
|
|
|
172 |
insert into menu (parent_id,caption,url) select menu_id,'Manual Upload','/modules/sysinfo/index.html' from menu where caption = 'SysInfo';
|
|
|
173 |
insert into menu (parent_id,caption,url) select menu_id,'Unknowns','/modules/sysinfo/process_unknowns.html' from menu where caption = 'SysInfo';
|
|
|
174 |
insert into menu (parent_id,caption,url) select menu_id,'Download','/modules/sysinfo/get_client.html' from menu where caption = 'SysInfo';
|
|
|
175 |
|
|
|
176 |
/* define reports */
|
|
|
177 |
|
|
|
178 |
/* Installed Packages list report */
|
|
|
179 |
insert into report ( name, query, parameters ) values ('Installed Packages','select client_site.name Client,
|
|
|
180 |
device.name Device,
|
|
|
181 |
software.package_name Package,
|
|
|
182 |
software_version.version Version
|
|
|
183 |
from client_site join device using (site_id)
|
|
|
184 |
join installed_packages using (device_id)
|
|
|
185 |
join software using (software_id)
|
|
|
186 |
join software_version using (software_version_id)
|
|
|
187 |
where device.device_id = <device_id>
|
|
|
188 |
order by package_name,version','device_id++System++select * from client_systems order by device++select name from device where device_id=<value>');
|
|
|
189 |
|
|
|
190 |
/* Count of packages currently installed on all systems */
|
|
|
191 |
insert into report ( name, query, parameters ) values ('Software Install Counts','select software.software_id ID,
|
|
|
192 |
software.package_name Package,
|
|
|
193 |
count(*) Installations
|
|
|
194 |
from installed_packages join software using (software_id)
|
|
|
195 |
where installed_packages.removed_date is null
|
|
|
196 |
group by software.software_id,package_name
|
|
|
197 |
order by software.package_name','');
|
|
|
198 |
|
|
|
199 |
/* Find what was on a system during a particular date */
|
|
|
200 |
insert into report ( name, query, parameters ) values ('Software Revisions for System','select date(installed_packages.added_date) \'Added\',
|
|
|
201 |
date(installed_packages.removed_date) \'Removed\',
|
|
|
202 |
device.name \'Device\',
|
|
|
203 |
package_name \'Package\',
|
|
|
204 |
version \'Version\'
|
|
|
205 |
from installed_packages join software using (software_id)
|
|
|
206 |
join software_version using (software_version_id)
|
|
|
207 |
join device using (device_id)
|
|
|
208 |
join site using (site_id)
|
|
|
209 |
join client using (client_id)
|
|
|
210 |
where device.device_id = <device_id>
|
|
|
211 |
and (installed_packages.removed_date is null or
|
|
|
212 |
installed_packages.removed_date > <end_date>)
|
|
|
213 |
and installed_packages.added_date < <end_date>
|
|
|
214 |
and installed_packages.added_date >= <start_date>
|
|
|
215 |
order by device.name,package_name,installed_packages.added_date
|
|
|
216 |
','device_id++System++select * from client_systems order by device++select name from device where device_id=<value>
|
|
|
217 |
start_date++Start Date++++
|
|
|
218 |
end_date++End Date++++');
|
|
|
219 |
|
|
|
220 |
/* Current Disk Usage */
|
|
|
221 |
insert into report ( name, query, parameters ) values ('Current Disk Usage','select device.name,
|
|
|
222 |
date(disk_space.added_date) \'Date Added\',
|
|
|
223 |
lpad(format(space_used/capacity*100, 0), 3, \' \') \"used %\",
|
|
|
224 |
lpad(format(space_used/1048576,2), 10, \' \') used,
|
|
|
225 |
lpad(format(capacity/1048576,2), 10, \' \') Part_Size,
|
|
|
226 |
mount_point,
|
|
|
227 |
disk_device,
|
|
|
228 |
filesystem
|
|
|
229 |
from device join disk_info on disk_info.device_id = device.device_id
|
|
|
230 |
join disk_space on disk_info.disk_info_id=disk_space.disk_info_id
|
|
|
231 |
where disk_info.removed_date is null
|
|
|
232 |
and device.removed_date is null
|
|
|
233 |
and disk_space.added_date = (select max(added_date) from disk_space b where b.disk_info_id = disk_space.disk_info_id)
|
|
|
234 |
order by device.name,disk_device
|
|
|
235 |
','');
|
|
|
236 |
|
|
|
237 |
/* Following reports are added to the Device Display in the main module. ORDER IS IMPORTANT as the first reports will be the first */
|
|
|
238 |
/* ones displayed. */
|
|
|
239 |
|
|
|
240 |
/* Sysinfo Reports */
|
|
|
241 |
insert into report( name, query, parameters, screen_report ) values ('Sysinfo Reports','select min(concat(date(report_date),\' (v\', version, \')\' )) "First Sysinfo Report", max(concat(date(report_date),\' (v\', version, \')\' )) "Latest Sysinfo Report" from sysinfo_report where device_id = <device_id>',
|
|
|
242 |
'device_id++Device++select device_id,name from device where removed_date is null++select name from device where device_id = <value>', 1);
|
|
|
243 |
|
|
|
244 |
/* Network Report */
|
|
|
245 |
insert into report( name, query, parameters, screen_report ) values ('Device Network','select interface "Port",address "IP Address",netmask "Netmask",mac "Mac" from network where removed_date is null and device_id = <device_id>',
|
|
|
246 |
'device_id++Device++select device_id,name from device where removed_date is null++select name from device where device_id = <value>', 1);
|
|
|
247 |
|
|
|
248 |
/* Current Disk Usage */
|
|
|
249 |
insert into report ( name, query, parameters,screen_report ) values ('Device Disk Usage','select date(disk_space.added_date) \'Date Added\',
|
|
|
250 |
lpad(format(space_used/capacity*100, 0), 3, \' \') "used %",
|
|
|
251 |
lpad(format(space_used/1048576,2), 10, \' \') used,
|
|
|
252 |
lpad(format(capacity/1048576,2), 10, \' \') Part_Size,
|
|
|
253 |
mount_point,
|
|
|
254 |
disk_device,
|
|
|
255 |
filesystem
|
|
|
256 |
from disk_info join disk_space using (disk_info_id)
|
|
|
257 |
where disk_info.device_id = <device_id>
|
|
|
258 |
and disk_info.removed_date is null
|
|
|
259 |
and disk_space.added_date = (select max(report_date) from sysinfo_report where device_id = <device_id>)
|
|
|
260 |
order by disk_device',
|
|
|
261 |
'device_id++Device++select device_id,name from device where removed_date is null++select name from device where device_id = <value>', 1
|
|
|
262 |
);
|
|
|
263 |
|
|
|
264 |
insert into report( name, query, parameters, screen_report ) values ('Device PCI','select device_attrib.value Slot,
|
|
|
265 |
device.name Card
|
|
|
266 |
from device join device_attrib using (device_id)
|
|
|
267 |
join attrib using (attrib_id)
|
|
|
268 |
where part_of = <device_id>
|
|
|
269 |
and attrib.name = \'Slot\'
|
|
|
270 |
and device.removed_date is null
|
|
|
271 |
order by device_attrib.value',
|
|
|
272 |
'device_id++Device++select device_id,name from device where removed_date is null++select name from device where device_id = <value>', 1);
|