2015-08-15 16:01:43 +10:00
< ? php
$row = 1 ;
$device_id = $_POST [ 'device_id' ];
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
if ( isset ( $searchPhrase ) && ! empty ( $searchPhrase )) {
$options [ 'filter' ][ 'label' ] = array ( 'LIKE' , $searchPhrase );
}
// Add a Sort option
if ( ! isset ( $sort ) || empty ( $sort )) {
// 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 )) {
$start = (( $current * $rowCount ) - ( $rowCount ));
}
if ( $rowCount != - 1 ) {
$options [ 'limit' ] = array ( $start , $rowCount );
}
2016-08-18 20:28:22 -05:00
$COMPONENTS = $OBJCOMP -> getComponents ( $device_id , $options );
2015-08-15 16:01:43 +10:00
$response [] = array (
'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>' ,
'ignore' => '<button type="submit" id="ignore-toggle" class="btn btn-default btn-sm" title="Toggle alerting for all components">Toggle</button><button type="button" id="ignore-select" class="btn btn-default btn-sm" title="Disable alerting on all components">Select All</button>' ,
);
foreach ( $COMPONENTS [ $device_id ] as $ID => $AVP ) {
2016-03-10 17:30:32 +10:00
if ( $AVP [ 'status' ] == 0 ) {
$class = " green " ;
$status = " Ok " ;
2016-08-18 20:28:22 -05:00
} elseif ( $AVP [ 'status' ] == 1 ) {
2016-03-10 17:30:32 +10:00
$class = " grey " ;
$status = " Warning " ;
2016-08-18 20:28:22 -05:00
} else {
2016-03-10 17:30:32 +10:00
// Critical
$class = " red " ;
$status = " Critical " ;
}
2015-08-15 16:01:43 +10:00
$response [] = array (
'id' => $ID ,
'type' => $AVP [ 'type' ],
'label' => $AVP [ 'label' ],
2016-03-10 17:30:32 +10:00
'status' => " <span name='status_ " . $ID . " ' class=' " . $class . " '> " . $status . " </span> " ,
2015-08-15 16:01:43 +10: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' : '' ) . '>' ,
);
} //end foreach
$output = array (
'current' => $current ,
'rowCount' => $rowCount ,
'rows' => $response ,
'total' => count ( $COMPONENTS [ $device_id ]),
);
2016-08-18 20:28:22 -05:00
echo _json_encode ( $output );