mirror of
https://github.com/stylersnico/librenms.git
synced 2026-08-02 00:32:09 +02:00
Updated Device-Group SQL-Update
This commit is contained in:
@@ -25,9 +25,10 @@
|
|||||||
/**
|
/**
|
||||||
* Generate SQL from Group-Pattern
|
* Generate SQL from Group-Pattern
|
||||||
* @param string $pattern Pattern to generate SQL for
|
* @param string $pattern Pattern to generate SQL for
|
||||||
|
* @param string $search What to searchid for
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function GenGroupSQL($pattern) {
|
function GenGroupSQL($pattern,$search='') {
|
||||||
$tmp = explode(" ",$pattern);
|
$tmp = explode(" ",$pattern);
|
||||||
$tables = array();
|
$tables = array();
|
||||||
foreach( $tmp as $opt ) {
|
foreach( $tmp as $opt ) {
|
||||||
@@ -48,7 +49,10 @@ function GenGroupSQL($pattern) {
|
|||||||
}
|
}
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
$sql = "SELECT ".str_replace("(","",$tables[0]).".device_id FROM ".implode(",",$tables)." WHERE (".str_replace(array("%","@","!~","~"),array("","%","NOT LIKE","LIKE"),$pattern).")";
|
if( !empty($search) ) {
|
||||||
|
$search .= " &&";
|
||||||
|
}
|
||||||
|
$sql = "SELECT DISTINCT(".str_replace("(","",$tables[0]).".device_id) FROM ".implode(",",$tables)." WHERE ".$search." (".str_replace(array("%","@","!~","~"),array("","%","NOT LIKE","LIKE"),$pattern).")";
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,14 +85,9 @@ function GetDeviceGroups() {
|
|||||||
function GetGroupsFromDevice($device) {
|
function GetGroupsFromDevice($device) {
|
||||||
$ret = array();
|
$ret = array();
|
||||||
foreach( GetDeviceGroups() as $group ) {
|
foreach( GetDeviceGroups() as $group ) {
|
||||||
foreach( GetDevicesFromGroup($group['id']) as $dev ) {
|
if( dbFetchCell(GenGroupSQL($group['pattern'],'device_id=?').' LIMIT 1',array($device)) == $device ){
|
||||||
if( $dev['device_id'] == $device ) {
|
|
||||||
if( !in_array($group['id'],$ret) ) {
|
|
||||||
$ret[] = $group['id'];
|
$ret[] = $group['id'];
|
||||||
}
|
}
|
||||||
continue 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user