Aller au contenu

Arreter Ou Rebooter Votre Synology Avec La Hc2


fdp2

Messages recommandés

Bonjour,

 

J'ai le même problème. Impossible de faire un "redémarrer" ou un "arrêter" avec ce VD.

Il semble bloquer à la ligne suivante :

payload = "/webman/reboot.cgi?opt=shutdown&session=DSM&_sid="..SID;
response, status, errorCode = Synology:GET(payload)

La variable "status" retourne le code erreur 500 (Internal Error).

 

Je n'arrive pas à trouver l'info pour avoir la bonne URL.

 

Si jamais vous y arrivez, je serai très heureux d'avoir la solution.

 

Merci !

 

Lien vers le commentaire
Partager sur d’autres sites

  • 5 mois après...

Bonjour,

 

Voici une version qui affiche en plus la charge CPU en %, la mémoire occupée en %, la température du système et la température de chaque disques quand on appuie sur le bouton "Etat" ou quand il se met à jour tout seul.

 

Voilà ... :P

 

NAS_Synology.vfib

Modifié par Kana-chan
  • Upvote 3
Lien vers le commentaire
Partager sur d’autres sites

Merci pour ces modifications. N'ayant plus de HC2, cela m'intéresse d'avoir juste le code (pour avoir l'api utilisée) et ainsi l'adapter pour ma LD.
Merci

Envoyé de mon Nexus 5 en utilisant Tapatalk

  • Upvote 2
Lien vers le commentaire
Partager sur d’autres sites

Bonjour jojo,

 

Impossible de vous envoyer un message, mais je me suis dit que cela serait pas trop grave de mettre le code ici.

Je rappelle que je n'ai pas la paternité du VD, il fut d'abord créé par fdp2.

 

Voici le code pour les différents boutons du VD NAS Synology :

Redémarrer :

--------------------------------------------------
-- Synology DSM
-- Reboot the disk station
-- janvier 2015
--------------------------------------------------

-- User configurable variables
local login = "aa";
local password = "bb";

-- System variables
local selfID = fibaro:getSelfId();
local ip = fibaro:get(selfID, 'IPAddress');
local port = fibaro:get(selfID, 'TCPPort');
local Synology = Net.FHttp(ip, tonumber(port));
local API_AUTH_ERROR_CODE = {
    [0]   = "Sans erreur.",
	[100] = "Erreur inconnue.",
	[101] = "Compte non spécifié.",
	[400] = "Mot de passe invalide.",
	[401] = "Compte désactivé.",
	[402] = "Permission refusée.",
	[403] = "Unique mot de passe non spécifié.",
	[404] = "Autentification erronée."
};
local API_RECORD_ERROR_CODE = {
	[400] = "Exécution ratée.",
};

