{"id":1575,"date":"2010-06-04T10:24:56","date_gmt":"2010-06-04T08:24:56","guid":{"rendered":"http:\/\/contoso.se\/blog\/?p=1575"},"modified":"2010-09-01T12:09:50","modified_gmt":"2010-09-01T10:09:50","slug":"check-last-line-only","status":"publish","type":"post","link":"http:\/\/contoso.se\/blog\/?p=1575","title":{"rendered":"Check Last Line Only"},"content":{"rendered":"<p>I wrote a script to check only the last line of a file. The scripts checks the last line every time it run. If you search my blog you will find a number of script to read logfiles. Create a new two state script monitor where you include the script below.\u00c2\u00a0 In my example script I looks in the C:\\temp\\myfile.txt file for the word &#8220;Warning&#8221; ( varWarPos = Instr(strLine, &#8220;Warning&#8221;) )<\/p>\n<ul>\n<li>Unhealthy Expression\n<ul>\n<li>Property[@Name=&#8217;Status&#8217;] Contains warning<\/li>\n<\/ul>\n<\/li>\n<li>Healthy Expression\n<ul>\n<li>Property[@Name=&#8217;Status&#8217;] Contains ok<\/li>\n<\/ul>\n<\/li>\n<li>Alert description\n<ul>\n<li>You could write any alert description here, but if you include the following parameters you will see the whole line and the status in the alert description.<\/li>\n<li>State $Data\/Context\/Property[@Name=&#8217;Status&#8217;]<\/li>\n<li>Line $Data\/Context\/Property[@Name=&#8217;Line&#8217;]$<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<div>Set oAPI = CreateObject(&#8220;MOM.ScriptAPI&#8221;)<\/div>\n<div>Set oBag = oAPI.CreatePropertyBag()<\/div>\n<div>Const ForReading = 1<\/div>\n<div>strFile = &#8220;C:\\TEMP\\myfile.txt&#8221;<\/div>\n<div>Set FSO = CreateObject(&#8220;Scripting.FileSystemObject&#8221;)<\/div>\n<div>Set inFile = FSO.OpenTextFile(strFile)<\/div>\n<div>lines = Split( inFile.ReadAll, vbLF )<\/div>\n<div>lineCount = UBound(lines)<\/div>\n<div>Set FSO = CreateObject(&#8220;Scripting.FileSystemObject&#8221;)<\/div>\n<div>Set TextFile = FSO.OpenTextFile(strFile, ForReading)<\/div>\n<div>For i = 1 to lineCount<\/div>\n<div>TextFile.ReadLine<\/div>\n<div>Next<\/div>\n<div>strLine = TextFile.ReadLine<\/div>\n<div>varWarPos = Instr(strLine, &#8220;Warning&#8221;)<\/div>\n<div>If varWarPos &gt; 0 Then<\/div>\n<div>varStatus = &#8220;Warning&#8221;<\/div>\n<div>varLine = strLine<\/div>\n<div>End If<\/div>\n<div>TextFile.Close<\/div>\n<div>If varStatus = &#8220;Warning&#8221; Then<\/div>\n<div>Call oBag.AddValue(&#8220;Line&#8221;, varLine)<\/div>\n<div>Call oBag.AddValue(&#8220;Status&#8221;,&#8221;warning&#8221;)<\/div>\n<div>Call oAPI.Return(oBag)<\/div>\n<div>Else<\/div>\n<div>Call oBag.AddValue(&#8220;Status&#8221;,&#8221;ok&#8221;)<\/div>\n<div>Call oAPI.Return(oBag)<\/div>\n<div>End If<\/div>\n","protected":false},"excerpt":{"rendered":"<p>I wrote a script to check only the last line of a file. The scripts checks the last line every time it run. If you search my blog you will find a number of script to read logfiles. Create a new two state script monitor where you include the script below.\u00c2\u00a0 In my example script &hellip; <a href=\"http:\/\/contoso.se\/blog\/?p=1575\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[13,19],"tags":[],"_links":{"self":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1575"}],"collection":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1575"}],"version-history":[{"count":7,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1575\/revisions"}],"predecessor-version":[{"id":1743,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1575\/revisions\/1743"}],"wp:attachment":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1575"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}