@@ -20,77 +20,77 @@ discard block |
||
20 | 20 | class MibCommand extends Command |
21 | 21 | { |
22 | 22 | /** |
23 | - * Update mib database |
|
24 | - * |
|
25 | - * USAGE |
|
26 | - * |
|
27 | - * icingli trapdirector mib update |
|
28 | - * |
|
29 | - * OPTIONS |
|
30 | - * |
|
31 | - * --pid <file> : run in background with pid in <file> |
|
32 | - * |
|
33 | - * --verb : Set output log to verbose |
|
34 | - * |
|
35 | - * --force-check : force check of all traps & objects for change. (NOT IMPLEMENTED) |
|
36 | - */ |
|
23 | + * Update mib database |
|
24 | + * |
|
25 | + * USAGE |
|
26 | + * |
|
27 | + * icingli trapdirector mib update |
|
28 | + * |
|
29 | + * OPTIONS |
|
30 | + * |
|
31 | + * --pid <file> : run in background with pid in <file> |
|
32 | + * |
|
33 | + * --verb : Set output log to verbose |
|
34 | + * |
|
35 | + * --force-check : force check of all traps & objects for change. (NOT IMPLEMENTED) |
|
36 | + */ |
|
37 | 37 | public function updateAction() |
38 | 38 | { |
39 | - $background = $this->params->get('pid', null); |
|
40 | - $logLevel= $this->params->has('verb') ? 4 : 2; |
|
41 | - if ($this->params->has('force-check')) { echo "Not implemented"; return;} |
|
42 | - $forceCheck=$this->params->has('force-check')?True:False; |
|
43 | - $pid=1; |
|
44 | - if ($background != null) |
|
45 | - { |
|
46 | - $file=@fopen($background,'w'); |
|
47 | - if ($file == false) |
|
48 | - { |
|
49 | - echo 'Error : cannot open pid file '.$background; |
|
50 | - return 1; |
|
51 | - } |
|
52 | - $pid = pcntl_fork(); |
|
53 | - if ($pid == -1) { |
|
54 | - echo 'Error : Cannot fork process'; |
|
55 | - return 1; |
|
56 | - } |
|
57 | - } |
|
58 | - $module=Icinga::app()->getModuleManager()->getModule($this->getModuleName()); |
|
39 | + $background = $this->params->get('pid', null); |
|
40 | + $logLevel= $this->params->has('verb') ? 4 : 2; |
|
41 | + if ($this->params->has('force-check')) { echo "Not implemented"; return;} |
|
42 | + $forceCheck=$this->params->has('force-check')?True:False; |
|
43 | + $pid=1; |
|
44 | + if ($background != null) |
|
45 | + { |
|
46 | + $file=@fopen($background,'w'); |
|
47 | + if ($file == false) |
|
48 | + { |
|
49 | + echo 'Error : cannot open pid file '.$background; |
|
50 | + return 1; |
|
51 | + } |
|
52 | + $pid = pcntl_fork(); |
|
53 | + if ($pid == -1) { |
|
54 | + echo 'Error : Cannot fork process'; |
|
55 | + return 1; |
|
56 | + } |
|
57 | + } |
|
58 | + $module=Icinga::app()->getModuleManager()->getModule($this->getModuleName()); |
|
59 | 59 | require_once($module->getBaseDir() .'/bin/trap_class.php'); |
60 | 60 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
61 | 61 | $trap = new Trap($icingaweb2_etc); |
62 | 62 | if ($pid == 1) |
63 | 63 | { |
64 | - $trap->setLogging($logLevel,'display'); |
|
64 | + $trap->setLogging($logLevel,'display'); |
|
65 | 65 | } |
66 | 66 | else |
67 | 67 | { // use default display TODO : if default is 'display' son process will be killed at first output.... |
68 | - if ($pid != 0) |
|
69 | - { |
|
70 | - // father process |
|
71 | - fwrite($file,$pid); |
|
72 | - fclose($file); |
|
73 | - echo "OK : process $pid in bckground"; |
|
74 | - return 0; |
|
75 | - } |
|
76 | - else |
|
77 | - { // son process : close all file descriptors and go to a new session |
|
78 | - fclose($file); |
|
68 | + if ($pid != 0) |
|
69 | + { |
|
70 | + // father process |
|
71 | + fwrite($file,$pid); |
|
72 | + fclose($file); |
|
73 | + echo "OK : process $pid in bckground"; |
|
74 | + return 0; |
|
75 | + } |
|
76 | + else |
|
77 | + { // son process : close all file descriptors and go to a new session |
|
78 | + fclose($file); |
|
79 | 79 | // $sid = posix_setsid(); |
80 | - fclose(STDIN); |
|
81 | - fclose(STDOUT); |
|
82 | - fclose(STDERR); |
|
83 | - try |
|
84 | - { |
|
85 | - $trap->update_mib_database(false,$forceCheck); |
|
86 | - } |
|
87 | - catch (Exception $e) |
|
88 | - { |
|
89 | - $trap->trapLog('Error in updating : ' . $e->getMessage(),2); |
|
90 | - } |
|
91 | - unlink($background); |
|
92 | - return 0; |
|
93 | - } |
|
80 | + fclose(STDIN); |
|
81 | + fclose(STDOUT); |
|
82 | + fclose(STDERR); |
|
83 | + try |
|
84 | + { |
|
85 | + $trap->update_mib_database(false,$forceCheck); |
|
86 | + } |
|
87 | + catch (Exception $e) |
|
88 | + { |
|
89 | + $trap->trapLog('Error in updating : ' . $e->getMessage(),2); |
|
90 | + } |
|
91 | + unlink($background); |
|
92 | + return 0; |
|
93 | + } |
|
94 | 94 | |
95 | 95 | } |
96 | 96 | |
@@ -108,20 +108,20 @@ discard block |
||
108 | 108 | } |
109 | 109 | if ($pid != 1) |
110 | 110 | { |
111 | - unlink($background); |
|
111 | + unlink($background); |
|
112 | 112 | } |
113 | 113 | } |
114 | 114 | /** |
115 | - * purge all mib database NOT IMPLEMENTED |
|
116 | - * |
|
117 | - * USAGE |
|
118 | - * |
|
119 | - * icingli trapdirector mib purge --confirm yes |
|
120 | - * |
|
121 | - * OPTIONS |
|
122 | - * |
|
123 | - * --confirm yes : needed to execute purge |
|
124 | - */ |
|
115 | + * purge all mib database NOT IMPLEMENTED |
|
116 | + * |
|
117 | + * USAGE |
|
118 | + * |
|
119 | + * icingli trapdirector mib purge --confirm yes |
|
120 | + * |
|
121 | + * OPTIONS |
|
122 | + * |
|
123 | + * --confirm yes : needed to execute purge |
|
124 | + */ |
|
125 | 125 | public function purgeAction() |
126 | 126 | { |
127 | 127 | $db_prefix=$this->Config()->get('config', 'database_prefix'); |