-- Discover available APIs and corresponding information
payload = "/webapi/query.cgi?api=SYNO.API.Info&method=Query&version=1&query=SYNO.API.Auth";
response, status, errorCode = Synology:GET(payload);
if tonumber(status) == 200 then
	jsonTable = json.decode(response);
  	local version = jsonTable.data["SYNO.API.Auth"].maxVersion;
	if version >= 2 then
		fibaro:debug("Version API Synology OK");
		pathAuth = jsonTable.data["SYNO.API.Auth"].path;
		fibaro:debug("Chemin API Synology = "..pathAuth);
        cgiUsed="/entry.cgi";
        apiUsed="SYNO.Core.System";
        if version < 6 then
            cgiUsed="/dsm/system.cgi";
            apiUsed="SYNO.DSM.System";
        end

		-- Create new login session
		payload = "/webapi/"..pathAuth.."?api=SYNO.API.Auth&method=Login&version=2&account="..login.."&passwd="..password.."&session=DSM&format=sid";
		response, status, errorCode = Synology:GET(payload);
		if tonumber(status) == 200 then
			jsonTable = json.decode(response);
			if jsonTable.success == true then
				SID = jsonTable.data.sid;
				fibaro:debug("SID API Synology = ["..SID.."]");

				-- Reboot the disk station
				payload = "/webapi"..cgiUsed.."?api="..apiUsed.."&version=1&method=reboot&_sid="..SID;
				response, status, errorCode = Synology:GET(payload);
        		if tonumber(status) == 200 then
        			fibaro:debug("Response ["..response.."]");
					jsonTable = json.decode(response);
					if jsonTable.success == true then
						fibaro:log("Redémarrage OK");
						fibaro:debug('<span style="color:green;">Redémarrage Disk Station Synology OK</span>');
					else
						fibaro:log("Erreur");
						fibaro:debug('<span style="color:red;">Disk Station Synology n\'a pas redémarré</span>');
					end
					--
				else
					fibaro:log("Erreur");
					fibaro:debug('<span style="color:red;">Erreur : '..API_AUTH_ERROR_CODE[tonumber(errorCode)]..'</span>');
          			--fibaro:debug('<span style="color:red;">Erreur : '..errorCode..'</span>');
        		end
				-- Destroy current login session
				payload = "/webapi/"..pathAuth.."?api=SYNO.API.Auth&method=Logout&version=2&session=DSM&_sid="..SID;
				response, status, errorCode = Synology:GET(payload);
                fibaro:debug(status);
			else
				fibaro:log("Erreur");
				fibaro:debug('<span style="color:red;">Erreur : '..API_AUTH_ERROR_CODE[tonumber(jsonTable.error.code)]..'</span>');
			end
		else
			fibaro:log("Erreur");
			fibaro:debug('<span style="color:red;">Erreur : Authentification API ratée</span>');
		end
	else
		fibaro:log("Erreur");
		fibaro:debug('<span style="color:red;">Erreur : Version API Synology trop vieille : <b>DSM 4.0-2251</b> est requise</span>');
	end
else
	fibaro:log("Erreur");
	fibaro:debug('<span style="color:red;">Erreur : Impossible de se connecter au Disk Station Synology</span>');
end

 

Arrêter :

--------------------------------------------------
-- Synology DSM
-- Shutdown the disk station
-- janvier 2015
--------------------------------------------------

-- User configurable variables
local login = "aa";
local password = "bb";

-- System variables
local selfID = fibaro:getSelfId();
local ip = fibaro:get(selfID, 'IPAddress');
local port = fibaro:get(selfID, 'TCPPort');
local Synology = Net.FHttp(ip, tonumber(port));
local API_AUTH_ERROR_CODE = {
	[100] = "Erreur inconnue.",
	[101] = "Compte non spécifié.",
	[400] = "Mot de passe invalide.",
	[401] = "Compte désactivé.",
	[402] = "Permission refusée.",
	[403] = "Unique mot de passe non spécifié.",
	[404] = "Autentification erronée."
};
local API_RECORD_ERROR_CODE = {
	[400] = "Exécution ratée.",
};

-- Discover available APIs and corresponding information
payload = "/webapi/query.cgi?api=SYNO.API.Info&method=Query&version=1&query=SYNO.API.Auth";
response, status, errorCode = Synology:GET(payload);
--fibaro:debug("response [" .. response .. "] status [" .. status .."] error [" .. errorCode .. "]")
if tonumber(status) == 200 then
	jsonTable = json.decode(response);
  	local version = jsonTable.data["SYNO.API.Auth"].maxVersion;
	if version >= 2 then
		fibaro:debug("Version API Synology OK");
		pathAuth = jsonTable.data["SYNO.API.Auth"].path;
		fibaro:debug("Chemin API Synology = "..pathAuth);
        cgiUsed="/entry.cgi";
        apiUsed="SYNO.Core.System";
        if version < 6 then
            cgiUsed="/dsm/system.cgi";
            apiUsed="SYNO.DSM.System";
        end

		-- Create new login session
		payload = "/webapi/"..pathAuth.."?api=SYNO.API.Auth&method=Login&version=2&account="..login.."&passwd="..password.."&session=DSM&format=sid";
		response, status, errorCode = Synology:GET(payload);
		if tonumber(status) == 200 then
			jsonTable = json.decode(response);
			if jsonTable.success == true then
				SID = jsonTable.data.sid;
				fibaro:debug("SID API Synology = "..SID);

				-- ShutDown the disk station
				payload = "/webapi"..cgiUsed.."?api="..apiUsed.."&version=1&method=shutdown&_sid="..SID;
				response, status, errorCode = Synology:GET(payload);
        		fibaro:debug("response [" .. response .. "] status [" .. status .."] error [" .. errorCode .. "]")
				jsonTable = json.decode(response);
				if jsonTable.success == true then
					fibaro:log("Arrêt OK");
					fibaro:debug('<span style="color:green;">Arrêt du Disk Station Synology OK</span>');
				else
					fibaro:log("Erreur");
					fibaro:debug('<span style="color:red;">Le Disk Station ne s\'est pas arrêté</span>');
				end
				--

				-- Destroy current login session
				payload = "/webapi/"..pathAuth.."?api=SYNO.API.Auth&method=Logout&version=2&session=DSM&_sid="..SID;
				response, status, errorCode = Synology:GET(payload);
               	fibaro:debug(status);
			else
				fibaro:log("Erreur");
				fibaro:debug('<span style="color:red;">Erreur : '..API_AUTH_ERROR_CODE[tonumber(jsonTable.error.code)]..'</span>');
			end
		else
			fibaro:log("Erreur");
			fibaro:debug('<span style="color:red;">Erreur : Authentification API ratée</span>');
		end
	else
		fibaro:log("Erreur");
		fibaro:debug('<span style="color:red;">Erreur : Version API Synology trop vieille : <b>DSM 4.0-2251</b> est requise</span>');
	end
