Skip to content

Commit af970a2

Browse files
author
Vítězslav Dvořák
committed
iecfgimporter now can import given directory contents
1 parent e1e5aac commit af970a2

File tree

8 files changed

+89
-73
lines changed

8 files changed

+89
-73
lines changed

bin/iecfgimporter.php

-45
This file was deleted.

debian/control

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Priority: optional
77
Homepage: http://vitexsoftware.cz/monitoring.php
88

99
Package: icinga-editor
10-
Depends: ${misc:Depends},libjs-twitter-bootstrap, ease-framework, dbconfig-common , php-mail, php5-curl, icinga-common, mtr-tiny, php-image-graphviz, libjs-d3js, php5-cli, php5-intl, composer, libjs-twitter-bootstrap-switch, nsca, traceroute
10+
Depends: ${misc:Depends},libjs-twitter-bootstrap, ease-framework, dbconfig-common , php-mail, php5-curl, icinga-common,monitoring-plugins-basic, mtr-tiny, php-image-graphviz, libjs-d3js, php5-cli, php5-intl, composer, libjs-twitter-bootstrap-switch, nsca, traceroute
1111
Recommends: mysql-server, graphicsmagick-imagemagick-compat, pnp4icinga,icinga-cgi,icinga-cgi-bin
1212
Pre-Depends: php-phinx,icinga-web,icinga-web-config-icinga
1313
Architecture: all

