1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Mpls.php |
4
|
|
|
* |
5
|
|
|
* -Description- |
6
|
|
|
* |
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU General Public License as published by |
9
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the |
15
|
|
|
* GNU General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License |
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
19
|
|
|
* |
20
|
|
|
* @package LibreNMS |
21
|
|
|
* @link http://librenms.org |
22
|
|
|
* @copyright 2019 Vitali Kari |
23
|
|
|
* @copyright 2019 Tony Murray |
24
|
|
|
* @author Vitali Kari <[email protected]> |
25
|
|
|
* @author Tony Murray <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
namespace LibreNMS\Modules; |
29
|
|
|
|
30
|
|
|
use LibreNMS\DB\SyncsModels; |
31
|
|
|
use LibreNMS\Interfaces\Discovery\MplsDiscovery; |
32
|
|
|
use LibreNMS\Interfaces\Module; |
33
|
|
|
use LibreNMS\Interfaces\Polling\MplsPolling; |
34
|
|
|
use LibreNMS\OS; |
35
|
|
|
use LibreNMS\Util\ModuleModelObserver; |
36
|
|
|
|
37
|
|
|
class Mpls implements Module |
38
|
|
|
{ |
39
|
|
|
use SyncsModels; |
|
|
|
|
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Discover this module. Heavier processes can be run here |
43
|
|
|
* Run infrequently (default 4 times a day) |
44
|
|
|
* |
45
|
|
|
* @param OS $os |
46
|
|
|
*/ |
47
|
|
|
public function discover(OS $os) |
48
|
|
|
{ |
49
|
|
|
if ($os instanceof MplsDiscovery) { |
50
|
|
|
echo "\nMPLS LSPs: "; |
51
|
|
|
ModuleModelObserver::observe('\App\Models\MplsLsp'); |
52
|
|
|
$lsps = $this->syncModels($os->getDeviceModel(), 'mplsLsps', $os->discoverMplsLsps()); |
53
|
|
|
|
54
|
|
|
echo "\nMPLS LSP Paths: "; |
55
|
|
|
ModuleModelObserver::observe('\App\Models\MplsLspPath'); |
56
|
|
|
$this->syncModels($os->getDeviceModel(), 'mplsLspPaths', $os->discoverMplsPaths($lsps)); |
57
|
|
|
|
58
|
|
|
echo "\nMPLS SDPs: "; |
59
|
|
|
ModuleModelObserver::observe('\App\Models\MplsSdp'); |
60
|
|
|
$sdps = $this->syncModels($os->getDeviceModel(), 'mplsSdps', $os->discoverMplsSdps()); |
61
|
|
|
|
62
|
|
|
echo "\nMPLS Services: "; |
63
|
|
|
ModuleModelObserver::observe('\App\Models\MplsService'); |
64
|
|
|
$svcs = $this->syncModels($os->getDeviceModel(), 'mplsServices', $os->discoverMplsServices()); |
65
|
|
|
|
66
|
|
|
echo "\nMPLS SAPs: "; |
67
|
|
|
ModuleModelObserver::observe('\App\Models\MplsSap'); |
68
|
|
|
$this->syncModels($os->getDeviceModel(), 'mplsSaps', $os->discoverMplsSaps($svcs)); |
69
|
|
|
|
70
|
|
|
echo "\nMPLS SDP Bindings: "; |
71
|
|
|
ModuleModelObserver::observe('\App\Models\MplsSdpBind'); |
72
|
|
|
$this->syncModels($os->getDeviceModel(), 'mplsSdpBinds', $os->discoverMplsSdpBinds($sdps, $svcs)); |
73
|
|
|
|
74
|
|
|
echo PHP_EOL; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Poll data for this module and update the DB / RRD. |
80
|
|
|
* Try to keep this efficient and only run if discovery has indicated there is a reason to run. |
81
|
|
|
* Run frequently (default every 5 minutes) |
82
|
|
|
* |
83
|
|
|
* @param OS $os |
84
|
|
|
*/ |
85
|
|
|
public function poll(OS $os) |
86
|
|
|
{ |
87
|
|
|
if ($os instanceof MplsPolling) { |
88
|
|
|
$device = $os->getDeviceModel(); |
89
|
|
|
|
90
|
|
|
if ($device->mplsLsps()->exists()) { |
91
|
|
|
echo "\nMPLS LSPs: "; |
92
|
|
|
ModuleModelObserver::observe('\App\Models\MplsLsp'); |
93
|
|
|
$lsps = $this->syncModels($device, 'mplsLsps', $os->pollMplsLsps()); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
if ($device->mplsLspPaths()->exists()) { |
97
|
|
|
echo "\nMPLS LSP Paths: "; |
98
|
|
|
ModuleModelObserver::observe('\App\Models\MplsLspPath'); |
99
|
|
|
$this->syncModels($device, 'mplsLspPaths', $os->pollMplsPaths($lsps)); |
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
if ($device->mplsSdps()->exists()) { |
103
|
|
|
echo "\nMPLS SDPs: "; |
104
|
|
|
ModuleModelObserver::observe('\App\Models\MplsSdp'); |
105
|
|
|
$sdps = $this->syncModels($device, 'mplsSdps', $os->pollMplsSdps()); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
if ($device->mplsServices()->exists()) { |
109
|
|
|
echo "\nMPLS Services: "; |
110
|
|
|
ModuleModelObserver::observe('\App\Models\MplsService'); |
111
|
|
|
$svcs = $this->syncModels($device, 'mplsServices', $os->pollMplsServices()); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
if ($device->mplsSaps()->exists()) { |
115
|
|
|
echo "\nMPLS SAPs: "; |
116
|
|
|
ModuleModelObserver::observe('\App\Models\MplsSap'); |
117
|
|
|
$this->syncModels($device, 'mplsSaps', $os->pollMplsSaps($svcs)); |
|
|
|
|
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
if ($device->mplsSdpBinds()->exists()) { |
121
|
|
|
echo "\nMPLS SDP Bindings: "; |
122
|
|
|
ModuleModelObserver::observe('\App\Models\MplsSdpBind'); |
123
|
|
|
$this->syncModels($device, 'mplsSdpBinds', $os->pollMplsSdpBinds($sdps, $svcs)); |
|
|
|
|
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
echo PHP_EOL; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Remove all DB data for this module. |
132
|
|
|
* This will be run when the module is disabled. |
133
|
|
|
* |
134
|
|
|
* @param OS $os |
135
|
|
|
*/ |
136
|
|
|
public function cleanup(OS $os) |
137
|
|
|
{ |
138
|
|
|
$os->getDeviceModel()->mplsLsps()->delete(); |
139
|
|
|
$os->getDeviceModel()->mplsLspPaths()->delete(); |
140
|
|
|
$os->getDeviceModel()->mplsSdps()->delete(); |
141
|
|
|
$os->getDeviceModel()->mplsServices()->delete(); |
142
|
|
|
$os->getDeviceModel()->mplsSaps()->delete(); |
143
|
|
|
$os->getDeviceModel()->mplsSdpBinds()->delete(); |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|