else
	fibaro:log("Erreur");
	fibaro:debug('<span style="color:red;">Erreur : Impossible de se connecter au Disk Station Synology</span>');
end

 

État :

--------------------------------------------------
-- Synology DSM
-- Reboot the disk station
-- janvier 2015
--------------------------------------------------

-- User configurable variables
local login = "aa";
local password = "bb";

-- System variables
local selfID = fibaro:getSelfId();
local ip = fibaro:get(selfID, 'IPAddress');
local port = fibaro:get(selfID, 'TCPPort');
local nameNAS = fibaro:getName(selfID);
local Synology = Net.FHttp(ip, tonumber(port));
local API_AUTH_ERROR_CODE = {
    [0] = "Sans erreur.",
	[100] = "Erreur inconnue.",
	[101] = "Compte non spécifié.",
	[400] = "Mot de passe invalide.",
	[401] = "Compte désactivé.",
	[402] = "Permission refusée.",
	[403] = "Unique mot de passe non spécifié.",
	[404] = "Autentification erronée."
};
local API_RECORD_ERROR_CODE = {
	[400] = "Exécution ratée.",
};
local OK_connected = false;

-- Test connection
tcpSocket = Net.FTcpSocket(ip, tonumber(port));
bytes, errorCode = tcpSocket:write("Test");
fibaro:log("Détection");
if errorCode == 0 then
	OK_connected = true;
  fibaro:log(nameNAS.." ON");
  fibaro:call(selfID, "setProperty", "currentIcon", "52");
  --fibaro:call(175, "sendDefinedPushNotification", "Ping ReseauHome OK");
else
  fibaro:log(nameNAS.." OFF");
  fibaro:call(selfID, "setProperty", "currentIcon", "53");
  --fibaro:call(175, "sendDefinedPushNotification", "Ping ReseauHome OFF");
end
tcpSocket:disconnect();

-- Round function to display percentages
round = function(num)
     local a = math.floor(num*100 + 0.5)/ 100;
     return a,string.format("%.2f",a);
end

