-
Notifications
You must be signed in to change notification settings - Fork 12
/
exec.php
134 lines (118 loc) · 4.72 KB
/
exec.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
<?php
// Copyright (C) 2014 Combodo SARL
//
// This application 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.
//
// iTop 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 this application. If not, see <http://www.gnu.org/licenses/>
/**
* Main entry point for the collector application
*/
define('APPROOT', dirname(__FILE__).'/');
require_once(APPROOT.'core/parameters.class.inc.php');
require_once(APPROOT.'core/ioexception.class.inc.php');
require_once(APPROOT.'core/utils.class.inc.php');
require_once(APPROOT.'core/restclient.class.inc.php');
require_once(APPROOT.'core/lookuptable.class.inc.php');
require_once(APPROOT.'core/mappingtable.class.inc.php');
require_once(APPROOT.'core/collectionplan.class.inc.php');
require_once(APPROOT.'core/collector.class.inc.php');
require_once(APPROOT.'core/orchestrator.class.inc.php');
require_once(APPROOT.'core/sqlcollector.class.inc.php'); // Depends on Orchestrator for settings a minimum version for PHP because of the use of PDO
require_once(APPROOT.'core/csvcollector.class.inc.php');
require_once(APPROOT.'core/jsoncollector.class.inc.php');
require_once(APPROOT.'core/polyfill.inc.php');
$aOptionalParams = array(
'configure_only' => 'boolean',
'collect_only' => 'boolean',
'synchro_only' => 'boolean',
'dump_config_only' => 'boolean',
'console_log_level' => 'integer',
'eventissue_log_level' => 'integer',
'max_chunk_size' => 'integer',
'help' => 'boolean',
'config_file' => 'string',
);
$bHelp = (Utils::ReadBooleanParameter('help', false) == true);
$aUnknownParameters = Utils::CheckParameters($aOptionalParams);
if ($bHelp || count($aUnknownParameters) > 0) {
if (!$bHelp) {
Utils::Log(LOG_ERR, "Unknown parameter(s): ".implode(' ', $aUnknownParameters));
}
echo "Usage:\n";
echo 'php '.basename($argv[0]);
foreach ($aOptionalParams as $sParam => $sType) {
switch ($sType) {
case 'boolean':
echo '[--'.$sParam.']';
break;
default:
echo '[--'.$sParam.'=xxx]';
break;
}
}
echo "\n";
exit(1);
}
$bResult = true;
// Note: The parameter 'config_file' is read directly by Utils::LoadConfig()
$bConfigureOnly = (Utils::ReadBooleanParameter('configure_only', false) == true);
$bCollectOnly = (Utils::ReadBooleanParameter('collect_only', false) == true);
$bSynchroOnly = (Utils::ReadBooleanParameter('synchro_only', false) == true);
$bDumpConfigOnly = (Utils::ReadBooleanParameter('dump_config_only', false) == true);
try {
Utils::InitConsoleLogLevel();
Utils::$iEventIssueLogLevel = Utils::ReadParameter('eventissue_log_level', Utils::GetConfigurationValue('eventissue_log_level', LOG_NONE));//On windows LOG_NOTICE=LOG_INFO=LOG_DEBUG=6
$iMaxChunkSize = Utils::ReadParameter('max_chunk_size', Utils::GetConfigurationValue('max_chunk_size', 1000));
if (file_exists(APPROOT.'collectors/main.php')) {
require_once(APPROOT.'collectors/main.php');
} else {
Utils::Log(LOG_ERR, "The file '".APPROOT."collectors/main.php' is missing (or unreadable).");
}
if (!Orchestrator::CheckRequirements()) {
exit(1);
}
$aConfig = Utils::GetConfigFiles();
$sConfigDebug = "The following configuration files were loaded (in this order):\n\n";
$idx = 1;
foreach ($aConfig as $sFile) {
$sConfigDebug .= "\t{$idx}. $sFile\n";
$idx++;
}
$sConfigDebug .= "\nThe resulting configuration is:\n\n";
$sConfigDebug .= Utils::DumpConfig();
if ($bDumpConfigOnly) {
echo $sConfigDebug;
exit(0);
} else {
Utils::Log(LOG_DEBUG, $sConfigDebug);
}
$oOrchestrator = new Orchestrator();
$aCollectors = $oOrchestrator->ListCollectors();
Utils::Log(LOG_DEBUG, "Registered collectors:");
foreach ($aCollectors as $oCollector) {
Utils::Log(LOG_DEBUG, "Collector: ".$oCollector->GetName().", version: ".$oCollector->GetVersion());
}
if (!$bCollectOnly) {
Utils::Log(LOG_DEBUG, 'iTop web services version: '.RestClient::GetNewestKnownVersion());
$bResult = $oOrchestrator->InitSynchroDataSources($aCollectors);
}
if ($bResult && !$bSynchroOnly && !$bConfigureOnly) {
$bResult = $oOrchestrator->Collect($aCollectors, $iMaxChunkSize, $bCollectOnly);
}
if ($bResult && !$bConfigureOnly && !$bCollectOnly) {
$bResult = $oOrchestrator->Synchronize($aCollectors);
}
} catch (Exception $e) {
$bResult = false;
Utils::Log(LOG_ERR, "Exception: ".$e->getMessage());
}
exit ($bResult ? 0 : 1); // exit code is zero means success