-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.br-lifecycle.php
177 lines (167 loc) · 9.42 KB
/
module.br-lifecycle.php
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
<?php
/**
* @copyright Copyright (C) 2023 Björn Rudner
* @license https://www.gnu.org/licenses/gpl-3.0.en.html
* @version 2023-05-09
*
* iTop module definition file
*/
SetupWebPage::AddModule(
__FILE__, // Path to the current file, all other file names are relative to the directory containing this file
'br-lifecycle/0.2.0',
array(
// Identification
//
'label' => 'Datamodel: Lifecycle Management',
'category' => 'business',
// Setup
//
'dependencies' => array(
'(itop-config-mgmt/2.5.0 & itop-config-mgmt/<3.0.0)||itop-structure/3.0.0'
),
'mandatory' => false,
'visible' => true,
'installer' => 'LifeCycleManagementInstaller',
// Components
//
'datamodel' => array(),
'webservice' => array(),
'data.struct' => array(
// add your 'structure' definition XML files here,
),
'data.sample' => array(
// add your sample data XML files here,
),
// Documentation
//
'doc.manual_setup' => '', // hyperlink to manual setup documentation, if any
'doc.more_information' => '', // hyperlink to more information, if any
// Default settings
//
'settings' => array(
// Module specific settings go here, if any
),
)
);
if (!class_exists('LifeCycleManagementInstaller')) {
/**
* Module installation handler
*/
class LifeCycleManagementInstaller extends ModuleInstallerAPI
{
public static function AfterDatabaseCreation(Config $oConfiguration, $sPreviousVersion, $sCurrentVersion)
{
// Create audit rules introduced in Version 0.2.0
if (version_compare($sPreviousVersion, '0.2.0', '<')) {
SetupPage::log_info("|- Installing Life Cycle Management from '$sPreviousVersion' to '$sCurrentVersion'. The extension comes with audit rules so corresponding objects will created into the DB...");
if (MetaModel::IsValidClass('AuditRule')) {
// First, create audit category for Physical Device Lifecycle
$oSearch = DBObjectSearch::FromOQL('SELECT AuditCategory WHERE name = "Physical Device Lifecycle"');
$oSet = new DBObjectSet($oSearch);
$oAuditCategory = $oSet->Fetch();
if ($oAuditCategory === null) {
try {
$oAuditCategory = MetaModel::NewObject('AuditCategory', array(
'name' => 'Physical Device Lifecycle',
'description' => 'Lifecycle of physical device in production',
'definition_set' => "SELECT pd,m FROM PhysicalDevice AS pd JOIN Model AS m ON pd.model_id = m.id\n" .
"WHERE pd.status='production' AND pd.model_id != 0",
));
$oAuditCategory->DBWrite();
SetupPage::log_info('| |- AuditCategory "Physical Device Lifecycle" created.');
} catch (Exception $oException) {
SetupPage::log_info('| |- Could not create AuditCategory. (Error: ' . $oException->getMessage() . ')');
}
} else {
SetupPage::log_info('| |- AuditCategory "Physical Device Lifecycle" already existing! Weird as it is supposed to be created by this extension, but will use it anyway!');
}
// Then, create audit rules
$aAuditRules = array(
array(
'name' => '00 - Outdated',
'description' => 'EoL / EoSL passed',
'query' => "SELECT pd,m FROM PhysicalDevice AS pd JOIN Model AS m ON pd.model_id = m.id\n" .
"WHERE pd.status='production' AND pd.model_id != 0\n" .
"AND (m.eol < NOW() OR m.eosl < NOW())",
'valid_flag' => 'false',
),
array(
'name' => '01 - EoL outdated',
'description' => 'End of life passed',
'query' => "SELECT pd,m FROM PhysicalDevice AS pd JOIN Model AS m ON pd.model_id = m.id\n" .
"WHERE pd.status='production' AND pd.model_id != 0\n" .
"AND m.eol < NOW()",
'valid_flag' => 'false',
),
array(
'name' => '01 - EoSL outdated',
'description' => 'End of service life passed',
'query' => "SELECT pd,m FROM PhysicalDevice AS pd JOIN Model AS m ON pd.model_id = m.id\n" .
"WHERE pd.status='production' AND pd.model_id != 0\n" .
"AND m.eosl < NOW()",
'valid_flag' => 'false',
),
array(
'name' => '02 - EoL in 30 days',
'description' => 'End of life in less than 30 days',
'query' => "SELECT pd,m FROM PhysicalDevice AS pd JOIN Model AS m ON pd.model_id = m.id\n" .
"WHERE pd.status='production' AND pd.model_id != 0\n" .
"AND m.eol > NOW() AND m.eol < DATE_ADD(NOW(), INTERVAL 30 DAY)",
'valid_flag' => 'false',
),
array(
'name' => '02 - EoSL in 30 days',
'description' => 'End of service life in less than 30 days',
'query' => "SELECT pd,m FROM PhysicalDevice AS pd JOIN Model AS m ON pd.model_id = m.id\n" .
"WHERE pd.status='production' AND pd.model_id != 0\n" .
"AND m.eosl > NOW() AND m.eosl < DATE_ADD(NOW(), INTERVAL 30 DAY)",
'valid_flag' => 'false',
),
array(
'name' => '03 - EoL this year',
'description' => 'End of life this year',
'query' => "SELECT pd,m FROM PhysicalDevice AS pd JOIN Model AS m ON pd.model_id = m.id\n" .
"WHERE pd.status='production' AND pd.model_id != 0\n" .
"AND m.eol > DATE_FORMAT(NOW(),'%Y-01-01 00:00:00') AND m.eol < DATE_FORMAT(NOW(),'%Y-12-31 23:59:59')",
'valid_flag' => 'false',
),
array(
'name' => '03 - EoSL this year',
'description' => 'End of service life this year',
'query' => "SELECT pd,m FROM PhysicalDevice AS pd JOIN Model AS m ON pd.model_id = m.id\n" .
"WHERE pd.status='production' AND pd.model_id != 0\n" .
"AND m.eosl > DATE_FORMAT(NOW(),'%Y-01-01 00:00:00') AND m.eosl < DATE_FORMAT(NOW(),'%Y-12-31 23:59:59')",
'valid_flag' => 'false',
),
array(
'name' => '04 - EoL next year',
'description' => 'End of life next year',
'query' => "SELECT pd,m FROM PhysicalDevice AS pd JOIN Model AS m ON pd.model_id = m.id\n" .
"WHERE pd.status='production' AND pd.model_id != 0\n" .
"AND m.eol > DATE_FORMAT(DATE_ADD(NOW(), INTERVAL 1 YEAR),'%Y-01-01 00:00:00') AND m.eol < DATE_FORMAT(DATE_ADD(NOW(), INTERVAL 1 YEAR),'%Y-12-31 23:59:59')",
'valid_flag' => 'false',
),
array(
'name' => '04 - EoSL next year',
'description' => 'End of service life next year',
'query' => "SELECT pd,m FROM PhysicalDevice AS pd JOIN Model AS m ON pd.model_id = m.id\n" .
"WHERE pd.status='production' AND pd.model_id != 0\n" .
"AND m.eosl > DATE_FORMAT(DATE_ADD(NOW(), INTERVAL 1 YEAR),'%Y-01-01 00:00:00') AND m.eosl < DATE_FORMAT(DATE_ADD(NOW(), INTERVAL 1 YEAR),'%Y-12-31 23:59:59')",
'valid_flag' => 'false',
),
);
foreach ($aAuditRules as $aAuditRule) {
try {
$oAuditRule = MetaModel::NewObject('AuditRule', $aAuditRule);
$oAuditRule->Set('category_id', $oAuditCategory->GetKey());
$oAuditRule->DBWrite();
SetupPage::log_info('| |- AuditRule "' . $aAuditRule['name'] . '" created.');
} catch (Exception $oException) {
SetupPage::log_info('| |- Could not create AuditRule "' . $aAuditRule['name'] . '". (Error: ' . $oException->getMessage() . ')');
}
}
}
}
}
}
};