if OK_connected then
	-- Discover available APIs and corresponding information
	payload = "/webapi/query.cgi?api=SYNO.API.Info&method=Query&version=1&query=SYNO.API.Auth";
	response, status, errorCode = Synology:GET(payload);
	if tonumber(status) == 200 then
		jsonTable = json.decode(response);
  	version = jsonTable.data["SYNO.API.Auth"].maxVersion;
		if version >= 2 then
			fibaro:debug("Version API Synology OK");
			pathAuth = jsonTable.data["SYNO.API.Auth"].path;
			fibaro:debug("Chemin API Synology = "..pathAuth);
			cgiUsed_cpu_mem = "/entry.cgi";
			cgiUsed_temp = cgiUsed_cpu_mem;
			cgiUsed_vols = cgiUsed_cpu_mem;
			apiUsed_cpu_mem = "SYNO.Core.System.Utilization";
			apiUsed_temp_system = "SYNO.Core.System";
			apiUsed_temp_disk = apiUsed_temp_system;
			apiUsed_vols = apiUsed_temp_system;
			apiMethod_cpu_mem="get";
			apiMethod_temp = "info";
			apiMethod_vols = apiMethod_temp;
			if version < 6 then
				cgiUsed_cpu_mem = "/dsm/system_loading.cgi";
				cgiUsed_temp = "/dsm/info.cgi";
				cgiUsed_vols = "/dsm/volume.cgi";
				apiUsed_cpu_mem = "SYNO.DSM.SystemLoading";
				apiUsed_temp_system = "SYNO.DSM.Info";
				apiUsed_temp_disk = "";
				apiUsed_vols = "SYNO.DSM.Volume";
				apiMethod_cpu_mem = "getinfo";
				apiMethod_temp = apiMethod_cpu_mem;
				apiMethod_vols = "list";
			end

			-- Create new login session
			payload = "/webapi/"..pathAuth.."?api=SYNO.API.Auth&method=Login&version=2&account="..login.."&passwd="..password.."&session=DSM&format=sid";
			response, status, errorCode = Synology:GET(payload);
			if tonumber(status) == 200 then
				jsonTable = json.decode(response);
				if jsonTable.success == true then
					SID = jsonTable.data.sid;
					fibaro:debug("SID API Synology = ["..SID.."]");
					
					-- Prepare string
					local info_cpu_memory = "";
					
					-- CPU info from the disk station
					payload = "/webapi"..cgiUsed_cpu_mem.."?api="..apiUsed_cpu_mem.."&version=1&method="..apiMethod_cpu_mem.."&type=current&_sid="..SID;
					response, status, errorCode = Synology:GET(payload);
					if tonumber(status) == 200 then
						jsonTable = json.decode(response);
						if jsonTable.success == true then
							info_cpu = jsonTable.data.cpu;
							load_mem = jsonTable.data.memory.real_usage;
							fibaro:debug("Memory: "..load_mem.."%");
							info_cpu_memory = "Memory: "..load_mem.."% ";
							load_cpu = 0;
							if (version < 6) then
								load_cpu = info_cpu.user*100;
							else
								load_cpu = info_cpu.other_load+info_cpu.system_load+info_cpu.user_load;
							end
							fibaro:debug("CPU: "..load_cpu.."%");
							info_cpu_memory = info_cpu_memory.."CPU: "..load_cpu.."%";
							fibaro:call(selfID, "setProperty", "ui.CPULoad.value", info_cpu_memory);
						end
					else
						fibaro:log("Erreur");
						fibaro:debug('<span style="color:red;">Erreur : '..API_AUTH_ERROR_CODE[tonumber(errorCode)]..'</span>');
					end

					-- Temp info from the disk station
					payload = "/webapi"..cgiUsed_temp.."?api="..apiUsed_temp_system.."&version=1&method="..apiMethod_temp.."&_sid="..SID;
					response, status, errorCode = Synology:GET(payload);
					if tonumber(status) == 200 then
						jsonTable = json.decode(response);
						if jsonTable.success == true then
							if jsonTable.data.sys_temp ~= nil then
								temp_system = "System: "..jsonTable.data.sys_temp.."°C";
							else
								temp_system = "System: N/A";
							end
							fibaro:debug("Temperature "..temp_system);
							fibaro:call(selfID, "setProperty", "ui.SYSTEMTemp.value", temp_system);
						end
					else
						fibaro:log("Erreur");
						fibaro:debug('<span style="color:red;">Erreur : '..API_AUTH_ERROR_CODE[tonumber(errorCode)]..'</span>');
					end

					-- Prepare string
					local temp_disks = "";
				
					-- Temp info from the disk station
					payload = "/webapi"..cgiUsed_temp.."?api="..apiUsed_temp_disk.."&version=1&method="..apiMethod_temp.."&type=storage&_sid="..SID;
					response, status, errorCode = Synology:GET(payload);
					if tonumber(status) == 200 then
						jsonTable = json.decode(response);
						if jsonTable.success == true then
							local disk_tab = jsonTable.data.hdd_info;
							for nb = 1, #disk_tab do
								temp_disks = temp_disks..disk_tab[nb].diskno..": "..disk_tab[nb].temp.."°C ";
							end
							fibaro:debug("Disks temperature: "..temp_disks);
							fibaro:call(selfID, "setProperty", "ui.DISKSTemp.value", temp_disks);
						end
					else
						fibaro:log("Erreur");
						fibaro:debug('<span style="color:red;">Erreur : '..API_AUTH_ERROR_CODE[tonumber(errorCode)]..'</span>');
					end

					-- Prepare string
					local vols_load = "";
				
					-- Temp info from the disk station
					payload = "/webapi"..cgiUsed_vols.."?api="..apiUsed_vols.."&version=1&method="..apiMethod_vols.."&type=storage&_sid="..SID;
					response, status, errorCode = Synology:GET(payload);
					if tonumber(status) == 200 then
						jsonTable = json.decode(response);
						if jsonTable.success == true then
							local vols_tab = jsonTable.data.vol_info;
							for nb = #vols_tab, 1, -1 do
								used_size_vol = vols_tab[nb].used_size;
								total_size_vol = vols_tab[nb].total_size;
								occupied_size = round(used_size_vol / total_size_vol * 100);
								vols_load = vols_load..vols_tab[nb].name..": "..occupied_size.."% ";
							end
							fibaro:debug("Volumes Load: "..vols_load);
							fibaro:call(selfID, "setProperty", "ui.VOLSLoad.value", vols_load);
						end
					else
						fibaro:log("Erreur");
						fibaro:debug('<span style="color:red;">Erreur : '..API_AUTH_ERROR_CODE[tonumber(errorCode)]..'</span>');
					end

					-- Destroy current login session
					payload = "/webapi/"..pathAuth.."?api=SYNO.API.Auth&method=Logout&version=2&session=DSM&_sid="..SID;
					response, status, errorCode = Synology:GET(payload);
					fibaro:debug("Déconnexion: "..status);
				else
					fibaro:log("Erreur");
					fibaro:debug('<span style="color:red;">Erreur : '..API_AUTH_ERROR_CODE[tonumber(jsonTable.error.code)]..'</span>');
				end
			else
				fibaro:log("Erreur");
				fibaro:debug('<span style="color:red;">Erreur : Authentification API ratée</span>');
			end
		else
			fibaro:log("Erreur");
			fibaro:debug('<span style="color:red;">Erreur : Version API Synology trop vieille : <b>DSM 4.0-2251</b> est requise</span>');
		end
	else
		fibaro:log("Erreur");
		fibaro:debug('<span style="color:red;">Erreur : Impossible de se connecter au Disk Station Synology</span>');
	end
