{"id":459,"date":"2009-03-08T14:42:49","date_gmt":"2009-03-08T12:42:49","guid":{"rendered":"http:\/\/contoso.se\/blog\/?p=459"},"modified":"2010-09-01T12:26:15","modified_gmt":"2010-09-01T10:26:15","slug":"logfile-size-on-suse","status":"publish","type":"post","link":"https:\/\/contoso.se\/blog\/?p=459","title":{"rendered":"Logfile Check on Linux"},"content":{"rendered":"<p>In Operations Manager 2007 R2 we have the possibility to monitor Linux and UNIX machines. There are among with other new features two new management pack templates:<\/p>\n<ul>\n<li>Unix\/Linux LogFile (monitor a logfile for a specified entry)<\/li>\n<li>Unix\/Linux Service (monitor a service with a standalone process)<\/li>\n<\/ul>\n<p>In this post I will show some ideas how to monitor file size on a linux machine. File size monitoring is not a default feature in R2, not on Windows or on Linux machines. On Windows machines I use a two state monitor and a script, describe in <a href=\"http:\/\/contoso.se\/blog\/?p=127\">this<\/a> post.<\/p>\n<p>The first step is to create a script on the Linux side. This script checks how big the file is, and if the file is bigger then 100 it will write a warning to a logfile (scriptlog.log).<\/p>\n<blockquote><p>#!\/bin\/sh<br \/>\nfind \/load.sh -printf &#8216;%s %p\\n&#8217; | while read size name; do<br \/>\nif [ &#8220;$size&#8221; -gt 100 ]; then<br \/>\necho $(date) WARNING the file is $size &gt;&gt; scriptlog.log<br \/>\nfi<br \/>\ndone<\/p><\/blockquote>\n<p>The next step is to get Linux to run it automatically, we can do that with cron. Cron is a time-based job scheduler in Linux. Cron is driven by a crontab, a configuration file that specifies what to run and when. My crontab looks like<\/p>\n<blockquote><p>* * * * * \/ root\/script.sh<\/p><\/blockquote>\n<p>It is very simple, I run the script every minute. Configure it with<\/p>\n<blockquote><p>crontab -e<\/p><\/blockquote>\n<p>The next step is to configure a management pack template for the Linux logfile to trigger on WARNING in the scriptlog.log file, configure it to trigger on WARNING. It is also important to keep track of the cron process, fortunately that is monitored with the default SUSE management pack.<\/p>\n<p>You are now monitoring if there is a problem with the file size. The next step is to get the size of the file as performance data in Operations Manager. This can also be done with a script and a collection rule. Create a Collection Rule (Probe Based\/Script (Performance)) and run the following script with the rule:<\/p>\n<blockquote><p>Set objShell = WScript.CreateObject(&#8220;WScript.Shell&#8221;)<br \/>\nSet objExecObject = objShell.Exec(&#8220;cmd \/c C:\\plink.exe user@192.168.0.71 -pw password stat -c%s \/ root\/script.sh&#8221;)<br \/>\nDo While Not objExecObject.StdOut.AtEndOfStream<br \/>\nstrText = objExecObject.StdOut.ReadLine()<\/p>\n<p>Dim oAPI,oBAG<br \/>\nSet oAPI = CreateObject(&#8220;MOM.ScriptAPI&#8221;)<br \/>\nSet oBag = oAPI.CreatePropertyBag()<br \/>\nCall oBag.AddValue(&#8220;PerfValue&#8221;, 10)<br \/>\nCall oAPI.Return(oBag)<br \/>\nLoop<\/p><\/blockquote>\n<p>This script runs plink.exe. Plink (PuTTY Link) is a command-line connection tool. We will use that to execute commands on the Linux side. The script will then collect the result of the command, the file size, and send it back as a performance data value (PerfValue). I have the same kind of script for Windows <a href=\"http:\/\/contoso.se\/blog\/?p=213\">here<\/a>.<\/p>\n<p>The next thing we might want to check is if the file exists. We can do that with a two state monitor. In <a href=\"http:\/\/contoso.se\/blog\/?p=305\">this<\/a> post you can read how to configure a two state monitor with a script. Use the script below in your monitor<\/p>\n<blockquote><p>Dim oAPI, oBag<br \/>\nSet oAPI = CreateObject(&#8220;MOM.ScriptAPI&#8221;)<br \/>\nSet oBag = oAPI.CreatePropertyBag()<br \/>\nSet objShell = WScript.CreateObject(&#8220;WScript.Shell&#8221;)<br \/>\nSet objExecObject = objShell.Exec(&#8220;cmd \/c C:\\plink.exe user@192.168.0.71 -pw password [ -f \/ root\/thefile.log ] &amp;&amp; echo ok || echo bad&#8221;)<br \/>\nDo While Not objExecObject.StdOut.AtEndOfStream<br \/>\nstrValue = objExecObject.StdOut.ReadLine()<\/p>\n<p>If instr(strValue, &#8220;ok&#8221;) Then<br \/>\nCall oBag.AddValue(&#8220;Status&#8221;,&#8221;OK&#8221;)<br \/>\nCall oAPI.Return(oBag)<br \/>\nEnd If<\/p>\n<p>If instr(strValue, &#8220;bad&#8221;) Then<br \/>\nCall oBag.AddValue(&#8220;Status&#8221;,&#8221;Bad&#8221;)<br \/>\nCall oAPI.Return(oBag)<br \/>\nEnd If<\/p>\n<p>Loop<\/p><\/blockquote>\n<p>That script checks if thefile.log exists in the root directory. If it does it will send back &#8220;ok&#8221; else &#8220;bad&#8221;.<\/p>\n<p>Summary: We use a couple of different scripts and forwards the result to Ops Mgr. One script echo to a logfile that we then pickup with default a Logfile management pack template. Another script is run from inside a two state monitor with the plink.exe tool. In this post I wanted to give you some ideas to get info into Operations Manager 2007 from your Linux machines.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Operations Manager 2007 R2 we have the possibility to monitor Linux and UNIX machines. There are among with other new features two new management pack templates: Unix\/Linux LogFile (monitor a logfile for a specified entry) Unix\/Linux Service (monitor a service with a standalone process) In this post I will show some ideas how to &hellip; <a href=\"https:\/\/contoso.se\/blog\/?p=459\">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":[19],"tags":[],"_links":{"self":[{"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/459"}],"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=459"}],"version-history":[{"count":45,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/459\/revisions"}],"predecessor-version":[{"id":1766,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/459\/revisions\/1766"}],"wp:attachment":[{"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=459"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=459"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=459"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}