mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-25 00:32:16 +02:00
Fix coding style part 2
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
|
||||
if(is_admin() === false) {
|
||||
if (is_admin() === false) {
|
||||
die('ERROR: You need to be admin');
|
||||
}
|
||||
|
||||
@@ -21,46 +21,56 @@ $target = mres($_POST['target']);
|
||||
$map_id = mres($_POST['map_id']);
|
||||
$ret = array();
|
||||
|
||||
if( empty($rule) || empty($target) ) {
|
||||
$ret[] = "ERROR: No map was generated";
|
||||
} else {
|
||||
$raw = $rule;
|
||||
$rule = dbFetchCell('SELECT id FROM alert_rules WHERE name = ?',array($rule));
|
||||
if( !is_numeric($rule) ) {
|
||||
array_unshift($ret, "ERROR: Could not find rule for '".$raw."'");
|
||||
} else {
|
||||
$raw = $target;
|
||||
if( $target[0].$target[1] == "g:" ) {
|
||||
$target = "g".dbFetchCell('SELECT id FROM device_groups WHERE name = ?',array(substr($target,2)));
|
||||
} else {
|
||||
$target = dbFetchCell('SELECT device_id FROM devices WHERE hostname = ?',array($target));
|
||||
}
|
||||
if( !is_numeric(str_replace('g','',$target)) ) {
|
||||
array_unshift($ret, "ERROR: Could not find entry for '".$raw."'");
|
||||
} else {
|
||||
if(is_numeric($map_id) && $map_id > 0) {
|
||||
if(dbUpdate(array('rule' => $rule,'target'=>$target), 'alert_map', 'id=?',array($map_id)) >= 0) {
|
||||
$ret[] = "Edited Map: <i>".$map_id.": ".$rule." = ".$target."</i>";
|
||||
} else {
|
||||
array_unshift($ret,"ERROR: Failed to edit Map: <i>".$map_id.": ".$rule." = ".$target."</i>");
|
||||
}
|
||||
} else {
|
||||
if( dbInsert(array('rule'=>$rule,'target'=>$target),'alert_map') ) {
|
||||
$ret[] = "Added Map: <i>".$rule." = ".$target."</i>";
|
||||
} else {
|
||||
array_unshift($ret,"ERROR: Failed to add Map: <i>".$rule." = ".$target."</i>");
|
||||
}
|
||||
}
|
||||
if( ($tmp=dbFetchCell('SELECT device_id FROM alert_rules WHERE id = ?',array($rule))) && $tmp[0] != ":" ) {
|
||||
if(dbUpdate(array('device_id' => ':'.$tmp), 'alert_rules', 'id=?',array($rule)) >= 0) {
|
||||
$ret[] = "Edited Rule: <i>".$rule." device_id = ':".$tmp."'</i>";
|
||||
} else {
|
||||
array_unshift($ret,"ERROR: Failed to edit Rule: <i>".$rule.": device_id = ':".$tmp."'</i>");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (empty($rule) || empty($target)) {
|
||||
$ret[] = 'ERROR: No map was generated';
|
||||
}
|
||||
foreach( $ret as $msg ) {
|
||||
echo $msg."<br/>";
|
||||
else {
|
||||
$raw = $rule;
|
||||
$rule = dbFetchCell('SELECT id FROM alert_rules WHERE name = ?', array($rule));
|
||||
if (!is_numeric($rule)) {
|
||||
array_unshift($ret, "ERROR: Could not find rule for '".$raw."'");
|
||||
}
|
||||
else {
|
||||
$raw = $target;
|
||||
if ($target[0].$target[1] == 'g:') {
|
||||
$target = 'g'.dbFetchCell('SELECT id FROM device_groups WHERE name = ?', array(substr($target, 2)));
|
||||
}
|
||||
else {
|
||||
$target = dbFetchCell('SELECT device_id FROM devices WHERE hostname = ?', array($target));
|
||||
}
|
||||
|
||||
if (!is_numeric(str_replace('g', '', $target))) {
|
||||
array_unshift($ret, "ERROR: Could not find entry for '".$raw."'");
|
||||
}
|
||||
else {
|
||||
if (is_numeric($map_id) && $map_id > 0) {
|
||||
if (dbUpdate(array('rule' => $rule, 'target' => $target), 'alert_map', 'id=?', array($map_id)) >= 0) {
|
||||
$ret[] = 'Edited Map: <i>'.$map_id.': '.$rule.' = '.$target.'</i>';
|
||||
}
|
||||
else {
|
||||
array_unshift($ret, 'ERROR: Failed to edit Map: <i>'.$map_id.': '.$rule.' = '.$target.'</i>');
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (dbInsert(array('rule' => $rule, 'target' => $target), 'alert_map')) {
|
||||
$ret[] = 'Added Map: <i>'.$rule.' = '.$target.'</i>';
|
||||
}
|
||||
else {
|
||||
array_unshift($ret, 'ERROR: Failed to add Map: <i>'.$rule.' = '.$target.'</i>');
|
||||
}
|
||||
}
|
||||
|
||||
if (($tmp = dbFetchCell('SELECT device_id FROM alert_rules WHERE id = ?', array($rule))) && $tmp[0] != ':') {
|
||||
if (dbUpdate(array('device_id' => ':'.$tmp), 'alert_rules', 'id=?', array($rule)) >= 0) {
|
||||
$ret[] = 'Edited Rule: <i>'.$rule." device_id = ':".$tmp."'</i>";
|
||||
}
|
||||
else {
|
||||
array_unshift($ret, 'ERROR: Failed to edit Rule: <i>'.$rule.": device_id = ':".$tmp."'</i>");
|
||||
}
|
||||
}
|
||||
}//end if
|
||||
}//end if
|
||||
}//end if
|
||||
foreach ($ret as $msg) {
|
||||
echo $msg.'<br/>';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user