else
	fibaro:call(selfID, "setProperty", "ui.CPULoad.value", "Memory: N/A % CPU: N/A %");
	fibaro:call(selfID, "setProperty", "ui.SYSTEMTemp.value", "System: N/A °C");
	fibaro:call(selfID, "setProperty", "ui.DISKSTemp.value", "Disk: N/A °C");
end

Réveiller :

-- convert MAC adress, every 2 Chars (7-bit ASCII), to one Byte Char (8-bits)
function convertMacAddress(address)
  local s = string.gsub(address, ":", "");
  local x = "";  -- will contain converted MAC
  for i=1, 12, 2 do
    x = x .. string.char(tonumber(string.sub(s, i, i+1), 16));
  end
  return x;
end

fibaro:log("Réveiller");

-- MAC adress
local _macAddress = convertMacAddress("AA:BB:CC:DD:EE:FF");
-- Create Magic Packet 6 x FF
local _magicPacket = string.char(0xff, 0xff, 0xff, 0xff, 0xff, 0xff);
-- Broadcast Address
local _broadcastAddress = "192.168.X.255";
-- Default port used
local _wakeOnLanPort = 9;

fibaro:sleep(750);

for i = 1, 16 do
  _magicPacket = _magicPacket .. _macAddress;
end

fibaro:log("Magic packet créé");

fibaro:sleep(1000);

socket = Net.FUdpSocket();
socket:setBroadcast(true);

local bytes, errorCode = socket:write(_magicPacket, _broadcastAddress, _wakeOnLanPort);
--check for error
if errorCode == 0 then
  fibaro:log("Envoyé");
