1<?php
2
3/**
4 * Observium
5 *
6 *   This file is part of Observium.
7 *
8 * @package    observium
9 * @subpackage poller
10 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
11 *
12 */
13
14// Very basic parser to parse classic Observium-type schemes.
15// Parser should populate $port_ifAlias array with type, descr, circuit, speed and notes
16
17function custom_port_parser($port)
18{
19  global $config;
20
21  print_debug($port['ifAlias']);
22
23  // Pull out Type and Description or abort
24  if (!preg_match('/^([^:]+)[:_]([^\[\]\(\)\{\}]+)/', $port['ifAlias'], $matches))
25  {
26    return array();
27  }
28
29  // Munge and Validate type
30  $types = array('core', 'peering', 'transit', 'cust', 'server', 'l2tp', 'service');
31
32  foreach ($config['int_groups'] as $custom_type)
33  {
34    $types[] = strtolower(trim($custom_type));
35  }
36  $type  = strtolower(trim($matches[1], " \t\n\r\0\x0B\\/\"'"));
37  if (!in_array($type, $types)) { return array(); }
38
39  // Munge and Validate description
40  $descr = trim($matches[2]);
41  if ($descr == '') { return array(); }
42
43  if (preg_match('/\{(.*?)\}/', $port['ifAlias'], $matches)) { $circuit = $matches[1]; }
44  if (preg_match('/\[(.*?)\]/', $port['ifAlias'], $matches)) { $speed   = $matches[1]; }
45  if (preg_match('/\((.*?)\)/', $port['ifAlias'], $matches)) { $notes   = $matches[1]; }
46
47  $port_ifAlias = array();
48  $port_ifAlias['type']    = $type;
49  $port_ifAlias['descr']   = $descr;
50  $port_ifAlias['circuit'] = $circuit;
51  $port_ifAlias['speed']   = $speed;
52  $port_ifAlias['notes']   = $notes;
53
54  if (OBS_DEBUG > 1) { print_vars($port_ifAlias); }
55
56  return $port_ifAlias;
57}
58
59// EOF
60