From 5ce9fbc388438f0d9bf7550b47347ed706a88374 Mon Sep 17 00:00:00 2001 From: f0o Date: Sat, 9 May 2015 12:33:11 +0000 Subject: [PATCH] Add port-rewrite options --- doc/Support/Configuration.md | 10 ++++++++++ includes/rewrites.php | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/doc/Support/Configuration.md b/doc/Support/Configuration.md index f96ad50f7..3d0f2807e 100644 --- a/doc/Support/Configuration.md +++ b/doc/Support/Configuration.md @@ -322,6 +322,16 @@ by continuing the array. `bad_iftype` is matched against the ifType value. `bad_if_regexp` is matched against the ifDescr value as a regular expression. +#### Interfaces to be rewritten + +```php +$config['rewrite_if']['cpu'] = 'Management Interface'; +$config['rewrite_if_regexp']['/cpu /'] = 'Management '; +``` +Entries defined in `rewrite_if` are being replaced completely. +Entries defined in `rewrite_if_regexp` only replace the match. +Matches are compared case-insensitive. + #### Storage configuration ```php diff --git a/includes/rewrites.php b/includes/rewrites.php index e4b9afe50..6a0904504 100644 --- a/includes/rewrites.php +++ b/includes/rewrites.php @@ -82,6 +82,22 @@ function ifLabel($interface, $device = NULL) list($interface['label']) = explode("thomson", $interface['label']); } + if( is_array($config['rewrite_if']) ) { + foreach( $config['rewrite_if'] as $src => $val ) { + if( stristr($interface['label'], $src) ) { + $interface['label'] = $val; + } + } + } + + if( is_array($config['rewrite_if_regexp']) ) { + foreach( $config['rewrite_if_regexp'] as $reg => $val ) { + if( preg_match($reg."i", $interface['label']) ) { + $interface['label'] = preg_replace($reg."i",$val,$interface['label']); + } + } + } + return $interface; }