2015-08-15 16:01:43 +10:00
< ? php
$row = 1 ;
2018-03-25 22:50:09 +02:00
$device_id = $vars [ 'device_id' ];
2015-08-15 16:01:43 +10:00
2016-08-21 08:07:14 -05:00
$OBJCOMP = new LibreNMS\Component ();
2015-08-15 16:01:43 +10:00
// Add a filter if supplied
2020-09-21 15:40:17 +02:00
if ( isset ( $searchPhrase ) && ! empty ( $searchPhrase )) {
$options [ 'filter' ][ 'label' ] = [ 'LIKE' , $searchPhrase ];
2015-08-15 16:01:43 +10:00
}
// Add a Sort option
2020-09-21 15:40:17 +02:00
if ( ! isset ( $sort ) || empty ( $sort )) {
2015-08-15 16:01:43 +10:00
// Nothing supplied, default is id ASC.
$options [ 'sort' ] = 'id asc' ;
2016-08-18 20:28:22 -05:00
} else {
2015-08-15 16:01:43 +10:00
$options [ 'sort' ] = $sort ;
}
// Define the Limit parameters
if ( isset ( $current )) {
2020-09-21 15:40:17 +02:00
$start = (( $current * $rowCount ) - ( $rowCount ));
2015-08-15 16:01:43 +10:00
}
if ( $rowCount != - 1 ) {
2020-09-21 15:40:17 +02:00
$options [ 'limit' ] = [ $start , $rowCount ];
2015-08-15 16:01:43 +10:00
}
2016-08-18 20:28:22 -05:00
$COMPONENTS = $OBJCOMP -> getComponents ( $device_id , $options );
2015-08-15 16:01:43 +10:00
2020-09-21 15:40:17 +02:00
$response [] = [
2015-08-15 16:01:43 +10:00
'id' => '<button type="submit" id="save-form" class="btn btn-success btn-sm" title="Save current component disable/ignore settings">Save</button><button type="submit" id="form-reset" class="btn btn-danger btn-sm" title="Reset form to when the page was loaded">Reset</button>' ,
'label' => ' ' ,
2016-03-10 17:30:32 +10:00
'status' => '<button type="submit" id="warning-select" class="btn btn-default btn-sm" title="Disable alerting on all currently warning components">Warning</button> <button type="submit" id="critical-select" class="btn btn-default btn-sm" title="Disable alerting on all currently critical components">Critical</button>' ,
2015-08-15 16:01:43 +10:00
'disable' => '<button type="submit" id="disable-toggle" class="btn btn-default btn-sm" title="Toggle polling for all components">Toggle</button><button type="button" id="disable-select" class="btn btn-default btn-sm" title="Disable polling on all components">Select All</button>' ,
2020-01-09 23:55:09 +01:00
'ignore' => '<button type="submit" id="ignore-toggle" class="btn btn-default btn-sm" title="Toggle alert tag for all components">Toggle</button><button type="button" id="ignore-select" class="btn btn-default btn-sm" title="Disable alert tag on all components">Select All</button>' ,
2020-09-21 15:40:17 +02:00
];
2015-08-15 16:01:43 +10:00
foreach ( $COMPONENTS [ $device_id ] as $ID => $AVP ) {
2016-03-10 17:30:32 +10:00
if ( $AVP [ 'status' ] == 0 ) {
2020-09-21 15:59:34 +02:00
$class = 'green' ;
$status = 'Ok' ;
2016-08-18 20:28:22 -05:00
} elseif ( $AVP [ 'status' ] == 1 ) {
2020-09-21 15:59:34 +02:00
$class = 'grey' ;
$status = 'Warning' ;
2016-08-18 20:28:22 -05:00
} else {
2016-03-10 17:30:32 +10:00
// Critical
2020-09-21 15:59:34 +02:00
$class = 'red' ;
$status = 'Critical' ;
2016-03-10 17:30:32 +10:00
}
2020-09-21 15:40:17 +02:00
$response [] = [
2015-08-15 16:01:43 +10:00
'id' => $ID ,
'type' => $AVP [ 'type' ],
'label' => $AVP [ 'label' ],
2020-09-21 15:59:34 +02:00
'status' => " <span name='status_ " . $ID . " ' class=' " . $class . " '> " . $status . '</span>' ,
2020-09-21 15:40:17 +02:00
'disable' => '<input type="checkbox" class="disable-check" name="dis_' . $ID . '"' . ( $AVP [ 'disabled' ] ? 'checked' : '' ) . '>' ,
'ignore' => '<input type="checkbox" class="ignore-check" name="ign_' . $ID . '"' . ( $AVP [ 'ignore' ] ? 'checked' : '' ) . '>' ,
];
2015-08-15 16:01:43 +10:00
} //end foreach
2020-09-21 15:40:17 +02:00
$output = [
2015-08-15 16:01:43 +10:00
'current' => $current ,
'rowCount' => $rowCount ,
'rows' => $response ,
2021-04-08 10:27:20 -05:00
'total' => ! empty ( $COMPONENTS [ $device_id ]) ? count ( $COMPONENTS [ $device_id ]) : 0 ,
2020-09-21 15:40:17 +02:00
];
2021-03-04 07:55:41 -06:00
echo json_encode ( $output , JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );