|
|
Línea 1: |
Línea 1: |
| <source lang=php> | | <source lang=php> |
− | public static function create_matrices_last( $datas, $list_services, $hour ) { | + | /** |
− | echo "<h2>MRM ---DEBUGANDO ...en create_matrices_fast </h2>";
| + | * @covers Monitorizacion_Controller::service_host_to_string |
− | //Inicializo el primer nivel del array
| + | * @group production |
− | $matrix[ 'host' ] = array_values( $datas )[ 0 ]->host_id;
| + | * @runInSeparateProcess |
− | $matrix[ 'date' ] = []; //Será un array indexado de las diferentes fechas
| + | */ |
− | $matrix[ 'services' ] = []; //Array asociativo con cada servicio cada uno tendrá un arrau con los índices
| + | public function testService_host_to_string() { |
− | // //Ahora recorremos para cada documento (host - día)
| + | // Comparacion de fechas |
− | //primero inicializamos las fechas
| + | $array = array( |
− | $min = "00"; | + | Monitorizacion_Constants::SERVICIO_SSH => 'SSH', |
− | | + | Monitorizacion_Constants::SERVICIO_HTTP => 'HTTP', |
− | //Nos quedamos con los dos array si los ubiera si no data2 tendrá un false
| + | Monitorizacion_Constants::SERVICIO_MYSQL => 'MYSQL', |
− | reset( $datas );
| + | Monitorizacion_Constants::SERVICIO_DISCOS => 'DISK', |
− | Logs_Controller::vardump( $hour );
| + | Monitorizacion_Constants::SERVICIO_CPU => 'CPU', |
− | $data1 = current( $datas );
| + | Monitorizacion_Constants::SERVICIO_PING => 'PING', |
− | $data2 = next( $datas );
| + | -1 => null |
− | Logs_Controller::vardump( $data1 );
| + | ); |
− | Logs_Controller::vardump( $data2 );
| + | foreach ( $array as $servicio => $value_expected ) { |
− | | + | $this->assertEquals( $value_expected, Monitorizacion_Controller::service_host_to_string( $servicio ), "ERROR: $value_expected != " . Monitorizacion_Controller::service_host_to_string( $servicio ) ); |
− | $fecha = substr( $data1->timestamp, 0, 10 ) . " $hour:00:00";
| + | } |
− | $dateMAX = date( 'Y-m-d H:i:00', strtotime( $fecha . " -3 hour" ) );
| + | |
− | $fecha = date( 'Y-m-d H:i:00', strtotime( $fecha . " -2 minute" ) );
| + | |
− | $matrix[ 'date' ] = Charts_Controller::get_array_datetime_range( $dateMAX, $fecha, 60, 'H:i:00' );
| + | |
− | | + | |
− | | + | |
− | | + | |
− | foreach ( $list_services as $service ) {
| + | |
− | $matrix[ 'services' ][ $service ] = []; | + | |
− | $indexes_service = array_keys( $data1->data[ $service ] ); | + | |
− | | + | |
− | | + | |
− | //Para cada índice de ese servicio
| + | |
− | $datas_of_mongo = [];
| + | |
− | foreach ( $indexes_service as $index_service ) {
| + | |
− | //Si hora =1 o 2 necesito datos de los dos días para generar la matriz
| + | |
− | //Si no lo cogeré de cada día
| + | |
− | | + | |
− | switch ( $hour ) {
| + | |
− | | + | |
− | case 0:
| + | |
− | $h = 21;
| + | |
− | //Primer array de documentos
| + | |
− | $datas_of_mongo = $data1->data[ $service ][ $index_service ][ $h ];
| + | |
− | $datas_of_mongo = array_merge( $datas_of_mongo, $data1->data[ $service ][ $index_service ][ ++$h ] );
| + | |
− | $datas_of_mongo = array_merge( $datas_of_mongo, $data1->data[ $service ][ $index_service ][ ++$h ] );
| + | |
− | break;
| + | |
− | case 1:
| + | |
− | $h = 22;
| + | |
− | //Primer array de documentos
| + | |
− | $datas_of_mongo = $data1->data[ $service ][ $index_service ][ $h ];
| + | |
− | $datas_of_mongo = array_merge( $datas_of_mongo, $data1->data[ $service ][ $index_service ][ $h + 1 ] );
| + | |
− | $datas_of_mongo = array_merge( $datas_of_mongo, $data2->data[ $service ][ $index_service ][ 0 ] );
| + | |
− | break;
| + | |
− | | + | |
− | case 2:
| + | |
− | $h = 23;
| + | |
− | //Primer array de documentos
| + | |
− | $datas_of_mongo = $data1->data[ $service ][ $index_service ][ $h ];
| + | |
− | $datas_of_mongo = array_merge( $datas_of_mongo, $data2->data[ $service ][ $index_service ][ 0 ] );
| + | |
− | $datas_of_mongo = array_merge( $datas_of_mongo, $data2->data[ $service ][ $index_service ][ 1 ] );
| + | |
− | break;
| + | |
− | default:
| + | |
− | Logs_Controller::vardump( $index_service );
| + | |
− | | + | |
− | //Primer array de documentos
| + | |
− | $h = $hour - 2;
| + | |
− | $datas_of_mongo = $data1->data[ $service ][ $index_service ][ $h ];
| + | |
− | $datas_of_mongo = array_merge( $datas_of_mongo, $data1->data[ $service ][ $index_service ][ ++$h ] );
| + | |
− | $datas_of_mongo = array_merge( $datas_of_mongo, $data1->data[ $service ][ $index_service ][ ++$h ] );
| + | |
− | }
| + | |
− | $matrix[ 'services' ][ $service ][ $index_service ] = $datas_of_mongo;
| + | |
− | }//End while index (indices de los servicios
| + | |
− | // echo "FECHA - VALOR SERVICIO<br/>";
| + | |
− | }//End foreach $services
| + | |
− | //ver matriz
| + | |
− | Logs_Controller::vardump( $matrix );
| + | |
− | | + | |
− | return ($matrix); | + | |
| | | |
| } | | } |
| + | } |
| </source> | | </source> |
/**
* @covers Monitorizacion_Controller::service_host_to_string
* @group production
* @runInSeparateProcess
*/
public function testService_host_to_string() {
// Comparacion de fechas
$array = array(
Monitorizacion_Constants::SERVICIO_SSH => 'SSH',
Monitorizacion_Constants::SERVICIO_HTTP => 'HTTP',
Monitorizacion_Constants::SERVICIO_MYSQL => 'MYSQL',
Monitorizacion_Constants::SERVICIO_DISCOS => 'DISK',
Monitorizacion_Constants::SERVICIO_CPU => 'CPU',
Monitorizacion_Constants::SERVICIO_PING => 'PING',
-1 => null
);
foreach ( $array as $servicio => $value_expected ) {
$this->assertEquals( $value_expected, Monitorizacion_Controller::service_host_to_string( $servicio ), "ERROR: $value_expected != " . Monitorizacion_Controller::service_host_to_string( $servicio ) );
}
}
}