{"id":268,"date":"2016-04-23T20:54:13","date_gmt":"2016-04-24T00:54:13","guid":{"rendered":"http:\/\/jasonralph.org\/?p=268"},"modified":"2016-11-22T16:27:56","modified_gmt":"2016-11-22T21:27:56","slug":"nagios-python-plugin-check-lock-file-exists","status":"publish","type":"post","link":"https:\/\/jasonralph.org\/?p=268","title":{"rendered":"Nagios Python Plugin Check Lock File Exists"},"content":{"rendered":"<pre class=\"theme:solarized-dark lang:default decode:true \" >\r\n#!\/usr\/bin\/python\r\n\r\nimport os.path\r\nimport time\r\nimport datetime\r\nimport sys\r\nimport optparse\r\n\r\n\"\"\"Check the status of application lock file to be sure it is not stale, warn at critical at 18000 seconds warn at 10800\"\"\"\r\nparser = optparse.OptionParser()\r\nparser.add_option('-w', action=\"store\", default=\"10800\", help=\"seconds to warn\", type=\"int\")\r\nparser.add_option('-c', action=\"store\", default=\"18000\", help=\"seconds to crit\", type=\"int\")\r\noptions, args = parser.parse_args()\r\n\r\nnagOk = 0\r\nnagWarn = 1\r\nnagCrit = 2\r\n\r\ntry:\r\n    statInfo = os.stat('\/opt\/application\/.sync-lock')\r\nexcept OSError:\r\n    print(\"WAITING FOR LOCK FILE\")\r\n    sys.exit(nagOk)\r\n\r\nnow = int(time.time())\r\nstatInfoSlice = statInfo[8]\r\ntimeDiff = now - statInfoSlice\r\n#print(\"NOW: %s\") % now\r\n#print(\"FILEAGE: %s\") %  statInfoSlice\r\n#print(\"TIMEDIFF: %s\") % timeDiff\r\n\r\nif timeDiff > options.c:\r\n    print(\"CRIT: lock file is older than 5 hours\")\r\n    sys.exit(nagCrit)\r\nelif timeDiff > options.w:\r\n    print(\"WARN: lock file is older than 3 hours\")\r\n    sys.exit(nagWarn)\r\nelse:\r\n    print(\"OK: lock file is under 3 hours\")\r\n    sys.exit(nagOk)\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>#!\/usr\/bin\/python import os.path import time import datetime import sys import optparse &#8220;&#8221;&#8221;Check the status of application lock file to be sure it is not stale, warn at critical at 18000 seconds warn at 10800&#8243;&#8221;&#8221; parser = optparse.OptionParser() parser.add_option(&#8216;-w&#8217;, action=&#8221;store&#8221;, default=&#8221;10800&#8243;, help=&#8221;seconds to warn&#8221;, type=&#8221;int&#8221;) parser.add_option(&#8216;-c&#8217;, action=&#8221;store&#8221;, default=&#8221;18000&#8243;, help=&#8221;seconds to crit&#8221;, type=&#8221;int&#8221;) options, args = parser.parse_args() [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-268","post","type-post","status-publish","format-standard","hentry","category-general-code"],"_links":{"self":[{"href":"https:\/\/jasonralph.org\/index.php?rest_route=\/wp\/v2\/posts\/268","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jasonralph.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jasonralph.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jasonralph.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jasonralph.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=268"}],"version-history":[{"count":2,"href":"https:\/\/jasonralph.org\/index.php?rest_route=\/wp\/v2\/posts\/268\/revisions"}],"predecessor-version":[{"id":506,"href":"https:\/\/jasonralph.org\/index.php?rest_route=\/wp\/v2\/posts\/268\/revisions\/506"}],"wp:attachment":[{"href":"https:\/\/jasonralph.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jasonralph.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jasonralph.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}