debian/install

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ debian/conf/icinga-editor.conf etc/apache2/conf-available
1818
debian/conf/icinga-editor.service etc/avahi/services
1919
debian/conf/icinga-editor etc/sudoers.d
2020
debian/plugins/* usr/lib/nagios/plugins
21-
bin/iecfgimporter.php usr/bin
21+
src/iecfgimporter usr/bin
2222
bin/toicmdfile.sh usr/bin
2323

2424
db/migrations/* var/lib/icinga-editor/db/migrations/

nbproject/private/config.properties

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
config=Import_iecfgimporter__etc_nagios-plugins_config_

src/classes/engine/Configurator.php

+26-21
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,7 @@ public function saveToSQL($data = null, $searchForID = false)
783783
}
784784
}
785785
if (!is_null($dbId) && ($dbId != $this->getMyKey($data) )) {
786+
$result = -1;
786787
if ($this->allowTemplating && $this->isTemplate()) {
787788
$this->addStatusMessage(sprintf(_('Template %s allready defined. Please use another name'),
788789
$data['name']), 'warning');
@@ -791,7 +792,6 @@ public function saveToSQL($data = null, $searchForID = false)
791792
$this->nameColumn, $data[$this->nameColumn]), 'warning');
792793
}
793794

794-
return null;
795795
} else {
796796
foreach ($data as $fieldName => $value) {
797797
if (!is_null($value)) {
@@ -1213,35 +1213,40 @@ public function importArray($cfgArray, $commonValues = null)
12131213
$this->dataReset();
12141214

12151215
$this->takeData($buffer);
1216-
if ($this->saveToSQL()) {
1216+
$import = $this->saveToSQL();
12171217

1218-
if ($this->isTemplate()) {
1219-
$this->addStatusMessage(_('předloha').' '.$this->keyword.' <strong>'.$buffer['name'].'</strong>'._(' byl naimportován'),
1220-
'success');
1221-
} else {
1222-
if (!is_null($this->webLinkColumn) && !isset($buffer[$this->webLinkColumn])) {
1223-
$this->updateToSQL(
1224-
[$this->getmyKeyColumn() => $this->getMyKey(),
1225-
$this->webLinkColumn =>
1226-
(str_replace(basename(\Ease\WebPage::getUri()),
1227-
'', \Ease\WebPage::phpSelf(true))).
1228-
$this->keyword.'.php?'.
1229-
$this->getmyKeyColumn().'='.
1230-
$this->getMyKey()]);
1231-
}
1232-
$this->addStatusMessage($this->keyword.' <strong>'.$buffer[$this->nameColumn].'</strong>'._(' was imported'),
1233-
'success');
1234-
}
1235-
$success++;
1236-
} else {
1218+
1219+
if (is_null($import)) {
12371220
if ($this->isTemplate()) {
12381221
$this->addStatusMessage($this->keyword.' <strong>'.$buffer['name'].'</strong>'._(' was not imported'),
12391222
'error');
12401223
} else {
12411224
$this->addStatusMessage($this->keyword.' <strong>'.$buffer[$this->nameColumn].'</strong>'._(' was not imported'),
12421225
'error');
12431226
}
1227+
} else {
1228+
if ($import != -1) {
1229+
if ($this->isTemplate()) {
1230+
$this->addStatusMessage(_('Preset').' '.$this->keyword.' <strong>'.$buffer['name'].'</strong> '._('was imported'),
1231+
'success');
1232+
} else {
1233+
if (!is_null($this->webLinkColumn) && !isset($buffer[$this->webLinkColumn])) {
1234+
$this->updateToSQL(
1235+
[$this->getmyKeyColumn() => $this->getMyKey(),
1236+
$this->webLinkColumn =>
1237+
(str_replace(basename(\Ease\WebPage::getUri()),
1238+
'', \Ease\WebPage::phpSelf(true))).
1239+
$this->keyword.'.php?'.
1240+
$this->getmyKeyColumn().'='.
1241+
$this->getMyKey()]);
1242+
}
1243+
$this->addStatusMessage($this->keyword.' <strong>'.$buffer[$this->nameColumn].'</strong>'._(' was imported'),
1244+
'success');
1245+
}
1246+
$success++;
1247+
}
12441248
}
1249+
12451250
$buffer = null;
12461251
}
12471252
}

src/classes/engine/Importer.php

+20-4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ public function dbInit()
6666
}
6767
}
6868

69+
/**
70+
* Import Configuration from path File or directory contents
71+
*
72+
* @param string $path import target
73+
* @return array import results
74+
*/
75+
function importCfgPath($path){
76+
$imported = [];
77+
if(is_dir($path)){
78+
$imported = $this->importCfg(Configurator::readRawConfigDir($path, $this));
79+
} else {
80+
$imported = $this->importCfgFile($path);
81+
}
82+
return $imported;
83+
}
84+
6985
/**
7086
* Naimportuje konfiguraci ze souboru
7187
*
@@ -100,10 +116,10 @@ public function importCfg($cfg)
100116
{
101117
$doneCount = 0;
102118
if (count($cfg)) {
103-
$this->addStatusMessage(sprintf(_('Načteno %s řádek konfigurace'),
119+
$this->addStatusMessage(sprintf(_('%s lines of configuration read'),
104120
count($cfg)), 'success');
105121
} else {
106-
$this->addStatusMessage(sprintf(_('konfigurace nebyla načtena'),
122+
$this->addStatusMessage(sprintf(_('configuration parsing failed'),
107123
count($cfg)), 'warning');
108124
return 0;
109125
}
@@ -121,10 +137,10 @@ public function importCfg($cfg)
121137
$doneCount += $IEClass->importArray($cfg, $this->getData());
122138
}
123139
if ($doneCount) {
124-
$this->addStatusMessage(sprintf(_('Bylo naimportováno %s konfigurací'),
140+
$this->addStatusMessage(sprintf(_('%s configurations imported'),
125141
$doneCount), 'success');
126142
} else {
127-
$this->addStatusMessage(_('Nic se nenaimportovalo'), 'warning');
143+
$this->addStatusMessage(_('None imported'), 'warning');
128144
}
129145

130146
return $doneCount;

src/iecfgimporter

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env php
2+
<?php
3+
//namespace Icinga\Editor;
4+
5+
/**
6+
* Configuration import form file
7+
*
8+
* @author Vitex <vitex@hippy.cz>
9+
* @copyright 2015-2017 Vitex@hippy.cz (G)
10+
*/
11+
12+
define('EASE_LOGGER', 'console|syslog');
13+
require_once 'includes/IEInit.php';
14+
15+
if (!isset($argv[1])) {
16+
die("which file to import ?");
17+
} else {
18+
if (file_exists($argv[1])) {
19+
$cfgFile = $argv[1];
20+
} else {
21+
die("file or directory $cfgFile does not exists");
22+
}
23+
}
24+
25+
$params = ['public' => true, 'generate' => true];
26+
27+
$importer = new Icinga\Editor\Engine\Importer($params);
28+
$importer->importCfgPath($cfgFile);
29+
30+
foreach ($importer->files as $cfgFile) {
31+
if ($cfgFile == '/etc/icinga/icinga.cfg') {
32+
continue;
33+
}
34+
if (is_writable($cfgFile) && rename($cfgFile, $cfgFile.'.disabled')) {
35+
$importer->addStatusMessage($cfgFile." disabled",'success');
36+
} else {
37+
$importer->addStatusMessage($cfgFile." not disabled",'warning');
38+
}
39+
}

src/wizard-active-host.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
$oPage->onlyForLogged();
1616

17-
$oPage->addItem(new UI\PageTop(_('Icinga Editor')));
17+
$oPage->addItem(new UI\PageTop(_('New Active Host')));
1818
$oPage->addPageColumns();
1919

2020
$hostName = trim($oPage->getRequestValue('host_name'));

0 commit comments

Comments
 (0)