Hallo zusammen
Ich betrieb seit Jahren einen FHEM Server auf einem Raspberry. Nun bin ich umgezogen auf einen NUC. Dabei habe ich die Chance genutzt, auf proxmox auch nextcloud in einer CT laufen zu lassen. Auch das klappte wunderbar. Nun bietet nextcloud ja eine API an, in welcher im json Format aktuelle Informationen abgefragt werden können. Dabei muss man jedoch eingeloggt sein.
Hat jemand im FHEM diese json Anfrage mit httpmod integriert und könnte mir mit dem synthax helfen?
Bevor Du Dich da in was rein stürzt, eine Frage meiner Seits. Was genau willst Du denn wissen? Du hast nämlich einen super Aktivitäten Feed der schon sehr viel Infos liefert über Deine Aktivitäten auf Nextcloud.
Also, Nextcloud bietet diese API im json Format an:
https://localIP/ocs/v2.php/apps/serverinfo/api/v1/info?format=json
Wenn ich diese im Browser eingebe bekomme ich die Daten im json Format dargestellt welche ich genau benötigte. Wenn ich diese in der HttpMod Abfrage hinterlege kommt folgende Antwort:
Internals:
BUSY 0
CFGFN
CHANGED
DEF https://InternalIP/ocs/v2.php/apps/serverinfo/api/v1/info?format=json
FUUID 5e3e839b-f33f-3873-772d-b185b7b9a8a469f6
Interval 300
LASTSEND 1581155229.77915
MainURL https://InternalIP/ocs/v2.php/apps/serverinfo/api/v1/info?format=json
ModuleVersion 3.5.21 - 27.12.2019
NAME Nextcloud
NOTIFYDEV global
NR 11392
NTFY_ORDER 50-Nextcloud
STATE ???
TRIGGERTIME 1581155529.77869
TRIGGERTIME_FMT 2020-02-08 10:52:09
TYPE HTTPMOD
addr https://InternalIP:443
auth 0
buf
code 401
compress 1
conn
data
displayurl https://InternalIP/ocs/v2.php/apps/serverinfo/api/v1/info?format=json
header
host InternalIP
httpheader HTTP/1.1 401 Unauthorized
Server: nginx
Date: Sat, 08 Feb 2020 09:47:09 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 106
Connection: close
Set-Cookie: ocs3nf6v2ee2=859at56bb0kug96dj4jsjhgdd0; path=/; secure; HttpOnly
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Pragma: no-cache
Set-Cookie: oc_sessionPassphrase=aFnl5fCIm4irxG0bJm3uMvSwjIttXoN%2BgUY7dFr4C6fljun%2Beg08uTRGHVZxDrxYcUNZXsC5Ub8q3r6HKsGnuJaSwTWp33uAWIsmytYQOdfvJ8A0a1ChwFElRhz0B2FS; path=/; secure; HttpOnly
Set-Cookie: __Host-nc_sameSiteCookielax=true; path=/; httponly;secure; expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=lax
Set-Cookie: __Host-nc_sameSiteCookiestrict=true; path=/; httponly;secure; expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=strict
Cache-Control: no-cache, no-store, must-revalidate
Content-Security-Policy: default-src 'none';base-uri 'none';manifest-src 'self'
Feature-Policy: autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone 'none';payment 'none'
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Referrer-Policy: no-referrer
httpversion 1.0
hu_blocking 0
hu_filecount 1
hu_port 443
hu_portSfx
ignoreredirects 1
loglevel 4
path /ocs/v2.php/apps/serverinfo/api/v1/info?format=json
protocol https
redirects 0
timeout 2
url https://InternalIP/ocs/v2.php/apps/serverinfo/api/v1/info?format=json
value 0
HTTPCookieHash:
__Host-nc_sameSiteCookielax;/:
Name __Host-nc_sameSiteCookielax
Options path=/; httponly;secure; expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=lax
Path /
Value true
__Host-nc_sameSiteCookiestrict;/:
Name __Host-nc_sameSiteCookiestrict
Options path=/; httponly;secure; expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=strict
Path /
Value true
oc_sessionPassphrase;/:
Name oc_sessionPassphrase
Options path=/; secure; HttpOnly
Path /
Value aFnl5fCIm4irxG0bJm3uMvSwjIttXoN%2BgUY7dFr4C6fljun%2Beg08uTRGHVZxDrxYcUNZXsC5Ub8q3r6HKsGnuJaSwTWp33uAWIsmytYQOdfvJ8A0a1ChwFElRhz0B2FS
ocs3nf6v2ee2;/:
Name ocs3nf6v2ee2
Options path=/; secure; HttpOnly
Path /
Value 859at56bb0kug96dj4jsjhgdd0
QUEUE:
READINGS:
REQUEST:
data
header
ignoreredirects 0
retryCount 0
type update
url https://InernalIP/ocs/v2.php/apps/serverinfo/api/v1/info?format=json
value 0
sslargs:
Attributes:
DbLogExclude .*
Ich vermute das es etwas mit der Berechtigung zu tun hat. sprich ich müsste username und passwort noch mitschicken....
Das war nicht meine Frage. Ich wollte wissen was Du genau für Daten haben willst aus Deiner Nextcloud. Was willst Du wissen?
Denn wie gesagt es gibt ein XM Feed der ganz einfach integriert werden kann.
hallo
ich hätte gerne solche Infos wie z.B.: verwendeter Speicherpaltz, Benutzer und freier RAM, Anzahl User, Anzahl Shares, Anzahl der Dateien und so weiter.
Geht das mit diesem XM Feed und wo finde ich diesen?
Ok das ist was ganz anderes. Da musst Du in der Tat die API nehmen.
Bekommst Du denn die Daten per json wenn Du das im Browser machst?
Zitat von: CoolTux am 08 Februar 2020, 13:28:23
Ok das ist was ganz anderes. Da musst Du in der Tat die API nehmen.
Bekommst Du denn die Daten per json wenn Du das im Browser machst?
Ja genau. Da komme ich das richtige Resultat. Aber da bin ich natürlich auch eingeloggt. Wenn die Anfrage von fhem kommt ist da niemand eingeloggt, sprich er braucht die credential. Aber ich bringe es nicht hin diese richtig in die Anfrage einzubauen!
DEF https://user:password@InternalIP/ocs/v2.php/apps/serverinfo/api/v1/info?format=json
geht das
Sorry, war echt der Meinung das ich das genau so probiert hatte!
Funktioniert tadellos!!!
Funktioniert leider bei mir nicht so:
https://user:password@192.168.178.3/nextcloud/ocs/v2.php/apps/serverinfo/api/v1/info?format=json
Meines Erachtens ist der Pfad der aktuellen NC Vers 18 auch /nextcloud
Wüsste gerne @Mumpitz wie du das erfolgreich getestet hast? Weiter 401 Fehler bei mir. Keine Ahnung ob das mit meinem umgeleiteten https Port 555 (Standard ist ja 443) zu tun hat. Im Browseraufruf alles bestens, da eingeloggt.
Nextcloud Instanz ist auch von außen per DynDNS erreichbar. Beide Varianten funktionieren nicht mit HTTPMOD bei mir.
define Nextcloud_Server HTTPMOD https://user:passwort@dyn.cloud.de:555/nextcloud/ocs/v2.php/apps/serverinfo/api/v1/info?format=json
sollte ja passen, tut es aber nicht.
Edit: Führe ich den Befehl in der Konsole aus:
curl -k https://user:password@dyn.cloud.de:555/nextcloud/ocs/v2.php/apps/serverinfo/api/v1/info
werden mir die Werte gelistet. Brauche diese aber in FHEM ;-)
verbose 5 liefert mir:
2020.03.25 10:23:51 4: Nextcloud_Server: Read callback: request type was update retry 0, no headers, no body
2020.03.25 10:23:51 5: Nextcloud_Server: Read callback: body empty
2020.03.25 10:23:51 4: Nextcloud_Server: Read found no charset header (bodyDecode was set to auto)
2020.03.25 10:23:51 5: Nextcloud_Server: GetCookies is looking for Cookies
2020.03.25 10:23:51 5: Nextcloud_Server: ExtractSid called, context reading, num
2020.03.25 10:23:51 4: Nextcloud_Server: no header to look for redirects
2020.03.25 10:23:51 5: Nextcloud_Server: CheckAuth decided no authentication required
Und was sagt
curl -k https://user:passwort@dyn.cloud.de:555/nextcloud/ocs/v2.php/apps/serverinfo/api/v1/info?format=json
Mit: JSON
{"ocs":{"meta":{"status":"ok","statuscode":200,"message":"OK"},"data":{"nextcloud":{"system":{"version":"18.0.2.2","theme":"topa","enable_avatars":"yes","enable_previews":"yes","memcache.local":"\\OC\\Memcache\\APCu","memcache.distributed":"none","filelocking.enabled":"yes","memcache.locking":"none","debug":"no","freespace":381973336064,"cpuload":[0.23,0.25,0.44],"mem_total":948304,"mem_free":614476,"swap_total":102396,"swap_free":26528,"apps":{"num_installed":42,"num_updates_available":0,"app_updates":[]}},"storage":{"num_users":8,"num_files":76541,"num_storages":10,"num_storages_local":2,"num_storages_home":8,"num_storages_other":0},"shares":{"num_shares":13,"num_shares_user":4,"num_shares_groups":3,"num_shares_link":2,"num_shares_mail":0,"num_shares_room":0,"num_shares_link_no_password":2,"num_fed_shares_sent":0,"num_fed_shares_received":0,"permissions_0_1":"4","permissions_1_1":"3","permissions_2_1":"4","permissions_3_1":"2"}},"server":{"webserver":"Apache\/2.4.25 (Raspbian)","php":{"version":"7.3.16","memory_limit":536870912,"max_execution_time":3600,"upload_max_filesize":17179869184},"database":{"type":"mysql","version":"10.1.44","size":818511872}},"activeUsers":{"last5minutes":1,"last1hour":1,"last24hours":1}}}}pi@Raspi-FHEM-Server:~ $
das hier (xml Ausgabe) wie im Browser auch ohne eben ?format=json
<?xml version="1.0"?>
<ocs>
<meta>
<status>ok</status>
<statuscode>200</statuscode>
<message>OK</message>
</meta>
<data>
<nextcloud>
<system>
<version>18.0.2.2</version>
<theme>topa</theme>
<enable_avatars>yes</enable_avatars>
<enable_previews>yes</enable_previews>
<memcache.local>\OC\Memcache\APCu</memcache.local>
<memcache.distributed>none</memcache.distributed>
<filelocking.enabled>yes</filelocking.enabled>
<memcache.locking>none</memcache.locking>
<debug>no</debug>
<freespace>381973336064</freespace>
<cpuload>
<element>0.24</element>
<element>0.35</element>
<element>0.52</element>
</cpuload>
<mem_total>948304</mem_total>
<mem_free>617192</mem_free>
<swap_total>102396</swap_total>
<swap_free>25760</swap_free>
<apps>
<num_installed>42</num_installed>
<num_updates_available>0</num_updates_available>
<app_updates/>
</apps>
</system>
<storage>
<num_users>8</num_users>
<num_files>76541</num_files>
<num_storages>10</num_storages>
<num_storages_local>2</num_storages_local>
<num_storages_home>8</num_storages_home>
<num_storages_other>0</num_storages_other>
</storage>
<shares>
<num_shares>13</num_shares>
<num_shares_user>4</num_shares_user>
<num_shares_groups>3</num_shares_groups>
<num_shares_link>2</num_shares_link>
<num_shares_mail>0</num_shares_mail>
<num_shares_room>0</num_shares_room>
<num_shares_link_no_password>2</num_shares_link_no_password>
<num_fed_shares_sent>0</num_fed_shares_sent>
<num_fed_shares_received>0</num_fed_shares_received>
<permissions_0_1>4</permissions_0_1>
<permissions_1_1>3</permissions_1_1>
<permissions_2_1>4</permissions_2_1>
<permissions_3_1>2</permissions_3_1>
</shares>
</nextcloud>
<server>
<webserver>Apache/2.4.25 (Raspbian)</webserver>
<php>
<version>7.3.16</version>
<memory_limit>536870912</memory_limit>
<max_execution_time>3600</max_execution_time>
<upload_max_filesize>17179869184</upload_max_filesize>
</php>
<database>
<type>mysql</type>
<version>10.1.44</version>
<size>818511872</size>
</database>
</server>
<activeUsers>
<last5minutes>1</last5minutes>
<last1hour>1</last1hour>
<last24hours>1</last24hours>
</activeUsers>
</data>
</ocs>
Dann sollte mit HTTPMOD auch was kommen. Oder machst Du den curl Aufruf aus einem anderen System? Also nicht vom FHEM Server.
Zitat von: CoolTux am 25 März 2020, 13:26:24
Dann sollte mit HTTPMOD auch was kommen. Oder machst Du den curl Aufruf aus einem anderen System? Also nicht vom FHEM Server.
Doch, klar mache ich den Aufruf von der Konsole (Putty SSH) vom FHEM Server. Kommen tut ja schon was im Define in FHEM, nur eben mit 401 Error.
Vielleicht liegt es ja am umgeswitchten 555 Port.
Vielleicht Sonderzeichen im Benutzernamen oder Passwort, die man in FHEM escapen muss?
https://developer.mozilla.org/de/docs/Web/HTTP/Status/401
401 ist ein Auth Problem. Eventuell muss man das anders machen mit HTTPMOD aber da kenne ich mich zu wenig aus mit.