@link http://blog.idleman.fr
@licence CC by nc sa
@version 1.0.0
@description Ajoute des widgets de monitoring du raspberry pi
*/
function dash_monitoring_plugin_menu(&$widgets){
$widgets[] = array(
'uid' => 'dash_monitoring_clock',
'icon' => 'fa fa-calendar-o',
'label' => 'Horloge',
'background' => '#394264',
'color' => '#fffffff',
'unique' => true,
'onLoad' => 'action.php?action=dash_monitoring_plugin_load&bloc=clock',
'onMove' => 'action.php?action=dash_monitoring_plugin_move&bloc=clock',
'onDelete' => 'action.php?action=dash_monitoring_plugin_delete&bloc=clock',
);
$widgets[] = array(
'uid' => 'dash_monitoring_ram',
'icon' => 'fa fa-bar-chart-o',
'label' => 'RAM',
'background' => '#50597B',
'color' => '#fffffff',
'onLoad' => 'action.php?action=dash_monitoring_plugin_load&bloc=ram',
'onMove' => 'action.php?action=dash_monitoring_plugin_move&bloc=ram',
'onDelete' => 'action.php?action=dash_monitoring_plugin_delete&bloc=ram',
);
$widgets[] = array(
'uid' => 'dash_monitoring_vocal',
'icon' => 'fa fa-comments-o',
'label' => 'Commandes vocales',
'background' => '#014B96',
'color' => '#fffffff',
'onLoad' => 'action.php?action=dash_monitoring_plugin_load&bloc=vocal',
'onMove' => 'action.php?action=dash_monitoring_plugin_move&bloc=vocal',
'onDelete' => 'action.php?action=dash_monitoring_plugin_delete&bloc=vocal',
);
$widgets[] = array(
'uid' => 'dash_monitoring_logs',
'icon' => 'fa fa-dedent',
'label' => 'Logs',
'background' => '#0FC7E3',
'color' => '#fffffff',
'onLoad' => 'action.php?action=dash_monitoring_plugin_load&bloc=logs'
);
$widgets[] = array(
'uid' => 'dash_monitoring_system',
'icon' => 'fa fa-tachometer',
'label' => 'Système',
'background' => '#84C400',
'color' => '#fffffff',
'onLoad' => 'action.php?action=dash_monitoring_plugin_load&bloc=system',
'onMove' => 'action.php?action=dash_monitoring_plugin_move&bloc=system',
'onDelete' => 'action.php?action=dash_monitoring_plugin_delete&bloc=system',
);
$widgets[] = array(
'uid' => 'dash_monitoring_network',
'icon' => 'fa fa-exchange',
'label' => 'Réseau',
'background' => '#006AFF',
'color' => '#fffffff',
'onLoad' => 'action.php?action=dash_monitoring_plugin_load&bloc=network',
'onMove' => 'action.php?action=dash_monitoring_plugin_move&bloc=network',
'onDelete' => 'action.php?action=dash_monitoring_plugin_delete&bloc=network',
);
$widgets[] = array(
'uid' => 'dash_monitoring_hdd',
'icon' => 'fa fa-hdd-o',
'label' => 'HDD',
'background' => '#FF2E12',
'color' => '#fffffff',
'onLoad' => 'action.php?action=dash_monitoring_plugin_load&bloc=hdd',
'onMove' => 'action.php?action=dash_monitoring_plugin_move&bloc=hdd',
'onDelete' => 'action.php?action=dash_monitoring_plugin_delete&bloc=hdd',
);
$widgets[] = array(
'uid' => 'dash_monitoring_disk',
'icon' => 'fa fa-download',
'label' => 'Disques',
'background' => '#C1004F',
'color' => '#fffffff',
'onLoad' => 'action.php?action=dash_monitoring_plugin_load&bloc=disk',
'onMove' => 'action.php?action=dash_monitoring_plugin_move&bloc=disk',
'onDelete' => 'action.php?action=dash_monitoring_plugin_delete&bloc=disk',
);
$widgets[] = array(
'uid' => 'dash_monitoring_users',
'icon' => 'fa fa-users',
'label' => 'Utilisateurs',
'background' => '#E51400',
'color' => '#fffffff',
'onLoad' => 'action.php?action=dash_monitoring_plugin_load&bloc=users',
'onMove' => 'action.php?action=dash_monitoring_plugin_move&bloc=users',
'onDelete' => 'action.php?action=dash_monitoring_plugin_delete&bloc=users',
);
$widgets[] = array(
'uid' => 'dash_monitoring_services',
'icon' => 'fa fa-users',
'label' => 'Services',
'background' => '#632F00',
'color' => '#fffffff',
'onLoad' => 'action.php?action=dash_monitoring_plugin_load&bloc=services',
'onMove' => 'action.php?action=dash_monitoring_plugin_move&bloc=services',
'onDelete' => 'action.php?action=dash_monitoring_plugin_delete&bloc=services',
);
$widgets[] = array(
'uid' => 'dash_monitoring_gpio',
'icon' => 'fa fa-dot-circle-o',
'label' => 'GPIO',
'background' => '#373737',
'color' => '#fffffff',
'onLoad' => 'action.php?action=dash_monitoring_plugin_load&bloc=gpio',
'onMove' => 'action.php?action=dash_monitoring_plugin_move&bloc=gpio',
'onDelete' => 'action.php?action=dash_monitoring_plugin_delete&bloc=gpio',
);
}
function dash_monitoring_plugin_actions(){
global $myUser,$_,$conf;
switch($_['action']){
case 'dash_monitoring_plugin_load':
if($myUser==false) exit('Vous devez vous connecter pour cette action.');
header('Content-type: application/json');
$response = array();
switch($_['bloc']){
case 'ram':
$response['title'] = 'RAM';
$hdds = Monitoring::ram();
$response['content'] = '
RAM UTILISEE
'.$hdds['percentage'].'%
RAM LIBRE
'.$hdds['free'].' Mo
RAM TOTALE
'.$hdds['total'].' Mo
';
break;
case 'clock':
$response['title'] = 'Horloge';
$response['content'] = '
';
break;
case 'system':
$response['title'] = 'Système';
if(PHP_OS!='WINNT'){
$heat = Monitoring::heat();
$cpu = Monitoring::cpu();
}
$response['content'] = '
Distribution : '.Monitoring::distribution().'
Kernel : '.Monitoring::kernel().'
HostName : '.Monitoring::hostname().'
Température : '.$heat["degrees"].'°C
Temps de marche : '.Monitoring::uptime().'
CPU : '.$cpu['current_frequency'].' Mhz (Max '.$cpu['maximum_frequency'].' Mhz/ Min '.$cpu['minimum_frequency'].' Mhz)
Charge : '.$cpu['loads'].' | '.$cpu['loads5'].' 5min | '.$cpu['loads15'].' 15min
';
break;
case 'vocal':
if($myUser->getId()=='') exit('{"error":"invalid or missing token"}');
if(!$myUser->can('vocal','r')) exit('{"error":"insufficient permissions for this account"}');
$protocol = 'http'.(isset($_SERVER['HTTPS'])?"s":"");
list($host,$port) = explode(':',$_SERVER['HTTP_HOST']);
$actionUrl = $protocol.'://'.$host.':'.$_SERVER['SERVER_PORT'].$_SERVER['REQUEST_URI'];
$actionUrl = substr($actionUrl,0,strpos($actionUrl , '?'));
Plugin::callHook("vocal_command", array(&$response,$actionUrl));
$response['title'] = count($response['commands']).' Commandes vocales';
$response['content'] = '';
if(isset($response['commands'])){
foreach($response['commands'] as $command){
$response['content'] .= ''.$command['command'].' ';
}
}
$response['content'] .= ' ';
break;
case 'logs':
if($myUser->getId()=='') exit('{"error":"invalid or missing token"}');
$response['title'] = 'Logs';
$logs = dirname(__FILE__).'/../../'.LOG_FILE ;
$response['content'] = '';
if(file_exists($logs)){
$lines = file($logs);
$nb_lines = count($lines)-1; // -1 pour ne pas avoir la ligne avec uniquement la virgule
for($i=$nb_lines; $i>0; $i--){
$response['content'] .= ''.$line.' ';
}
}else{
$response['content'] .= 'Aucun logs ';
}
$response['content'] .= ' ';
break;
case 'network':
$response['title'] = 'Réseau';
$ethernet = array();
$lan = '';
$wan = '';
$http = '';
$connections = '';
if(PHP_OS!='WINNT'){
$ethernet = Monitoring::ethernet();
$lan = Monitoring::internalIp();
$wan = Monitoring::externalIp();
$http = Monitoring::webServer();
$connections = Monitoring::connections();
}
$response['content'] = '
IP LAN : '.$lan.'
IP WAN : '.$wan.'
Serveur HTTP : '.$http.'
Ethernet : '.$ethernet['up'].' Montant / '.$ethernet['down'].' Descendant
Connexions : '.$connections.'
';
break;
case 'gpio':
$response['title'] = 'GPIO';
$gpios = array();
$gpios = Monitoring::gpio();
$model = System::getModel();
$pinLabelsRange = System::getPinForModel($model['type'],$model['version']);
$response['title'] = 'RPI Type '.$model['type'].' V'.$model['version'].' ('.count($gpios).' pins)';
$response['content'] .= '';
$response['content'] .= '';
foreach($pinLabelsRange as $range=>$pinLabels){
$response['content'] .= '';
foreach($pinLabels as $pin){
$roleColor = 'transparent';
$class = 'gpio_state_'.($gpios[$pin->wiringPiNumber]?'on':'off');
if($pin->name=='5V' || $pin->name=='3.3V') $class = 'gpio_power';
if($pin->name=='0V' || $pin->name=='DNC') $class = 'gpio_ground';
$response['content'] .= '';
$response['content'] .= ' '.$pin->name.' ('.($pin->role==''?'GPIO':$pin->role).') ';
$response['content'] .= '
';
}
$response['content'] .= '
';
}
$response['content'] .= ' ';
$response['content'] .= '
';
if($model['type']=='unknown'){
$response['title'] = 'RPI Inconnu, révision ('.$model['revision'].') ';
$response['content'] = 'Votre RPI dispose d\'une révision ('.$model['revision'].') inconnue de yana, il n\'est pas possible d\'afficher ses pins. Pour ajouter cette révision, merci de faire une demande sur github en précisant la révision, le nombre de pins, le modèle et la vesion de votre rpi.
';
}
break;
case 'users':
$users = array();
if(PHP_OS!='WINNT'){
$users = Monitoring::users();
}
$response['title'] = count($users).' utilisateurs connectés';
$response['content'] = '';
foreach ($users as $value) {
$response['content'] .= 'Utilisateur '.$value['user'].' IP : '.$value['ip'].'
, Connexion : '.$value['hour'].' ';
}
$response['content'] .= ' ';
break;
case 'services':
$response['title'] = 'Services';
$services = array();
if(PHP_OS!='WINNT'){
$services = Monitoring::services();
$response['content'] = '';
foreach ($services as $value) {
$response['content'] .= '- '.$value['name'].' ';
}
$response['content'] .= ' ';
}else{
$response['content'] .='Information indisponible sur cet OS :'.PHP_OS;
}
break;
case 'hdd':
$response['title'] = 'HDD';
$hdds = array();
if(PHP_OS!='WINNT'){
$hdds = Monitoring::hdd();
$response['content'] ='';
foreach ($hdds as $value) {
$response['content'] .=''.$value['name'].' Espace : '.$value['used'].'/'.$value['total'].' Format : '.$value['format'].' ';
}
$response['content'] .=' ';
}else{
$response['content'] .='Information indisponible sur cet OS :'.PHP_OS;
}
break;
case 'disk':
$response['title'] = 'Disques';
$disks = array();
if(PHP_OS!='WINNT'){
$disks = Monitoring::disks();
$response['content'] ='';
foreach ($disks as $value) {
$response['content'] .=''.$value['name'].' Statut : '.$value['size'].' Type : '.$value['type'].' Chemin : '.$value['mountpoint'].' ';
}
$response['content'] .=' ';
}else{
$response['content'] .='Information indisponible sur cet OS :'.PHP_OS;
}
break;
}
echo json_encode($response);
exit(0);
break;
case 'dash_monitoring_plugin_edit':
echo 'Time Zone ';
break;
case 'dash_monitoring_plugin_save':
break;
case 'dash_monitoring_plugin_delete':
break;
case 'dash_monitoring_plugin_move':
break;
}
}
Plugin::addCss('/css/style.css',true);
Plugin::addJs('/js/main.js',true);
Plugin::addHook("widgets", "dash_monitoring_plugin_menu");
Plugin::addHook("action_post_case", "dash_monitoring_plugin_actions");
?>