Skip to content

Commit 0868d69

Browse files
authored
Merge pull request #41 from statusengine/ITC-3481
ITC-3481 CustomalertModule: Statusengine, don't truncate whole *stat…
2 parents 1e98e3a + b4938ab commit 0868d69

File tree

5 files changed

+64
-13
lines changed

5 files changed

+64
-13
lines changed

etc/config.yml.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,3 +363,9 @@ age_perfdata: 90
363363
# Enable (1) this option to clear proxy environment variables (For Statusengine only)
364364
# Disable (0) and Statusengine will use the proxy out of your environment
365365
disable_http_proxy: 1
366+
367+
# This option is only for users of openITCOCKPIT (https://openitcockpit.io)
368+
# It enables specific performance optimizations, that can only be used with openITCOCKPIT.
369+
# Enable (1) If Statusengine is running with openITCOCKPIT
370+
# Disable (0) you are a happy user of standalone Statusengine :)
371+
is_openitcockpit: 0

src/Backends/MySQL/MySQL.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,15 @@ public function deleteNodeByName($nodeName) {
231231
}
232232

233233
public function dispatch() {
234-
/*$bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
234+
/*$bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
235235
236-
if($bt[3]['function'] === 'forkServicestatusChild'){
237-
// echo "============ START ========== \n";
238-
// foreach($bt as $line){
239-
// printf("File: %s Line: %s function: %s\n", $line['file'], $line['line'], $line['function']);
240-
// }
241-
// echo "============ END ========== \n\n";
242-
}*/
236+
if($bt[3]['function'] === 'forkServicestatusChild'){
237+
// echo "============ START ========== \n";
238+
// foreach($bt as $line){
239+
// printf("File: %s Line: %s function: %s\n", $line['file'], $line['line'], $line['function']);
240+
// }
241+
// echo "============ END ========== \n\n";
242+
}*/
243243

244244

245245
if ($this->BulkInsertObjectStore->hasRaisedTimeout()) {
@@ -672,10 +672,18 @@ public function getServiceScheduleddowntimeBackend() {
672672
public function monitoringengineWasRestarted() {
673673
$this->connect();
674674
$Hoststatus = new MysqlHoststatus($this, $this->BulkInsertObjectStore, $this->nodeName);
675-
$Hoststatus->truncate();
675+
if ($this->Config->isOpenITCOCKPIT() === true) {
676+
$Hoststatus->truncateForOpenITCOCKPIT();
677+
} else {
678+
$Hoststatus->truncate();
679+
}
676680

677681
$Servicestatus = new MysqlServicestatus($this, $this->BulkInsertObjectStore, $this->nodeName);
678-
$Servicestatus->truncate();
682+
if ($this->Config->isOpenITCOCKPIT() === true) {
683+
$Servicestatus->truncateForOpenITCOCKPIT();
684+
} else {
685+
$Servicestatus->truncate();
686+
}
679687
$this->disconnect();
680688
}
681689

src/Backends/MySQL/SqlObjects/MysqlHoststatus.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,20 @@ public function truncate($isRecursion = false){
152152
}
153153
}
154154

155+
/**
156+
* @param bool $isRecursion
157+
* @return bool
158+
*/
159+
public function truncateForOpenITCOCKPIT($isRecursion = false){
160+
$query = $this->MySQL->prepare('DELETE FROM statusengine_hoststatus WHERE NOT EXISTS (SELECT hosts.uuid FROM hosts WHERE statusengine_hoststatus.hostname = hosts.uuid AND hosts.disabled=0)');
161+
try {
162+
return $this->MySQL->executeQuery($query, 'MysqlHoststatus');
163+
} catch (StorageBackendUnavailableExceptions $Exceptions) {
164+
//Retry
165+
if ($isRecursion === false) {
166+
$this->insert(true);
167+
}
168+
}
169+
}
170+
155171
}

src/Backends/MySQL/SqlObjects/MysqlServicestatus.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class MysqlServicestatus extends MysqlModel {
6161
* @param BulkInsertObjectStore $BulkInsertObjectStore
6262
* @param string $nodeName
6363
*/
64-
public function __construct(MySQL $MySQL, BulkInsertObjectStore $BulkInsertObjectStore, $nodeName){
64+
public function __construct(MySQL $MySQL, BulkInsertObjectStore $BulkInsertObjectStore, $nodeName) {
6565
$this->MySQL = $MySQL;
6666
$this->BulkInsertObjectStore = $BulkInsertObjectStore;
6767
$this->nodeName = $nodeName;
@@ -71,7 +71,7 @@ public function __construct(MySQL $MySQL, BulkInsertObjectStore $BulkInsertObjec
7171
* @param bool $isRecursion
7272
* @return bool
7373
*/
74-
public function insert($isRecursion = false){
74+
public function insert($isRecursion = false) {
7575
/**
7676
* @var Servicestatus $Servicestatus
7777
*/
@@ -142,7 +142,7 @@ public function insert($isRecursion = false){
142142
* @param bool $isRecursion
143143
* @return bool
144144
*/
145-
public function truncate($isRecursion = false){
145+
public function truncate($isRecursion = false) {
146146
$query = $this->MySQL->prepare('DELETE FROM statusengine_servicestatus WHERE node_name=?');
147147
$query->bindValue(1, $this->nodeName);
148148
try {
@@ -155,4 +155,17 @@ public function truncate($isRecursion = false){
155155
}
156156
}
157157

158+
public function truncateForOpenITCOCKPIT($isRecursion = false) {
159+
$query = $this->MySQL->prepare('DELETE FROM statusengine_servicestatus WHERE NOT EXISTS (SELECT services.uuid FROM services WHERE statusengine_servicestatus.service_description = services.uuid AND services.disabled=0)');
160+
try {
161+
return $this->MySQL->executeQuery($query, 'MysqlServicestatus');
162+
} catch (StorageBackendUnavailableExceptions $Exceptions) {
163+
//Retry
164+
if ($isRecursion === false) {
165+
$this->insert(true);
166+
}
167+
}
168+
}
169+
170+
158171
}

src/Config.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,4 +959,12 @@ public function isDumpOfMysqlQueryParametersEnabled() {
959959
return $default;
960960
}
961961

962+
public function isOpenITCOCKPIT() {
963+
$default = false;
964+
$default = Env::get('SE_IS_OPENITCOCKPIT', $default, Env::VALUE_BOOL);
965+
if (isset($this->config['is_openitcockpit'])) {
966+
return (bool)$this->config['is_openitcockpit'];
967+
}
968+
return $default;
969+
}
962970
}

0 commit comments

Comments
 (0)