98_fheminfo.pm 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. ################################################################
  2. #+$Id: 98_fheminfo.pm 11984 2016-08-19 12:47:50Z rudolfkoenig $
  3. #+vim: ts=2:et
  4. #
  5. #+ (c) 2012 Copyright: Martin Fischer (m_fischer at gmx dot de)
  6. #+ All rights reserved
  7. #
  8. #+ This script free software; you can redistribute it and/or modify
  9. #+ it under the terms of the GNU General Public License as published by
  10. #+ the Free Software Foundation; either version 2 of the License, or
  11. # any later version.
  12. #
  13. # The GNU General Public License can be found at
  14. # http://www.gnu.org/copyleft/gpl.html.
  15. # A copy is found in the textfile GPL.txt and important notices to the license
  16. # from the author is found in LICENSE.txt distributed with these scripts.
  17. #
  18. # This script is distributed in the hope that it will be useful,
  19. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. # GNU General Public License for more details.
  22. #
  23. ################################################################
  24. package main;
  25. use strict;
  26. use warnings;
  27. use Config;
  28. sub CommandFheminfo($$);
  29. ########################################
  30. sub
  31. fheminfo_Initialize($$)
  32. {
  33. my %hash = (
  34. Fn => "CommandFheminfo",
  35. Hlp => "[send],show or send Fhem statistics",
  36. );
  37. $cmds{fheminfo} = \%hash;
  38. }
  39. ########################################
  40. sub
  41. CommandFheminfo($$)
  42. {
  43. my ($cl,$param) = @_;
  44. # split arguments
  45. my @args = split(/ +/,$param);
  46. my $name = "fheminfo";
  47. my %info;
  48. my $module = "HTTP::Request::Common";
  49. my $err = "Missing perl module '$module'. Please install this module first.";
  50. if(!checkModule($module)) {
  51. Log 1, "$name $err";
  52. return $err;
  53. }
  54. $module = "LWP::UserAgent";
  55. if(!checkModule($module)) {
  56. Log 1, "$name $err";
  57. return $err;
  58. }
  59. return "Unknown argument $args[0], usage: fheminfo [send]"
  60. if(@args && lc($args[0]) ne "send");
  61. return "Won't send, as sendStatistics is set to 'never'."
  62. if(@args &&
  63. lc($args[0]) eq "send" &&
  64. lc(AttrVal("global","sendStatistics","")) eq "never");
  65. my $branch = "DEVELOPMENT"; # UNUSED
  66. my $release = "5.8";
  67. my $feature = $featurelevel ? $featurelevel : $release;
  68. my $os = $^O;
  69. my $arch = $Config{"archname"};
  70. my $perl = $^V;
  71. my $uniqueID = getUniqueId();
  72. my $sendStatistics = AttrVal("global","sendStatistics",undef);
  73. my $moddir = $attr{global}{modpath}."/FHEM";
  74. my $upTime = fhemUptime();
  75. my %official_module;
  76. opendir(DH, $moddir) || return("$moddir: $!");
  77. foreach my $file (grep /^controls.*.txt$/, readdir(DH)) {
  78. open(FH, "$moddir/$file") || next;
  79. while(my $l = <FH>) {
  80. $official_module{$1} = 1 if($l =~ m+^UPD.* FHEM/\d\d_(.*).pm+);
  81. }
  82. close(FH);
  83. }
  84. closedir(DH);
  85. return "Can't read FHEM/controls_fhem.txt, execute update first."
  86. if(!%official_module);
  87. foreach my $d (sort keys %defs) {
  88. my $n = $defs{$d}{NAME};
  89. my $t = $defs{$d}{TYPE};
  90. my $m = "unknown";
  91. $m = $defs{$d}{model} if( defined($defs{$d}{model}) );
  92. $m = AttrVal($n,"model",$m);
  93. if($official_module{$t} && !$defs{$d}{TEMPORARY} && !$attr{$d}{ignore}) {
  94. $info{modules}{$t}{$n} = $m;
  95. }
  96. }
  97. $info{modules}{configDB}{configDB} = 'unknown' if (configDBUsed());
  98. my $str;
  99. $str = "Fhem info:\n";
  100. $str .= sprintf(" Release%*s: %s FeatureLevel: %s\n",
  101. 2, " ", $release, $feature);
  102. $str .= sprintf(" OS%*s: %s\n",7," ",$os);
  103. $str .= sprintf(" Arch%*s: %s\n",5," ",$arch);
  104. $str .= sprintf(" Perl%*s: %s\n",5," ",$perl);
  105. $str .= sprintf(" uniqueID%*s: %s\n",0," ",$uniqueID);
  106. $str .= sprintf(" upTime%*s: %s\n",3," ",$upTime);
  107. $str .= "\n";
  108. my $contModules;
  109. my $contModels;
  110. my $modStr;
  111. my @modules = keys %{$info{modules}};
  112. my $length = (reverse sort { $a <=> $b } map { length($_) } @modules)[0];
  113. $str .= "Defined modules:\n";
  114. foreach my $t (sort keys %{$info{modules}}) {
  115. my $c = scalar keys %{$info{modules}{$t}};
  116. my @models;
  117. foreach my $n (sort keys %{$info{modules}{$t}}) {
  118. my $model = $info{modules}{$t}{$n};
  119. if($model ne "unknown" && $t ne "dummy") {
  120. push(@models,$model) if(!grep {$_ =~ /$model/} @models);
  121. }
  122. }
  123. $str .= sprintf(" %s%*s: %d\n",$t,$length-length($t)+1," ",$c);
  124. if(@models != 0) {
  125. $modStr .= sprintf(" %s%*s: %s\n",
  126. $t,$length-length($t)+1," ", join(",",sort @models));
  127. $contModels .= join(",",sort @models)."|";
  128. }
  129. $contModules .= "$t:$c|";
  130. }
  131. if($modStr) {
  132. $str .= "\n";
  133. $str .= "Defined models per module:\n";
  134. $str .= $modStr;
  135. }
  136. my $td = (lc(AttrVal("global", "sendStatistics", "")) eq "onupdate") ?
  137. "yes" : "no";
  138. $str .= "\n";
  139. $str .= "Transmitting this information during an update: $td\n";
  140. $str .= "You can change this via the global attribute sendStatistics\n";
  141. if(@args != 0 && $args[0] eq "send") {
  142. my $uri = "http://fhem.de/stats/statistics.cgi";
  143. my $req = HTTP::Request->new("POST",$uri);
  144. $req->content_type("application/x-www-form-urlencoded");
  145. my $contInfo;
  146. $contInfo = "Release:$release|";
  147. $contInfo .= "Branch:$branch|";
  148. $contInfo .= "OS:$os|";
  149. $contInfo .= "Arch:$arch|";
  150. $contInfo .= "Perl:$perl";
  151. chop($contModules);
  152. if(!$contModels) {
  153. $req->content("uniqueID=$uniqueID&system=$contInfo&modules=$contModules");
  154. } else {
  155. chop($contModels);
  156. $req->content("uniqueID=$uniqueID&system=$contInfo&modules=$contModules&models=$contModels");
  157. }
  158. my $ua = LWP::UserAgent->new(
  159. agent => "Fhem/$release",
  160. timeout => 60);
  161. my $res = $ua->request($req);
  162. $str .= "\nserver response: ";
  163. if($res->is_success) {
  164. $str .= $res->content."\n";
  165. } else {
  166. $str .= $res->status_line."\n";
  167. }
  168. }
  169. return $str;
  170. }
  171. ########################################
  172. sub checkModule($) {
  173. my $module = shift;
  174. eval("use $module");
  175. if($@) {
  176. return(0);
  177. } else {
  178. return(1);
  179. }
  180. }
  181. sub
  182. fhemUptime()
  183. {
  184. my $diff = time - $fhem_started;
  185. my ($d,$h,$m,$ret);
  186. ($d,$diff) = _myDiv($diff,86400);
  187. ($h,$diff) = _myDiv($diff,3600);
  188. ($m,$diff) = _myDiv($diff,60);
  189. $ret = "";
  190. $ret .= "$d days, " if($d > 1);
  191. $ret .= "1 day, " if($d == 1);
  192. $ret .= sprintf("%02s:%02s:%02s", $h, $m, $diff);
  193. return $ret;
  194. }
  195. sub
  196. _myDiv($$)
  197. {
  198. my ($p1,$p2) = @_;
  199. return (int($p1/$p2), $p1 % $p2);
  200. }
  201. 1;
  202. =pod
  203. =item command
  204. =item summary display information about the system and FHEM definitions
  205. =item summary_DE zeigt Systeminformationen an
  206. =begin html
  207. <a name="fheminfo"></a>
  208. <h3>fheminfo</h3>
  209. <ul>
  210. <code>fheminfo [send]</code>
  211. <br>
  212. <br>
  213. fheminfo displays information about the system and FHEM definitions.
  214. <br>
  215. <br>
  216. The optional parameter <code>send</code> transmitts the collected data
  217. to a central server in order to support the development of FHEM. The
  218. transmitted data is processed graphically. The results can be viewed
  219. on <a href="http://fhem.de/stats/statistics.html">http://fhem.de/stats/statistics.html</a>.
  220. Based on the IP address, the approximate location is determined with
  221. an accuracy of about 40-80 km. The IP address is not saved.
  222. <br>
  223. <br>
  224. Features:<br>
  225. <ul>
  226. <li>Operating System Information</li>
  227. <li>Hardware architecture</li>
  228. <li>Installed Perl version</li>
  229. <li>Installed FHEM release</li>
  230. <li>Defined modules (only official FHEM Modules are counted)</li>
  231. <li>Defined models per module</li>
  232. </ul>
  233. <br>
  234. Example:
  235. <pre>
  236. fhem&gt; fheminfo
  237. Fhem info:
  238. Release : 5.3
  239. OS : linux
  240. Arch : i686-linux-gnu-thread-multi-64int
  241. Perl : v5.14.2
  242. uniqueID : 87c5cca38dc75a4f388ef87bdcbfbf6f
  243. Defined modules:
  244. ACU : 1
  245. CUL : 1
  246. CUL_FHTTK : 12
  247. CUL_HM : 66
  248. CUL_WS : 3
  249. FHEM2FHEM : 1
  250. FHEMWEB : 3
  251. FHT : 9
  252. [...]
  253. at : 4
  254. autocreate : 1
  255. dummy : 23
  256. notify : 54
  257. structure : 3
  258. telnet : 2
  259. watchdog : 9
  260. weblink : 17
  261. Defined models per module:
  262. CUL : CUN
  263. CUL_FHTTK : FHT80TF
  264. CUL_HM : HM-CC-TC,HM-CC-VD,HM-LC-DIM1T-CV,HM-LC-DIM1T-FM,HM-LC-SW1-PL,[...]
  265. CUL_WS : S555TH
  266. FHT : fht80b
  267. FS20 : fs20pira,fs20s16,fs20s4a,fs20sd,fs20st
  268. HMS : hms100-mg,hms100-tf,hms100-wd
  269. KS300 : ks300
  270. OWSWITCH : DS2413
  271. </pre>
  272. <br>
  273. <a name="fheminfoattr"></a>
  274. <b>Attributes</b>
  275. <br>
  276. <br>
  277. The following attributes are used only in conjunction with the
  278. <code>send</code> parameter. They are set on <code>attr global</code>.
  279. <br>
  280. <br>
  281. <ul>
  282. <li>sendStatistics<br>
  283. This attribute is used in conjunction with the <code>update</code> command.
  284. <br>
  285. <code>onUpdate</code>: transfer of data on every update (recommended setting).
  286. <br>
  287. <code>manually</code>: manually transfer of data via the <code>fheminfo send</code> command.
  288. <br>
  289. <code>never</code>: prevents transmission of data at anytime.
  290. </li>
  291. <br>
  292. </ul>
  293. </ul>
  294. =end html
  295. =begin html_DE
  296. <a name="fheminfo"></a>
  297. <h3>fheminfo</h3>
  298. <ul>
  299. <code>fheminfo [send]</code>
  300. <br>
  301. <br>
  302. fheminfo zeigt Informationen &uuml;ber das System und FHEM Definitionen an.
  303. <br>
  304. <br>
  305. Der optionale Parameter <code>send</code> &uuml;bertr&auml;gt die Informationen
  306. an einen zentralen Server um die Entwicklung von FHEM zu unterst&uuml;tzen.
  307. Die &uuml;bermittelten Daten werden grafisch aufbereitet und k&ouml;nnen auf
  308. <a href="http://fhem.de/stats/statistics.html">http://fhem.de/stats/statistics.html</a>
  309. abgerufen werden. Anhand der IP-Adresse wird der ungef&auml;hre Standort mit
  310. einer Genauigkeit von ca. 40-80 km ermittelt. Die IP-Adresse wird nicht gespeichert.
  311. <br>
  312. <br>
  313. Eigenschaften:<br>
  314. <ul>
  315. <li>Eingesetztes Betriebssystem</li>
  316. <li>Hardware Architektur</li>
  317. <li>Installierte Perl Version</li>
  318. <li>Installierte FHEM release</li>
  319. <li>Definierte Module (nur offizielle FHEM Module werden ermittelt)</li>
  320. <li>Definierte Modelle je Modul</li>
  321. </ul>
  322. <br>
  323. Beispiel:
  324. <pre>
  325. fhem&gt; fheminfo
  326. Fhem info:
  327. Release : 5.3
  328. OS : linux
  329. Arch : i686-linux-gnu-thread-multi-64int
  330. Perl : v5.14.2
  331. uniqueID : 87c5cca38dc75a4f388ef87bdcbfbf6f
  332. Defined modules:
  333. ACU : 1
  334. CUL : 1
  335. CUL_FHTTK : 12
  336. CUL_HM : 66
  337. CUL_WS : 3
  338. FHEM2FHEM : 1
  339. FHEMWEB : 3
  340. FHT : 9
  341. [...]
  342. at : 4
  343. autocreate : 1
  344. dummy : 23
  345. notify : 54
  346. structure : 3
  347. telnet : 2
  348. watchdog : 9
  349. weblink : 17
  350. Defined models per module:
  351. CUL : CUN
  352. CUL_FHTTK : FHT80TF
  353. CUL_HM : HM-CC-TC,HM-CC-VD,HM-LC-DIM1T-CV,HM-LC-DIM1T-FM,HM-LC-SW1-PL,[...]
  354. CUL_WS : S555TH
  355. FHT : fht80b
  356. FS20 : fs20pira,fs20s16,fs20s4a,fs20sd,fs20st
  357. HMS : hms100-mg,hms100-tf,hms100-wd
  358. KS300 : ks300
  359. OWSWITCH : DS2413
  360. </pre>
  361. <br>
  362. <a name="fheminfoattr"></a>
  363. <b>Attribute</b>
  364. <br>
  365. <br>
  366. Die folgenden Attribute werden nur in Verbindung mit dem Parameter
  367. <code>send</code> genutzt. Sie werden über <code>attr global</code> gesetzt.
  368. <br>
  369. <br>
  370. <ul>
  371. <li>sendStatistics<br>
  372. Dieses Attribut wird in Verbindung mit dem <code>update</code> Befehl verwendet.
  373. <br>
  374. <code>onUpdate</code>: &Uuml;bertr&auml;gt die Daten bei jedem Update (empfohlene Einstellung).
  375. <br>
  376. <code>manually</code>: Manuelle &Uuml;bertr&auml;gung der Daten &uuml;ber <code>fheminfo send</code>.
  377. <br>
  378. <code>never</code>: Verhindert die &Uuml;bertr&auml;gung der Daten.
  379. </li>
  380. <br>
  381. </ul>
  382. </ul>
  383. =end html_DE
  384. =cut