{"id":1367,"date":"2010-03-11T22:00:56","date_gmt":"2010-03-11T20:00:56","guid":{"rendered":"http:\/\/contoso.se\/blog\/?p=1367"},"modified":"2010-03-11T22:01:46","modified_gmt":"2010-03-11T20:01:46","slug":"how-to-monitor-file-size","status":"publish","type":"post","link":"https:\/\/contoso.se\/blog\/?p=1367","title":{"rendered":"How-to monitor file size"},"content":{"rendered":"<p>This script can be used with a monitor to monitor size of a file. In this example it monitor file C:\\temp\\myfile.txt and will generate an alert if that file is bigger then 50Mb (52428800 bytes). Settings for your two state script monitor can be<\/p>\n<ul>\n<li>General\n<ul>\n<li>Name: Contoso \u00e2\u20ac\u201c check file monitor<\/li>\n<li>Monitor Target: choose a suitable class<\/li>\n<li>Management Pack: choose a suitable MP<\/li>\n<\/ul>\n<\/li>\n<li>Schedule\n<ul>\n<li>Run every 15 Minutes<\/li>\n<\/ul>\n<\/li>\n<li>Script\n<ul>\n<li>File Name: contosocheckfilesize.vbs<\/li>\n<li>Script: see below<\/li>\n<\/ul>\n<\/li>\n<li>Unhealthy Expression\n<ul>\n<li>Property[@Name=&#8217;Status&#8217;] does not contain Ok<\/li>\n<\/ul>\n<\/li>\n<li>Healthy Expression\n<ul>\n<li>Property[@Name=&#8217;Status&#8217;] contain Ok<\/li>\n<\/ul>\n<\/li>\n<li>Health\n<ul>\n<li>Healthy Healthy Healthy<\/li>\n<li>Unhealthy Unhealthy Warning<\/li>\n<\/ul>\n<\/li>\n<li>Alerting\n<ul>\n<li>check Generate alerts fort this monitor<\/li>\n<li>check Automatically resolve the alert when the monitor returns to a healthy state<\/li>\n<li>Alert Name: Contoso \u00e2\u20ac\u201c File Size monitor<\/li>\n<li>Alert Description: Warning. C:\\temp\\myfile.txt is to big. The file is $Data\/Context\/Property[@Name=&#8217;Size&#8217;]$ bytes.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<blockquote><p>Set objFSO = CreateObject(&#8220;Scripting.FileSystemObject&#8221;)<br \/>\nSet objFile = objFSO.GetFile(&#8220;C:\\temp\\myfile.txt&#8221;)<br \/>\nvarSize = objFile.Size<\/p>\n<p>Dim oAPI, oBag<br \/>\nIf varSize &gt; 52428800 Then<br \/>\nSet oAPI = CreateObject(&#8220;MOM.ScriptAPI&#8221;)<br \/>\nSet oBag = oAPI.CreatePropertyBag()<br \/>\nCall oBag.AddValue(&#8220;Status&#8221;,&#8221;Bad&#8221;)<br \/>\nCall oBag.AddValue(&#8220;Size&#8221;, varSize)<br \/>\nCall oAPI.Return(oBag)<br \/>\nElse<br \/>\nSet oAPI = CreateObject(&#8220;MOM.ScriptAPI&#8221;)<br \/>\nSet oBag = oAPI.CreatePropertyBag()<br \/>\nCall oBag.AddValue(&#8220;Status&#8221;,&#8221;Ok&#8221;)<br \/>\nCall oAPI.Return(oBag)<br \/>\nEnd If<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>This script can be used with a monitor to monitor size of a file. In this example it monitor file C:\\temp\\myfile.txt and will generate an alert if that file is bigger then 50Mb (52428800 bytes). Settings for your two state script monitor can be General Name: Contoso \u00e2\u20ac\u201c check file monitor Monitor Target: choose a &hellip; <a href=\"https:\/\/contoso.se\/blog\/?p=1367\">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],"tags":[],"_links":{"self":[{"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1367"}],"collection":[{"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1367"}],"version-history":[{"count":7,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1367\/revisions"}],"predecessor-version":[{"id":1374,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1367\/revisions\/1374"}],"wp:attachment":[{"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}