Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. [Vorlage] JS: Log-Datei aufbereiten für VIS

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    [Vorlage] JS: Log-Datei aufbereiten für VIS

    This topic has been deleted. Only users with topic management privileges can see it.
    • liv-in-sky
      liv-in-sky @Nashra last edited by liv-in-sky

      @Nashra

      hast du das gemacht ?

      * Option 1: Hinzufügen im JavaScript-Adapter:
       *    1. Im ioBroker links auf "Instanzen" klicken, dort den JS-Adapter wählen, etwa javascript.0
       *    2. Unter "Zusätzliche NPM-Module" einfach "tail" (ohne Anführungszeichen) eingeben
       *    3. Speichern
       * 
      

      Image 1.png

      1 Reply Last reply Reply Quote 1
      • Nashra
        Nashra Most Active Forum Testing last edited by Nashra

        @liv-in-sky
        Ja habe ich alles gemacht, danke für die Info und Hilfe 👍

        1 Reply Last reply Reply Quote 0
        • Mic
          Mic Developer @Nashra last edited by Mic

          @Nashra sagte in [Vorlage] JS: Log-Datei aufbereiten für VIS:

          Und noch etwas...
          Um 0 Uhr bekomme ich folgenden Error im Log

          2019-09-28 00:00:02.102 - info: javascript.0 script.js.Meine_Geräte.VIS-Logs: Start new Tail process. File path to current log: [/opt/iobroker/log/iobroker.2019-09-28.log]
          2019-09-28 00:00:02.126 - error: javascript.0 Error in callback: Error [ERR_UNHANDLED_ERROR]: Unhandled error. ('watch for /opt/iobroker/log/iobroker.2019-09-28.log failed: Error: ENOENT: no such file or directory, stat \'/opt/iobroker/log/iobroker.2019-09-28.log\'')
          2019-09-28 00:00:02.126 - error: javascript.0 at Tail.emit (events.js:187:17)
          2019-09-28 00:00:02.127 - error: javascript.0 at Tail.watch (/opt/iobroker/node_modules/iobroker.javascript/node_modules/tail/lib/tail.js:136:12)
          2019-09-28 00:00:02.127 - error: javascript.0 at new Tail (/opt/iobroker/node_modules/iobroker.javascript/node_modules/tail/lib/tail.js:87:10)
          2019-09-28 00:00:02.128 - error: javascript.0 at Object.startTailingProcess (script.js.Meine_Geräte.VIS-Logs:770:14)
          2019-09-28 00:00:02.128 - error: javascript.0 at Timeout._onTimeout (/opt/iobroker/node_modules/iobroker.javascript/lib/sandbox.js:1888:34)
          2019-09-28 00:00:02.128 - error: javascript.0 at ontimeout (timers.js:438:13)
          2019-09-28 00:00:02.128 - error: javascript.0 at tryOnTimeout (timers.js:300:5)
          2019-09-28 00:00:02.128 - error: javascript.0 at listOnTimeout (timers.js:263:5)
          2019-09-28 00:00:02.128 - error: javascript.0 at Timer.processTimers (timers.js:223:10)
          2019-09-28 00:00:03.112 - info: javascript.0 script.js.Meine_Geräte.VIS-Logs: Start monitoring of the ioBroker log...
          

          Das sieht ja danach aus dass das Log noch nicht existiert, ist das richtig?
          Was müßte wo und wie geändert werden.

          Das ist seltsam, du bist bislang der erste, der das berichtet. Ich fange das eigentlich mit dem Script ab. D.h. falls für den neuen Tag um 0:00 Uhr noch kein neues Log-File existiert, lasse ich automatisch ein leeres Logfile erzeugen.

          function startTailingProcess() {
          
              // Path to iobroker log file
              let strFsFullPath = getCurrentFullFsLogPath();
          
              // Create a new log file. It will created if it is not yet existing.
              // This will avoid an error if right after midnight the log file is not yet there
          																											 
              const fs = require('fs');
              if (fs.existsSync(strFsFullPath)) {
                  // File is existing
              } else {
                  // File is not existing, so we create it.
                  if (LOG_DEBUG) log (DEBUG_IGNORE_STR + 'Log file is not existing, so we need to create a blank file.');
                  fs.writeFile(strFsFullPath, '', function(err) {
                      if(err) return log(err);
                  }); 
              }
          
              // Now start new tailing instance
              if(LOG_INFO) log('Start new Tail process. File path to current log: [' + strFsFullPath + ']');
              G_tail = new G_Tail(strFsFullPath, G_tailOptions);
          
          }
          

          Seltsam, dass das nur bei dir auftritt. Kann ich jetzt nicht reproduzieren...
          Aber ich habe eine Vermutung, und hab mal in die Runde gefragt: https://forum.iobroker.net/topic/25384/js-wie-erst-nach-file-erstellung-fortsetzen

          1 Reply Last reply Reply Quote 1
          • Mic
            Mic Developer last edited by

            @Nashra
            Bitte teste mal die neue Version 2.0.2 des Scripts und poste, welcher Log um Mitternacht dann ausgegeben wird.

            Also einfach Script austauschen, zum Test kannst du einfach alles unterhalb von dieser Zeile ersetzen, an den Einstellungen etc. habe ich nichts geändert:

            /*************************************************************************************************************************
             * Ab hier nichts mehr ändern / Stop editing here!
             *************************************************************************************************************************/
            
            
            Nashra 1 Reply Last reply Reply Quote 1
            • Nashra
              Nashra Most Active Forum Testing @Mic last edited by

              @Mic sagte in [Vorlage] JS: Log-Datei aufbereiten für VIS:

              @Nashra
              Bitte teste mal die neue Version 2.0.2 des Scripts und poste, welcher Log um Mitternacht dann ausgegeben wird.

              Also einfach Script austauschen, zum Test kannst du einfach alles unterhalb von dieser Zeile ersetzen, an den Einstellungen etc. habe ich nichts geändert:

              /*************************************************************************************************************************
               * Ab hier nichts mehr ändern / Stop editing here!
               *************************************************************************************************************************/
              

              Script ausgetauscht mal sehen was er um Mitternacht anzeigt, werde morgen berichten.

              1 Reply Last reply Reply Quote 1
              • Nashra
                Nashra Most Active Forum Testing last edited by

                Moin @Mic
                das Log von heute Morgen

                2019-10-02 00:00:00.079 - error: javascript.0 script.js.Meine_Geräte.VIS-Logs: monitorLogChanges not executed as starting new Tailing Process was not successful
                2019-10-02 00:00:00.122 - info: javascript.0 script.js.Meine_Geräte.VIS-Logs: Start new Tail process. File path to current log: [/opt/iobroker/log/iobroker.2019-10-02.log]
                
                
                1 Reply Last reply Reply Quote 0
                • Mic
                  Mic Developer last edited by

                  @Nashra
                  Danke fürs testen und berichten. Waren da nur diese 2 Zeilen im Log oder noch mehr?

                  Was kommt als Ausgabe, wenn du in der Konsole folgendes eingibst:

                  stat -c %a /opt/iobroker/log
                  

                  Bitte teste auch mal folgenden Code in einem neuen Script.

                  const FILE_TO_TEST = '/opt/iobroker/log/testdatei_01.txt';
                  const fs = require('fs');
                  fs.writeFile(FILE_TO_TEST, '', function(err) {
                      if (err) {
                          log('The file [' + FILE_TO_TEST + '] could not be created.', 'error');
                          log('fs.writeFile Error: ' + err, 'error');
                      } else {
                          log('File [' + FILE_TO_TEST + '] created.');
                      }
                  });
                  

                  Damit testen wir, ob du generell die Rechte hast, im Log-Verzeichnis die Datei testdatei_01.txt anzulegen.

                  Nashra 1 Reply Last reply Reply Quote 0
                  • Nashra
                    Nashra Most Active Forum Testing @Mic last edited by Nashra

                    @Mic sagte in [Vorlage] JS: Log-Datei aufbereiten für VIS:

                    @Nashra
                    Danke fürs testen und berichten. Waren da nur diese 2 Zeilen im Log oder noch mehr?

                    Nein, nur die zwei Zeilen

                    Was kommt als Ausgabe, wenn du in der Konsole folgendes eingibst:

                    stat -c %a /opt/iobroker/log
                    

                    Es kommt 777

                    Bitte teste auch mal folgenden Code in einem neuen Script.

                    Log-Ausgabe

                    javascript.0	2019-10-02 20:07:53.458	info	script.js.Meine_Geräte.TEST: File [/opt/iobroker/log/testdatei_01.txt] created.
                    javascript.0	2019-10-02 20:07:53.445	info	script.js.Meine_Geräte.TEST: registered 0 subscriptions and 0 schedules
                    javascript.0	2019-10-02 20:07:53.396	info	Start javascript script.js.Meine_Geräte.TEST
                    

                    wird also angelegt

                    1 Reply Last reply Reply Quote 0
                    • S
                      Stormbringer last edited by Stormbringer

                      Wieder mal Danke für den tollen Skript @Mic. Aber hätte mal ne echt blöde Frage.... Wie kann man denn den Inhalt vom LOG Viewer per Telegram verschicken? Wenn man den Wert von log oder logJSON in einen Telegram Textbaustein einfügt kommt nix an. Getriggert hätte ich jetzt auf logJSONcount.... Antwort in Blockly wär nett 😉

                      crunchip liv-in-sky 2 Replies Last reply Reply Quote 0
                      • crunchip
                        crunchip Forum Testing Most Active @Stormbringer last edited by

                        @Stormbringer wenn ich es richtig verstanden habe, möchtest du die log Datei per Telegram verschicken?
                        mal probiert ob es über den Schraubenschlüssel...Settings telegram...funktioniert

                        S 1 Reply Last reply Reply Quote 1
                        • S
                          Stormbringer @crunchip last edited by

                          @crunchip
                          ne habe ich noch nicht, wollte es eigentlich ohne benachrichtigung haben... kann man da ja nicht einstellen oder? ist das ûbertragungsprinzip darüber ein anderes wie über den blockly sendto block?

                          crunchip 1 Reply Last reply Reply Quote 0
                          • crunchip
                            crunchip Forum Testing Most Active @Stormbringer last edited by

                            @Stormbringer achso, ich dachte du möchtest ne Meldung, wenn z.b. ein Eintrag im log erfolgt.

                            S 1 Reply Last reply Reply Quote 0
                            • S
                              Stormbringer @crunchip last edited by

                              @crunchip ja aber eine stille ohne gebimmel 😉

                              crunchip 1 Reply Last reply Reply Quote 0
                              • crunchip
                                crunchip Forum Testing Most Active @Stormbringer last edited by

                                @Stormbringer ich lass bei mir eh nix bimmeln😁
                                hab mir z.b. ne 2te telegram instanz gemacht...in dem Fall nur für Bilder..
                                und diese könnte man ja dann lautlos stellen....nur so ne Idee

                                S 1 Reply Last reply Reply Quote 0
                                • S
                                  Stormbringer @crunchip last edited by

                                  @crunchip hab ich auch aber für unwichtige sachen. die erscheinen dann auch nicht am homescreen 😉 und das soll lautlos am homescreen erscheinen 😉

                                  1 Reply Last reply Reply Quote 0
                                  • liv-in-sky
                                    liv-in-sky @Stormbringer last edited by

                                    @Stormbringer damit bekommt man die letzte nachricht des json's - den trigger und den datenpunkt mußt du noch auswählen

                                    Image 1.png

                                    <block xmlns="http://www.w3.org/1999/xhtml" type="on_ext" id="9!yfv;Sg04Tj62+w58vA" x="-1137" y="112.00000000000011">
                                     <mutation items="1"></mutation>
                                     <field name="CONDITION">ne</field>
                                     <field name="ACK_CONDITION"></field>
                                     <value name="OID0">
                                       <shadow type="field_oid" id="tv*-N%k5`oqO5{9Q0-=(">
                                         <field name="oid">default</field>
                                       </shadow>
                                     </value>
                                     <statement name="STATEMENT">
                                       <block type="variables_set" id="8Kq4[NfoIG%e39OP.MDA">
                                         <field name="VAR" id="8}fHip}IhD3D~DSPXbPE" variabletype="">object-json</field>
                                         <value name="VALUE">
                                           <block type="convert_json2object" id="UjPByb7n?[_uotOmS1CX">
                                             <value name="VALUE">
                                               <block type="get_value" id="]NJjXm5k_Er[+`:u]M?9">
                                                 <field name="ATTR">val</field>
                                                 <field name="OID">javascript.0.Log-Script.logInfo.logJSON</field>
                                               </block>
                                             </value>
                                           </block>
                                         </value>
                                         <next>
                                           <block type="telegram" id="WhItLZul[bGEQ9[T.ndu">
                                             <field name="INSTANCE">.0</field>
                                             <field name="LOG"></field>
                                             <field name="SILENT">TRUE</field>
                                             <field name="PARSEMODE">default</field>
                                             <value name="MESSAGE">
                                               <shadow type="text" id="J?OV.%_=|B0:HaWV.!I@">
                                                 <field name="TEXT">text</field>
                                               </shadow>
                                               <block type="get_attr" id="VKg,pPLz0_clTk~0U8iT">
                                                 <value name="PATH">
                                                   <shadow type="text" id="+4X^EVXurAry7lAHs!QT">
                                                     <field name="TEXT">i.msg</field>
                                                   </shadow>
                                                   <block type="text_join" id="G0yz-^AsfL{c_PlG`w!(">
                                                     <mutation items="2"></mutation>
                                                     <value name="ADD0">
                                                       <block type="math_arithmetic" id="lS)m-s!@Z/hqJf1E.qx/">
                                                         <field name="OP">MINUS</field>
                                                         <value name="A">
                                                           <shadow type="math_number" id="+a+@O@g4U*ByH|U!vpAa">
                                                             <field name="NUM">1</field>
                                                           </shadow>
                                                           <block type="lists_length" id="95hg~r!{l$RTQlxX_$I{">
                                                             <value name="VALUE">
                                                               <block type="variables_get" id="^No#Hz9D0ld~i{io@~5d">
                                                                 <field name="VAR" id="8}fHip}IhD3D~DSPXbPE" variabletype="">object-json</field>
                                                               </block>
                                                             </value>
                                                           </block>
                                                         </value>
                                                         <value name="B">
                                                           <shadow type="math_number" id="T0k6Qgkkh#/-+;.7l6S#">
                                                             <field name="NUM">1</field>
                                                           </shadow>
                                                         </value>
                                                       </block>
                                                     </value>
                                                     <value name="ADD1">
                                                       <block type="text" id="!M9w^as(g+hUTaGM?IF#">
                                                         <field name="TEXT">.msg</field>
                                                       </block>
                                                     </value>
                                                   </block>
                                                 </value>
                                                 <value name="OBJECT">
                                                   <block type="variables_get" id="ls@fq`{,|]F7sc_l@a{)">
                                                     <field name="VAR" id="8}fHip}IhD3D~DSPXbPE" variabletype="">object-json</field>
                                                   </block>
                                                 </value>
                                               </block>
                                             </value>
                                           </block>
                                         </next>
                                       </block>
                                     </statement>
                                    </block>
                                    

                                    S 2 Replies Last reply Reply Quote 0
                                    • S
                                      Stormbringer @liv-in-sky last edited by Stormbringer

                                      @liv-in-sky
                                      alter schwede. hab jetzt eigentlich alles automatisiert mit blockly aber auf sowas wär ich nicht gekommen 😂😂 ich verstehs nicht mal 😋 aber scheint das zu sein was ich such. ich teste es mal. viel dank

                                      liv-in-sky 1 Reply Last reply Reply Quote 0
                                      • Nashra
                                        Nashra Most Active Forum Testing last edited by

                                        @Mic , es kommt nur noch dies um 0 Uhr

                                        2019-10-05 00:00:00.105 - error: javascript.0 script.js.Meine_Geräte.VIS-Logs: monitorLogChanges not executed as starting new Tailing Process was not successful
                                        

                                        sonst alles OK

                                        1 Reply Last reply Reply Quote -1
                                        • liv-in-sky
                                          liv-in-sky @Stormbringer last edited by liv-in-sky

                                          @Stormbringer sagte in [Vorlage] JS: Log-Datei aufbereiten für VIS:

                                          @liv-in-sky
                                          alter schwede. hab jetzt eigentlich alles automatisiert mit blockly aber auf sowas wär ich nicht gekommen 😂😂 ich verstehs nicht mal 😋 aber scheint das zu sein was ich such. ich teste es mal. viel dank

                                          ich denke man sollte noch irgendeine art zähler pro minute hinzufügen, in der das script blockiert wird - es werden sonst evtl ganz schön viele nachrichten - je nach dem welches log du aussliest

                                          z.b bei einem netzwerkproblem kann es sein das maßig fehler kommen - die würden dann alle versendet

                                          S 1 Reply Last reply Reply Quote 0
                                          • S
                                            Stormbringer @liv-in-sky last edited by

                                            @liv-in-sky Danke nett von dir, das habe ich schon berücksichtig. Wusste nur das mit dem Text konvertieren nicht weiter.... Aber dein Blockly rennt, vielen Dank nochmal g

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            937
                                            Online

                                            31.9k
                                            Users

                                            80.1k
                                            Topics

                                            1.3m
                                            Posts

                                            60
                                            617
                                            122780
                                            Loading More Posts
                                            • Oldest to Newest
                                            • Newest to Oldest
                                            • Most Votes
                                            Reply
                                            • Reply as topic
                                            Log in to reply
                                            Community
                                            Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                                            The ioBroker Community 2014-2023
                                            logo