else
  fibaro:log("Envoi raté");
end

-- clean up memory
socket = nil;

fibaro:log("Attendre le réveil.");

 

Et le lien vers la page qui m'a servie à faire cela :

api documentation for homebridge-synology (v0.2.2)

 

Voilà ... :P

 

  • Upvote 1
Lien vers le commentaire
Partager sur d’autres sites

Hello ,

bon je vous le dis tout de suite ...

 

je suis une buse ,

j ai mis le VD en place mais j'ai une erreur  au début ...:20: la loose

je pense que j ai loupé un truc ...

 

il faut bien renseigner , login /mdp

ip du nas 

port du nas

...?

 

VD_Syno.JPG.406d70f2e7c818c876e1bb5a2f60fc27.JPG

 

merci si des gens veulent faire du social ...

 

Minos

 

Lien vers le commentaire
Partager sur d’autres sites

Bonjour Minos,

 

L'IP du NAS se rentre en haut de la fenêtre du VD, dans le champ "Adresse IP" et le port dans le champ "Port" (5000 si vous ne l'avez pas changé).

Pour l'utilisateur et le mot de passe, cela se passe dans le code des boutons, au début, il y a :

-- User configurable variables
local login = "aa";
local password = "bb";

Là, il faut rentrer à la place de aa, le nom de votre utilisateur NAS, et à la place de bb le mot de passe de cet utilisateur.

Il faut faire cela dans les boutons "Redémarrer", "Arrêter" et "Etat".

 

Voilà ... :D

 

Lien vers le commentaire
Partager sur d’autres sites

Merci de prendre du temps pour répondre,

 

Cependant , j ai tout renseigné comme tu le décris .

 

malgré cela , j'ai l'erreur que j'ai postée ...

 

bizarre....

 

 

Lien vers le commentaire
Partager sur d’autres sites

Bon , j'ai honte...:(

 

je crois que avec  la chaleur ..... pffff neurones ont fondu...

 

je changeais l'ip et port dans le bouton .....pffff

 

 

maintenant c'est OK

 

 

Minas.JPG

Lien vers le commentaire
Partager sur d’autres sites

Bonsoir Minos,

 

Voici les icônes.

 

Une fois ajoutés dans la HC2, récupérer les index d'image et remplacer dans le bouton "Etat" :

[...]
  fibaro:log(nameNAS.." ON");
  fibaro:call(selfID, "setProperty", "currentIcon", "52");
[...]
et
[...]
  fibaro:log(nameNAS.." OFF");
  fibaro:call(selfID, "setProperty", "currentIcon", "53");
[...]

Voilà ... :P

OFF

Synology_OFF.png

 

ON

Synology_ON.png

 

REDEMARRER

Synology_restart.png

 

ARRETER

Synology_Shutdown.png

 

ETAT + REVEILLER

Synology_wol.png

Modifié par Kana-chan
Lien vers le commentaire
Partager sur d’autres sites

Hello

Etape 1   : Merci bien tout est fonctionnel. ...:16:

Etape 2 : Pensez vous qu il est possible de mettre en place  par exemple dans ce même VD ou ailleurs un script qui check-la t° système du syno et par rapport à un seuil  donné change la vitesse des ventilateurs pour le mode frais mode silencieux ...

 

Vos avis....

Aujourd'hui c épreuve de philo. ..

Lâchez-vous. ..

 

Lol

Bonne journée

 

Minos

 

 

Lien vers le commentaire
Partager sur d’autres sites

Perso is laisserais le soin au Synology de gérer sa vitesse de ventilation comme un grand. Si ta HC2 déconne, plus de gestion du ventilateur et ton Synology est mort, ou ordres contradictoires. Bref, e n théorie c'est une bonne idée, mais je ne prendrais pas le risque

Envoyé de mon Nexus 5 en utilisant Tapatalk

Lien vers le commentaire
Partager sur d’autres sites

Merci de vos retours. 

C est vrai que la réflexion de jojo est pertinente. 

Le syno  va se reguler tout seul comme un grand. 

Pas utile de rajouter une couche qui risque de dégrader le fonctionnement. 

 

Merci de vos lumières. .....

Lien vers le commentaire
Partager sur d’autres sites

×
×
  • Créer...