/
create.sql
2527 lines (2257 loc) · 103 KB
/
create.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--# create.sql -- SQL to build the initial tables for the OpenNMS Project
--#
--# Modifications:
--# 2013 Nov 15: Added protocol field in datalinkinterface table
--# 2009 Sep 29: Added linkTypeId field in datalinkinterface table
--# 2009 Mar 27: Added Users, Groups tables
--# 2009 Jan 28: Added Acks tables - david@opennms.org
--# 2007 Apr 10: Added statistics report tables - dj@opennms.org
--# 2006 Apr 17: Added pathOutage table
--# 2005 Mar 11: Added alarms table
--# 2004 Aug 30: See create.sql.changes
--#
--# Copyright (C) 1999-2015 The OpenNMS Group, Inc.
--# OpenNMS(R) is Copyright (C) 1999-2014 The OpenNMS Group, Inc.
--#
--# OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
--#
--# OpenNMS(R) is free software: you can redistribute it and/or modify
--# it under the terms of the GNU Affero General Public License as published
--# by the Free Software Foundation, either version 3 of the License,
--# or (at your option) any later version.
--#
--# OpenNMS(R) 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 Affero General Public License for more details.
--#
--# You should have received a copy of the GNU Affero General Public License
--# along with OpenNMS(R). If not, see:
--# http://www.gnu.org/licenses/
--#
--# For more information contact:
--# OpenNMS(R) Licensing <license@opennms.org>
--# http://www.opennms.org/
--# http://www.opennms.com/
drop table accessLocks cascade;
drop table accesspoints cascade;
drop table requisitioned_categories cascade;
drop table category_node cascade;
drop table categories cascade;
drop table assets cascade;
drop table usersNotified cascade;
drop table notifications cascade;
drop table outages cascade;
drop table ifServices cascade;
drop table snmpInterface cascade;
drop table ipInterface cascade;
drop table alarms cascade;
drop table memos cascade;
drop table node cascade;
drop table service cascade;
drop table scanreports cascade;
drop table monitoringlocations cascade;
drop table monitoringlocationspollingpackages cascade;
drop table monitoringlocationscollectionpackages cascade;
drop table monitoringlocationstags cascade;
drop table monitoringsystems cascade;
drop table events cascade;
drop table event_parameters cascade;
drop table pathOutage cascade;
drop table demandPolls cascade;
drop table pollResults cascade;
drop table reportLocator cascade;
drop table atinterface cascade;
drop table stpnode cascade;
drop table stpinterface cascade;
drop table iprouteinterface cascade;
drop table datalinkinterface cascade;
drop table inventory cascade;
drop table element cascade;
drop table map cascade;
drop table location_specific_status_changes cascade;
drop table vlan cascade;
drop table statisticsReportData cascade;
drop table resourceReference cascade;
drop table statisticsReport cascade;
drop table acks cascade;
drop table users cascade;
drop table groups cascade;
drop table group_user cascade;
drop table category_user cascade;
drop table category_group cascade;
drop table filterfavorites cascade;
drop table hwentity cascade;
drop table hwentityattribute cascade;
drop table hwentityattributetype cascade;
drop sequence catNxtId;
drop sequence nodeNxtId;
drop sequence serviceNxtId;
drop sequence eventsNxtId;
drop sequence alarmsNxtId;
drop sequence memoNxtId;
drop sequence outageNxtId;
drop sequence notifyNxtId;
drop sequence userNotifNxtId;
drop sequence demandPollNxtId;
drop sequence pollResultNxtId;
drop sequence reportNxtId;
drop sequence reportCatalogNxtId;
drop sequence mapNxtId;
drop sequence opennmsNxtId; --# should be used for all sequences, eventually
drop sequence filternextid;
drop index filternamesidx;
--# Begin quartz persistence
--# Legacy quartz 1.X tables
drop table qrtz_job_listeners;
drop table qrtz_trigger_listeners;
drop table qrtz_fired_triggers;
drop table qrtz_paused_trigger_grps;
drop table qrtz_scheduler_state;
drop table qrtz_locks;
drop table qrtz_simple_triggers;
drop table qrtz_cron_triggers;
drop table qrtz_simprop_triggers;
drop table qrtz_blob_triggers;
drop table qrtz_triggers;
drop table qrtz_job_details;
drop table qrtz_calendars;
--# End quartz persistence
CREATE FUNCTION plpgsql_call_handler ()
RETURNS OPAQUE AS '$libdir/plpgsql.so' LANGUAGE 'c';
CREATE TRUSTED PROCEDURAL LANGUAGE 'plpgsql'
HANDLER plpgsql_call_handler LANCOMPILER 'PL/pgSQL';
--##################################################################
--# The following commands set up automatic sequencing functionality
--# for fields which require this.
--#
--# DO NOT forget to add an "install" comment so that the installer
--# knows to fix and renumber the sequences if need be
--##################################################################
--# Sequence for the nodeID column in the aggregate_status_views and the
--# aggregate_status_definitions tables (eventually all tables, perhaps)
--# sequence, column, table
--# install: opennmsNxtId id aggregate_status_views
create sequence opennmsNxtId minvalue 1;
--# Sequence for the nodeID column in the node table
--# sequence, column, table
--# install: nodeNxtId nodeID node
create sequence nodeNxtId minvalue 1;
--# Sequence for the serviceID column in the service table
--# sequence, column, table
--# install: serviceNxtId serviceID service
create sequence serviceNxtId minvalue 1;
--# Sequence for the eventID column in the events table
--# sequence, column, table
--# install: eventsNxtId eventID events
create sequence eventsNxtId minvalue 1;
--# Sequence for the alarmId column in the alarms table
--# sequence, column, table
--# install: alarmsNxtId alarmId alarms
create sequence alarmsNxtId minvalue 1;
--# Sequence for the id column in the memos table
--# sequence, column, table
--# install: memoNxtId id memos
create sequence memoNxtId minvalue 1;
--# Sequence for the outageID column in the outages table
--# sequence, column, table
--# install: outageNxtId outageID outages
create sequence outageNxtId minvalue 1;
--# Sequence for the notifyID column in the notification table
--# sequence, column, table
--# install: notifyNxtId notifyID notifications
create sequence notifyNxtId minvalue 1;
--# Sequence for the id column in the categories table
--# sequence, column, table
--# install: catNxtId categoryid categories
create sequence catNxtId minvalue 1;
--# Sequence for the id column in the usersNotified table
--# sequence, column, table
--# install: userNotifNxtId id usersNotified
create sequence userNotifNxtId minvalue 1;
--# Sequence for the id column in the demandPolls table
--# sequence, column, table
--# install: demandPollNxtId id demandPolls
create sequence demandPollNxtId minvalue 1;
--# Sequence for the id column in the pollResults table
--# sequence, column, table
--# install: pollResultNxtId id pollResults
create sequence pollResultNxtId minvalue 1;
--# Sequence for the mapID column in the map table
--# sequence, column, table
--# install: mapNxtId mapid map
create sequence mapNxtId minvalue 1;
--# Sequence for the filterid column in the filterfavorites table
--# sequence, column, table
--# install: filternextid filterid filterfavorites
create sequence filternextid minvalue 1;
--# A table to use to manage upsert access
CREATE TABLE accessLocks (
lockName varchar(40) not null,
constraint pk_accessLocks PRIMARY KEY (lockName)
);
--#####################################################
--# monitoringlocations Table - Contains a list of network locations
--# that are being monitored by OpenNMS systems in this cluster
--#
--# This table contains the following information:
--#
--# id : The unique name of the location
--# monitoringarea: The monitoring location associated with the system
--# geolocation : Address used for geolocating the location
--# coordinates : Latitude/longitude coordinates determined by geolocating
--# the value of 'geolocation'
--# priority : Integer priority used to layer items in the UI
--#
--#####################################################
CREATE TABLE monitoringlocations (
id TEXT NOT NULL,
monitoringarea TEXT NOT NULL,
geolocation TEXT,
latitude DOUBLE PRECISION,
longitude DOUBLE PRECISION,
priority INTEGER,
CONSTRAINT monitoringlocations_pkey PRIMARY KEY (id)
);
CREATE TABLE monitoringlocationspollingpackages (
monitoringlocationid TEXT NOT NULL,
packagename TEXT NOT NULL,
CONSTRAINT monitoringlocationspollingpackages_fkey FOREIGN KEY (monitoringlocationid) REFERENCES monitoringlocations (id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE INDEX monitoringlocationspollingpackages_id_idx on monitoringlocationspollingpackages(monitoringlocationid);
CREATE UNIQUE INDEX monitoringlocationspollingpackages_id_pkg_idx on monitoringlocationspollingpackages(monitoringlocationid, packagename);
CREATE TABLE monitoringlocationscollectionpackages (
monitoringlocationid TEXT NOT NULL,
packagename TEXT NOT NULL,
CONSTRAINT monitoringlocationscollectionpackages_fkey FOREIGN KEY (monitoringlocationid) REFERENCES monitoringlocations (id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE INDEX monitoringlocationscollectionpackages_id_idx on monitoringlocationscollectionpackages(monitoringlocationid);
CREATE UNIQUE INDEX monitoringlocationscollectionpackages_id_pkg_idx on monitoringlocationscollectionpackages(monitoringlocationid, packagename);
CREATE TABLE monitoringlocationstags (
monitoringlocationid TEXT NOT NULL,
tag TEXT NOT NULL,
CONSTRAINT monitoringlocationstags_fkey FOREIGN KEY (monitoringlocationid) REFERENCES monitoringlocations (id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE INDEX monitoringlocationstags_id_idx on monitoringlocationstags(monitoringlocationid);
CREATE UNIQUE INDEX monitoringlocationstags_id_pkg_idx on monitoringlocationstags(monitoringlocationid, tag);
--##################################################################
--# The following command adds the initial 'Default' entry to
--# the 'monitoringlocations' table.
--##################################################################
INSERT INTO monitoringlocations (id, monitoringarea) values ('Default', 'Default');
--#####################################################
--# monitoringsystems Table - Contains a list of OpenNMS systems
--# that are producing management information for this database
--#
--# This table contains the following information:
--#
--# id : The UUID of the system
--# label : Human-readable label for the system
--# location : The monitoring location associated with the system
--# type : The type of monitoring system, one of "OpenNMS",
--# "Remote Poller" or "Minion"
--# status : The status of the system
--# last_updated : The last time the system reported in
--#
--#####################################################
CREATE TABLE monitoringsystems (
id TEXT NOT NULL,
label TEXT,
location TEXT NOT NULL,
type TEXT NOT NULL,
status TEXT,
last_updated TIMESTAMP WITH TIME ZONE,
CONSTRAINT monitoringsystems_pkey PRIMARY KEY (id)
);
CREATE TABLE monitoringsystemsproperties (
monitoringsystemid TEXT NOT NULL,
property TEXT NOT NULL,
propertyvalue TEXT,
CONSTRAINT monitoringsystemsproperties_fkey FOREIGN KEY (monitoringsystemid) REFERENCES monitoringsystems (id) ON DELETE CASCADE
);
CREATE INDEX monitoringsystemsproperties_id_idx on monitoringsystemsproperties(monitoringsystemid);
CREATE UNIQUE INDEX monitoringsystemsproperties_id_property_idx on monitoringsystemsproperties(monitoringsystemid, property);
--##################################################################
--# The following command adds the initial localhost poller entry to
--# the 'monitoringsystems' table.
--##################################################################
INSERT INTO monitoringsystems (id, label, location, type) values ('00000000-0000-0000-0000-000000000000', 'localhost', 'Default', 'OpenNMS');
--#####################################################
--# scanreports Table - Contains a list of OpenNMS remote poller scan reports
--#
--# This table contains the following information:
--#
--# id : The UUID of the report
--# location : The monitoring location name
--# locale : The locale the scan was run from
--# timestamp : The start time of the scan
--#
--#####################################################
CREATE TABLE scanreports (
id TEXT NOT NULL,
location TEXT NOT NULL,
locale TEXT,
timestamp TIMESTAMP WITH TIME ZONE,
CONSTRAINT scanreports_pkey PRIMARY KEY (id),
CONSTRAINT scanreports_monitoringlocations_fkey FOREIGN KEY (location) REFERENCES monitoringlocations (id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE UNIQUE INDEX scanreports_id_idx on scanreport(id);
--#####################################################
--# scanreportproperties Table - Contains an arbitrary collection of properties associated with a scan report
--#
--# This table contains the following information:
--#
--# scanReportId : The ID of the scan report
--# property : The property name/key
--# propertyValue : The property value
--#
--#####################################################
CREATE TABLE scanreportproperties (
scanReportId TEXT NOT NULL,
property TEXT NOT NULL,
propertyValue TEXT,
CONSTRAINT scanreportproperties_fkey FOREIGN KEY (scanReportId) REFERENCES scanreports (id) ON DELETE CASCADE
);
CREATE INDEX scanreportproperties_id_idx on scanreportproperties(scanreportid);
CREATE UNIQUE INDEX scanreportproperties_id_property_idx on scanreportproperties(scanreportid, property);
--#####################################################
--# scanreportpollresults Table - Contains the set of poll results (service up/down) associated with a scan report
--#
--# This table contains the following information:
--#
--# id : The UUID of the result
--# scanReportId : The ID of the scan report
--# serviceName : The name of the monitored service
--# serviceId : The ID of the monitored service
--# nodeLabel : The node label for display
--# nodeId : The ID of the node
--# ipaddress : The IP address of the monitored service
--# statusReason : A user-displayable description of the response
--# responseTime : The response time of the poll
--# statusCode : The response code associated with the poll
--# statusTime : The timestamp of the poll
--#
--#####################################################
CREATE TABLE scanreportpollresults (
id TEXT NOT NULL,
scanReportId TEXT NOT NULL,
serviceName TEXT NOT NULL,
serviceId INTEGER NOT NULL,
nodeLabel TEXT NOT NULL,
nodeId INTEGER NOT NULL,
ipaddress TEXT,
statusReason TEXT,
responseTime DOUBLE PRECISION,
statusCode INTEGER NOT NULL,
statusTime TIMESTAMP WITH TIME ZONE,
CONSTRAINT scanreportpollresults_pkey PRIMARY KEY (id),
CONSTRAINT scanreportpollresults_fkey FOREIGN KEY (scanReportId) REFERENCES scanreports (id) ON DELETE CASCADE
);
CREATE UNIQUE INDEX scanreportpollresults_id_idx on scanreportpollresults(id);
CREATE UNIQUE INDEX scanreportpollresults_id_scanreportid_idx on scanreportpollresults(id, scanreportid);
--#####################################################
--# scanreportlogs Table - Contains poll logs associated with a scan report
--#
--# This table contains the following information:
--#
--# scanReportId : The ID of the scan report
--# logText : The contents of the scan log
--#
--#####################################################
CREATE TABLE scanreportlogs (
scanReportId TEXT NOT NULL,
logText TEXT,
CONSTRAINT scanreportlogs_pkey PRIMARY KEY (scanReportId),
CONSTRAINT scanreportlogs_fkey FOREIGN KEY (scanReportId) REFERENCES scanreports (id) ON DELETE CASCADE
);
CREATE UNIQUE INDEX scanreportlogs_scanReportId_idx on scanreportlogs(scanReportId);
--########################################################################
--# node Table - Contains information on nodes discovered and potentially
--# managed by OpenNMS. nodeSys* fields map to SNMP MIB 2
--# system table information.
--#
--# This table contains the following fields:
--#
--# nodeID : Unique identifier for node. Note that this is the
--# enabler for overlapping IP ranges and that uniquity
--# is dependent on combination of dpName & IP address
--# dpName : Distributed Poller responsible for this node
--# nodeCreateTime : Time node was added to the database
--# nodeParentID : In the case that the node is virtual or an independent
--# device in a chassis that should be reflected as a
--# subcomponent or "child", this field reflects the nodeID
--# of the chassis/physical node/"parent" device.
--# Currently unused.
--# nodeType : Flag indicating status of node
--# 'A' - active
--# 'D' - deleted
--# nodeSysOID : SNMP MIB-2 system.sysObjectID.0
--# nodeSysName : SNMP MIB-2 system.sysName.0
--# nodeSysDescription : SNMP MIB-2 system.sysDescr.0
--# nodeSysLocation : SNMP MIB-2 system.sysLocation.0
--# nodeSysContact : SNMP MIB-2 system.sysContact.0
--# nodeLabel : User-friendly name associated with the node.
--# nodeLabelSource : Flag indicating source of nodeLabel
--# 'U' = user defined
--# 'H' = IP hostname
--# 'S' = sysName
--# 'A' = IP address
--# nodeNetBIOSName : NetBIOS workstation name associated with the node.
--# nodeDomainName : NetBIOS damain name associated with the node.
--# operatingSystem : Operating system running on the node.
--# lastCapsdPoll : Date and time of last Capsd scan.
--# foreignSource : When importing nodes this contains the source of the
--# nodes, null otherwise
--# foriegnId : When importing nodes this contains the id of the node
--# as known to the foriegn source, null otherwise
--########################################################################
create table node (
nodeID integer not null,
nodeCreateTime timestamp with time zone not null,
nodeParentID integer,
nodeType char(1),
nodeSysOID varchar(256),
nodeSysName varchar(256),
nodeSysDescription varchar(256),
nodeSysLocation varchar(256),
nodeSysContact varchar(256),
nodeLabel varchar(256),
nodeLabelSource char(1),
nodeNetBIOSName varchar(16),
nodeDomainName varchar(16),
operatingSystem varchar(64),
lastCapsdPoll timestamp with time zone,
foreignSource varchar(64),
foreignId varchar(64),
location text not null,
constraint pk_nodeID primary key (nodeID),
constraint fk_node_location foreign key (location) references monitoringlocations (id) ON UPDATE CASCADE
);
create index node_id_type_idx on node(nodeID, nodeType);
create index node_label_idx on node(nodeLabel);
create unique index node_foreign_unique_idx on node(foreignSource, foreignId);
--#########################################################################
--# snmpInterface Table - Augments the ipInterface table with information
--# available from IP interfaces which also support
--# SNMP.
--#
--# This table provides the following information:
--#
--# nodeID : Unique identifier for node to which this if belongs
--# snmpPhysAddr : SNMP MIB-2 ifTable.ifEntry.ifPhysAddress
--# Value is interface's MAC Address
--# snmpIfIndex : SNMP MIB-2 ifTable.ifEntry.ifIndex
--# Value is interface's arbitrarily assigned index,
--# or -100 if we can query the agent, but we can't find
--# this IP address in the ifTable.
--# snmpIfDescr : SNMP MIB-2 ifTable.ifEntry.ifDescr
--# Value is interface's manufacturer/product name/version
--# snmpIfType : SNMP MIB-2 ifTable.ifEntry.ifType
--# Value is interface's physical/link protocol
--# snmpIfName : SNMP MIB-2 ifTable.ifEntry.ifName
--# Value is interface's device name
--# snmpIfSpeed : SNMP MIB-2 ifTable.ifEntry.ifSpeed
--# Value is estimate of interface's data rate
--# snmpIfAdminStatus : SNMP MIB-2 ifTable.ifEntry.ifAdminStatus
--# Value is interface's desired status
--# 1 = Up, 2 = Down, 3 = Testing
--# snmpIfOperStatus : SNMP MIB-2 ifTable.ifEntry.ifOperStatus
--# Value is interface's current operational status
--# 1 = Up, 2 = Down, 3 = Testing
--# snmpIfAlias : SNMP MIB-2 ifXTable.ifXEntry.ifAlias
--# Value is interface's device alias
--# snmpCollect : 'C' means collect 'N' means don't collect
--# : 'UC' means collect 'UN' means don't collect (user override)
--# This has been moved from the isSnmpPrimary field in the
--# ipinterface table
--# snmpLastCapsdPoll : Date and time of last poll by capsd or provisiond
--# snmpPoll : 'P' means polled 'N' means not polled (interface admin and oper status)
--# snmpLastSnmpPoll : Date and time of last snmp poll
--#
--# NOTE: Although not marked as "not null" the snmpIfIndex field
--# should never be null. This table is considered to be uniquely
--# keyed by nodeId and snmpIfIndex.
--########################################################################
create table snmpInterface (
id INTEGER DEFAULT nextval('opennmsNxtId') NOT NULL,
nodeID integer not null,
snmpPhysAddr varchar(32),
snmpIfIndex integer not null,
snmpIfDescr varchar(256),
snmpIfType integer,
snmpIfName varchar(96),
snmpIfSpeed bigint,
snmpIfAdminStatus integer,
snmpIfOperStatus integer,
snmpIfAlias varchar(256),
snmpLastCapsdPoll timestamp with time zone,
snmpCollect varchar(2) default 'N',
snmpPoll varchar(1) default 'N',
snmpLastSnmpPoll timestamp with time zone,
CONSTRAINT snmpinterface_pkey primary key (id),
constraint fk_nodeID2 foreign key (nodeID) references node ON DELETE CASCADE
);
create unique index snmpinterface_nodeid_ifindex_unique_idx on snmpinterface(nodeID, snmpIfIndex);
create index snmpinterface_nodeid_idx on snmpinterface(nodeID);
--########################################################################
--# ipInterface Table - Contains information on interfaces which support
--# TCP/IP as well as current status information.
--# ipAddr is integer, to support easier filtering.
--#
--# This table contains the following information:
--#
--# nodeID : Unique identifier of the node that "owns" this interface
--# ipAddr : IP Address associated with this interface
--# netmask : Netmask associated with this interface
--# ifIndex : SNMP index of interface, used to uniquely identify
--# unnumbered interfaces, or null if there is no mapping to
--# snmpInterface table. Can be -100 if old code added an
--# snmpInterface table entry but no SNMP data could be gathered.
--#
--# NOTE: The combination of nodeID, ipAddr, and ifIndex must be unique,
--# and this must be enforced programmatically.
--#
--# ipHostname : IP Hostname associated with this interface
--# isManaged : Character used as a boolean flag
--# 'M' - Managed
--# 'A' - Alias
--# 'D' - Deleted
--# 'U' - Unmanaged
--# 'F' - Forced Unmanaged (via the user interface)
--# 'N' - Not polled as part of any package
--# 'X' - Remotely Monitored only
--# ipStatus : If interface supports SNMP this field will
--# hold a numeric representation of interface's
--# operational status (same as 'snmpIfOperStatus'
--# field in the snmpInterface table).
--# 1 = Up, 2 = Down, 3 = Testing
--# ipLastCapsdPoll : Date and time of last poll by capsd or provisiond
--# isSnmpPrimary : Character used as a boolean flag
--# 'P' - Primary SNMP
--# 'S' - Secondary SNMP
--# 'N' - Not eligible (does not support SNMP or
--# or has no ifIndex)
--# NOTE: 'C' is no longer a valid value for isSnmpPrimary
--# this has moved to the snmpinterface table
--#
--########################################################################
create table ipInterface (
id INTEGER DEFAULT nextval('opennmsNxtId') NOT NULL,
nodeID integer not null,
ipAddr text not null,
netmask varchar(45),
ipHostname varchar(256),
isManaged char(1),
ipStatus integer,
ipLastCapsdPoll timestamp with time zone,
isSnmpPrimary char(1),
snmpInterfaceId integer,
CONSTRAINT ipinterface_pkey PRIMARY KEY (id),
CONSTRAINT snmpinterface_fkey2 FOREIGN KEY (snmpInterfaceId) REFERENCES snmpInterface (id) ON DELETE SET NULL,
constraint fk_nodeID1 foreign key (nodeID) references node ON DELETE CASCADE
);
create unique index ipinterface_nodeid_ipaddr_notzero_idx on ipInterface (nodeID, ipAddr) WHERE ipAddr != '0.0.0.0';
create index ipinterface_nodeid_ipaddr_ismanaged_idx on ipInterface (nodeID, ipAddr, isManaged);
create index ipinterface_ipaddr_ismanaged_idx on ipInterface (ipAddr, isManaged);
create index ipinterface_ipaddr_idx on ipInterface (ipAddr);
create index ipinterface_nodeid_ismanaged_idx on ipInterface (ipAddr);
create index ipinterface_nodeid_idx on ipInterface (nodeID);
create index ipinterface_snmpInterfaceId_idx on ipInterface (snmpInterfaceId);
--########################################################################
--# service Table - Contains a name<->number mapping for services
--# (e.g., poller packages)
--#
--# This table provides the following information:
--#
--# serviceID : Unique integer mapping to service/poller package
--# serviceName : Name associated with service/poller package
--########################################################################
create table service (
serviceID integer default nextval('serviceNxtId') not null,
serviceName varchar(255) not null,
constraint pk_serviceID primary key (serviceID)
);
create unique index service_servicename_key on service (serviceid);
--########################################################################
--# ifServices Table - Contains a mapping of interfaces to services available
--# on those interfaces (e.g., FTP, SMTP, DNS, etc.) and
--# recent polling status information.
--#
--# This table provides the following information:
--#
--# nodeID : Unique integer identifier for node
--# ipAddr : IP Address of node's interface
--# ifIndex : SNMP ifIndex, if available, null otherwise
--# serviceID : Unique integer identifier of service/poller package
--# lastGood : Date and time of last successful poll by this poller package
--# lastFail : Date and time of last failed poll by this poller package
--# qualifier : Service qualifier. May be used to distinguish two
--# services which have the same serviceID. For example, in the
--# case of the HTTP service a qualifier might be the specific
--# port on which the HTTP server was found.
--# status : Flag indicating the status of the service.
--# 'A' - Active
--# 'D' - Deleted
--# 'U' - Unmanaged (per capsd configuration change and CAPSD)
--# 'F' - Forced unmanaged (via user interface)
--# 'N' - Not polled as part of any of the packages that the
--# interface belongs to
--# 'X' - service is remotely monitored only
--# source : Flag indicating how the service was detected.
--# 'P' - Plugin
--# 'F' - Forced (via CapsdPluginBehavior.conf)
--# notify : Flag indicating if this service should be notified on or not
--# 'Y' - to notify
--# 'N' = not to notify
--########################################################################
create table ifServices (
id integer default nextval('opennmsNxtId') NOT NULL,
ifIndex integer,
serviceID integer not null,
lastGood timestamp with time zone,
lastFail timestamp with time zone,
qualifier char(16),
status char(1),
source char(1),
notify char(1),
ipInterfaceId integer not null,
CONSTRAINT ifservices_pkey PRIMARY KEY (id),
CONSTRAINT ipinterface_fkey FOREIGN KEY (ipInterfaceId) REFERENCES ipInterface (id) ON DELETE CASCADE,
constraint fk_serviceID1 foreign key (serviceID) references service ON DELETE CASCADE
);
create unique index ifservices_ipinterfaceid_svc_unique on ifservices(ipInterfaceId, serviceId);
create index ifservices_ipinterfaceid_status on ifservices(ipInterfaceId, status);
create index ifservices_serviceid_idx on ifservices(serviceID);
create index ifservicves_ipInterfaceId_idx on ifservices(ipInterfaceId);
--##################################################################
--# events Table -- This table provides information on the events
--# that are passed into the event subsystem. It
--# contains information defining the event as
--# unique, while additional information is stored
--# in the eventsDetail table.
--#
--# This table provides the following information:
--#
--# eventID : Unique identifier for the event
--# eventUei : Universal Event Identifer (UEI) for this event
--# eventSnmp : Contains the eid, eidtext (optionally), specific,
--# and generic identifier for the SNMP Trap. This
--# maps directly to the <snmp> element in the
--# Event Data Stream DTD.
--# eventTime : The <time> element from the Event Data Stream DTD,
--# which is the time the event was received by the
--# source process.
--# eventCreateTime : Creation time of event in database
--# eventHost : The <host> element from the Event Data Stream DTD
--# eventSource : The entity/process which generated the event.
--# eventSnmphost : The <snmphost> element from the Event Data Stream DTD
--# eventDpName : The dpName of the Dist Poller which received the
--# event
--# eventParms : The <parms> element from the Event Data Stream DTD
--# nodeID : Unique integer identifier for node
--# ifindex : The <ifindex> element from the Event Data Stream DTD
--# ipAddr : IP Address of node's interface
--# serviceID : Unique integer identifier of service/poller package
--# eventDescr : Free-form textual description of the event
--# eventLogmsg : The log message for the event
--# eventSeverity : Severity of event
--# 1 = Indeterminate
--# 2 = Cleared (implementation is now in alarms)
--# 3 = Normal
--# 4 = Warning
--# 5 = Minor
--# 6 = Major
--# 7 = Critical
--# eventPathOutage : Event Path outage information
--# eventCorrelation : The event correlation configured for this event
--# (stored as an XML string)
--# eventSuppressedCount : The number of times the event was suppressed
--# (if event correlation was set for suppression)
--# eventOperInstruct : Operator instruction for event.
--# eventAutoAction : Automated Action for event. Should
--# consist of fully-qualfied pathname to
--# executable command, with possible variables
--# used to reference event-specific data
--# eventOperAction : Operator Action for event. Should
--# consist of fully-qualfied pathname to
--# executable command, with possible variables
--# used to reference event-specific data
--# eventOperActionMenuText : Menu text displayed to Operator, which if
--# selected, will invoke action described in
--# eventOperAction
--# eventLoggroup : Logical group with which to associate event.
--# This field provides a means of logically
--# grouping related events.
--# eventNotification : Notification string. Should consist of
--# a fully-qualfied pathname to an executable
--# which invokes the notification software, and
--# will likely contain event-specific variables
--# eventTticket : Trouble ticket integration string. Should
--# consist of fully-qualfied pathname to
--# executable command, with possible variables
--# used to reference event-specific data
--# eventTticketState : Trouble ticket on/off boolean
--# 1=on, 0=off
--# eventForward : Contains a list of triplets:
--# Destination,State,Mechanism;Destination,State,Mechanism;
--# which reflect the following:
--# - State is a boolean flag as to whether the
--# entry is active or not. 1=on, 0=off.
--# - Destination is hostname or IP of system to
--# forward the event to
--# - Method is the means by which it will be
--# forwarded. A keyword, e.g., SNMP
--# eventMouseOverText : Text to be displayed on MouseOver event, if
--# the event is displayed in the browser and
--# the operator needs additional info.
--# eventLog : Flag indicating if the event is to be logged, set
--# from the 'dest' attribute on the incoming event
--# Y = log, N = do not log
--# eventDisplay : Flag indicating if the event is to be displayed, set
--# from the 'dest' attribute on the incoming event
--# Y = display, N = do not display
--# eventAckUser : The user who acknowledged this event. If
--# null, then this event has not been acknowledged.
--# eventAckTime : The time this event was acknowledged.
--# alarmID : If this event is configured for alarmReduction, the alarmId
--# of the reduced event will set in this column
--#
--##################################################################
create table events (
eventID integer not null,
eventUei varchar(256) not null,
nodeID integer,
eventTime timestamp with time zone not null,
eventHost varchar(256),
eventSource varchar(128) not null,
ipAddr text,
systemId TEXT not null,
eventSnmphost varchar(256),
serviceID integer,
eventSnmp varchar(256),
eventCreateTime timestamp with time zone not null,
eventDescr text,
eventLoggroup varchar(32),
eventLogmsg text,
eventSeverity integer not null,
eventPathOutage varchar(1024),
eventCorrelation varchar(1024),
eventSuppressedCount integer,
eventOperInstruct varchar(1024),
eventAutoAction varchar(256),
eventOperAction varchar(256),
eventOperActionMenuText varchar(64),
eventNotification varchar(128),
eventTticket varchar(128),
eventTticketState integer,
eventForward varchar(256),
eventMouseOverText varchar(64),
eventLog char(1) not null,
eventDisplay char(1) not null,
ifIndex integer,
eventAckUser varchar(256),
eventAckTime timestamp with time zone,
alarmID integer,
constraint pk_eventID primary key (eventID)
);
create index events_uei_idx on events(eventUei);
create index events_systemid_idx on events(systemId);
create index events_nodeid_idx on events(nodeID);
create index events_ipaddr_idx on events(ipaddr);
create index events_serviceid_idx on events(serviceID);
create index events_time_idx on events(eventTime);
create index events_severity_idx on events(eventSeverity);
create index events_log_idx on events(eventLog);
create index events_display_idx on events(eventDisplay);
create index events_ackuser_idx on events(eventAckUser);
create index events_acktime_idx on events(eventAckTime);
create index events_alarmid_idx on events(alarmID);
create index events_nodeid_display_ackuser on events(nodeid, eventdisplay, eventackuser);
create table event_parameters (
eventID integer not null,
name varchar(256) not null,
value text not null,
type varchar(256) not null,
constraint pk_eventParameters primary key (eventID, name),
constraint fk_eventParametersEventID foreign key (eventID) references events (eventID) ON DELETE CASCADE
);
--########################################################################
--#
--# outages table -- This table maintains a record of outage periods for
--# given services on specific interfaces.
--#
--# This table provides the following information:
--#
--# outageID : Unique integer identifier for the outage
--# svcLostEventID : ID of the event that caused the outage. Will be
--# a non-null value when a new outage is inserted
--# but might be null in case of an opennms upgrade
--# svcRegainedEventID: ID of the event that cleared the outage
--# ifServiceId : Unique integer identifier of service
--# ifLostService : Time of lost service event
--# ifRegainedService : Time of regained service event
--# suppressTime : Time to suppress the outage
--# suppressedBy : The suppressor
--#
--########################################################################
create table outages (
outageID integer not null,
svcLostEventID integer,
svcRegainedEventID integer,
ifLostService timestamp with time zone not null,
ifRegainedService timestamp with time zone,
suppressTime timestamp with time zone,
suppressedBy varchar(256),
ifServiceId INTEGER not null,
constraint pk_outageID primary key (outageID),
constraint fk_eventID1 foreign key (svcLostEventID) references events (eventID) ON DELETE CASCADE,
constraint fk_eventID2 foreign key (svcRegainedEventID) references events (eventID) ON DELETE CASCADE,
CONSTRAINT ifServices_fkey2 FOREIGN KEY (ifServiceId) REFERENCES ifServices (id) ON DELETE CASCADE
);
create index outages_svclostid_idx on outages(svcLostEventID);
create index outages_svcregainedid_idx on outages(svcRegainedEventID);
create index outages_regainedservice_idx on outages(ifRegainedService);
create index outages_ifServiceId_idx on outages(ifServiceId);
create unique index one_outstanding_outage_per_service_idx on outages (ifserviceid) where ifregainedservice is null;
--########################################################################
--# notification table - Contains information on acknowleged and outstanding
--# pages listed by user/groups
--#
--# This table contains the following fields:
--#
--# textMsg : The message being sent in the page.
--# numericMsg : The message being sent to a numeric pager
--# notifyID : The primary key of this row, populated with the value from
--# the notifyNxtId sequence.
--# pageTime : A timestamp of when the page was originally sent.
--# respondTime : A timestamp of when the page was acknowleged. A null in this
--# field means that the page has not been answered yet.
--# answeredBy : The user id of the user that answered the page, set the same
--# for all rows with the same groupId field.
--# nodeId : The id of the node that has the problem
--# interfaceId : The id of the interface on the node that has the problem
--# serviceID : The id of the service on the interface that has the problem
--# eventID : The primary key of the event that spawned the notification
--# eventUEI : The uei of the event that spawned the notification, placed here
--# for speed of lookup as notifications are processed.
--#
--########################################################################
create table notifications (
textMsg text not null,
subject text,
numericMsg varchar(256),
notifyID integer not null,
pageTime timestamp with time zone,
respondTime timestamp with time zone,
answeredBy varchar(256),
nodeID integer,
interfaceID varchar(16),
serviceID integer,
queueID varchar(256),
eventID integer,
eventUEI varchar(256) not null,
notifConfigName varchar(63),
constraint pk_notifyID primary key (notifyID),
constraint fk_nodeID7 foreign key (nodeID) references node (nodeID) ON DELETE CASCADE,
constraint fk_eventID3 foreign key (eventID) references events (eventID) ON DELETE CASCADE
);
create index notifications_nodeid_idx on notifications(nodeid);
create index notifications_ipaddr_idx on notifications(interfaceID);
create index notifications_serviceid_idx on notifications(serviceID);
create index notifications_eventid_idx on notifications(eventID);
create index notifications_respondtime_idx on notifications(respondTime);
create index notifications_answeredby_idx on notifications(answeredBy);
create index notifications_eventuei_idx on notifications (eventuei);
--########################################################################
--#
--# This table contains the following fields:
--# id : ID column for the table
--# userID : The user id of the person being paged, from the users.xml
--# file.
--# notifyID : The index of the row from the notification table.
--# notifyTime : The timestamp of when the notification was sent
--# media : A string describing the type of contact being made, ie text
--# page, numeric page, email, etc...
--# contactInfo : A field for storing the information used to contact the user,
--# e.g. an email address, the phone number and pin of the pager...
--# autonotify : A character to determine how auto acknowledge is handled for
--# this entry
--#
--########################################################################
create table usersNotified (
id integer not null,
userID varchar(256) not null,
notifyID integer,
notifyTime timestamp with time zone,
media varchar(32),
contactinfo varchar(64),
autonotify char(1),
constraint pk_userNotificationID primary key (id),
constraint fk_notifID2 foreign key (notifyID) references notifications (notifyID) ON DELETE CASCADE
);
create index userid_notifyid_idx on usersNotified(userID, notifyID);