{"id":774,"date":"2013-03-30T11:50:07","date_gmt":"2013-03-30T10:50:07","guid":{"rendered":"http:\/\/www.streppone.it\/cosimo\/blog\/?p=774"},"modified":"2013-03-30T11:53:37","modified_gmt":"2013-03-30T10:53:37","slug":"logging-nagios-remote-commands","status":"publish","type":"post","link":"https:\/\/www.streppone.it\/cosimo\/blog\/2013\/03\/logging-nagios-remote-commands\/","title":{"rendered":"Logging nagios remote commands"},"content":{"rendered":"<p>Quick trick, I needed it to debug execution of remote <strong>nagios<\/strong> commands.<\/p>\n<p>Just drop this file into <code>\/var\/nagios\/.bashrc<\/code>, assuming your local <code>nagios<\/code> user is configured to use the <code>\/bin\/bash<\/code> shell:<\/p>\n<pre>\r\n#!\/bin\/bash\r\n#\r\n# Log every command run by the nagios user\r\n# into \/var\/log\/auth.log (at least on Debian and derivatives)\r\n#\r\ntrap 'logger -p auth.info -t nagios \"Running $BASH_COMMAND\"' DEBUG\r\n<\/pre>\n<p>The <code>trap<\/code> function executes a given command or list of commands when the list of signals specified as arguments are raised,<br \/>\nas in:<\/p>\n<pre>trap [COMMAND] [SIGNALS]<\/pre>\n<p>The <code>DEBUG<\/code> signal is special: it will fire every time a command is executed. Using <code>logger<\/code> ensures that whatever command the nagios user is trying to execute will be logged.<\/p>\n<p>Last bit, how do you get the command text? It&#8217;s available in the <code>$BASH_COMMAND<\/code> variable.<\/p>\n<p>Here&#8217;s an extract of the resulting log information:<\/p>\n<pre>\r\nMar 30 10:48:05 big1 nagios: Running \/usr\/lib\/nagios\/plugins\/check_cpu -i 5 -w 90 -c 98\r\nMar 30 10:49:42 big1 nagios: Running \/usr\/lib\/nagios\/plugins\/check_tcp -p 3306\r\nMar 30 10:49:42 big1 nagios: Running \/var\/nagios\/libexec\/check_load -w40,40,40 -c50,50,50\r\nMar 30 10:50:26 big1 nagios: Running \/usr\/lib\/nagios\/plugins\/check_procs -w 1:1 -c 1:1 -a \/usr\/sbin\/cron\r\nMar 30 10:50:44 big1 nagios: Running \/usr\/lib\/nagios\/plugins\/check_disk -w 20 -c 10 -r \"^\/(ssd|store[1-3])?$\"\r\n...\r\n<\/pre>\n<p>To learn more about traps, here&#8217;s a <a href=\"https:\/\/duckduckgo.com\/?q=bash+traps\">web search on &#8220;bash traps&#8221;<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Quick trick, I needed it to debug execution of remote nagios commands. Just drop this file into \/var\/nagios\/.bashrc, assuming your local nagios user is configured to use the \/bin\/bash shell: #!\/bin\/bash # # Log every command run by the nagios user # into \/var\/log\/auth.log (at least on Debian and derivatives) # trap &#8216;logger -p auth.info [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[512],"tags":[520,254,248,519,521,61],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Logging nagios remote commands - Random hacking<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.streppone.it\/cosimo\/blog\/2013\/03\/logging-nagios-remote-commands\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Logging nagios remote commands - Random hacking\" \/>\n<meta property=\"og:description\" content=\"Quick trick, I needed it to debug execution of remote nagios commands. Just drop this file into \/var\/nagios\/.bashrc, assuming your local nagios user is configured to use the \/bin\/bash shell: #!\/bin\/bash # # Log every command run by the nagios user # into \/var\/log\/auth.log (at least on Debian and derivatives) # trap &#039;logger -p auth.info [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.streppone.it\/cosimo\/blog\/2013\/03\/logging-nagios-remote-commands\/\" \/>\n<meta property=\"og:site_name\" content=\"Random hacking\" \/>\n<meta property=\"article:published_time\" content=\"2013-03-30T10:50:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-03-30T10:53:37+00:00\" \/>\n<meta name=\"author\" content=\"cosimo\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"cosimo\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2013\/03\/logging-nagios-remote-commands\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2013\/03\/logging-nagios-remote-commands\/\"},\"author\":{\"name\":\"cosimo\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\"},\"headline\":\"Logging nagios remote commands\",\"datePublished\":\"2013-03-30T10:50:07+00:00\",\"dateModified\":\"2013-03-30T10:53:37+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2013\/03\/logging-nagios-remote-commands\/\"},\"wordCount\":118,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\"},\"keywords\":[\".bashrc\",\"bash\",\"debian\",\"nagios\",\"trap\",\"webops\"],\"articleSection\":[\"Operations\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.streppone.it\/cosimo\/blog\/2013\/03\/logging-nagios-remote-commands\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2013\/03\/logging-nagios-remote-commands\/\",\"url\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2013\/03\/logging-nagios-remote-commands\/\",\"name\":\"Logging nagios remote commands - Random hacking\",\"isPartOf\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#website\"},\"datePublished\":\"2013-03-30T10:50:07+00:00\",\"dateModified\":\"2013-03-30T10:53:37+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2013\/03\/logging-nagios-remote-commands\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.streppone.it\/cosimo\/blog\/2013\/03\/logging-nagios-remote-commands\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2013\/03\/logging-nagios-remote-commands\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.streppone.it\/cosimo\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Logging nagios remote commands\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#website\",\"url\":\"https:\/\/www.streppone.it\/cosimo\/blog\/\",\"name\":\"Random hacking\",\"description\":\"Assume nothing. Code defensively. Keep it simple, stupid!\",\"publisher\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.streppone.it\/cosimo\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\",\"name\":\"cosimo\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g\",\"caption\":\"cosimo\"},\"logo\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/\"},\"url\":\"https:\/\/www.streppone.it\/cosimo\/blog\/author\/cosimo\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Logging nagios remote commands - Random hacking","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.streppone.it\/cosimo\/blog\/2013\/03\/logging-nagios-remote-commands\/","og_locale":"en_US","og_type":"article","og_title":"Logging nagios remote commands - Random hacking","og_description":"Quick trick, I needed it to debug execution of remote nagios commands. Just drop this file into \/var\/nagios\/.bashrc, assuming your local nagios user is configured to use the \/bin\/bash shell: #!\/bin\/bash # # Log every command run by the nagios user # into \/var\/log\/auth.log (at least on Debian and derivatives) # trap 'logger -p auth.info [&hellip;]","og_url":"https:\/\/www.streppone.it\/cosimo\/blog\/2013\/03\/logging-nagios-remote-commands\/","og_site_name":"Random hacking","article_published_time":"2013-03-30T10:50:07+00:00","article_modified_time":"2013-03-30T10:53:37+00:00","author":"cosimo","twitter_card":"summary_large_image","twitter_misc":{"Written by":"cosimo","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2013\/03\/logging-nagios-remote-commands\/#article","isPartOf":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2013\/03\/logging-nagios-remote-commands\/"},"author":{"name":"cosimo","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1"},"headline":"Logging nagios remote commands","datePublished":"2013-03-30T10:50:07+00:00","dateModified":"2013-03-30T10:53:37+00:00","mainEntityOfPage":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2013\/03\/logging-nagios-remote-commands\/"},"wordCount":118,"commentCount":0,"publisher":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1"},"keywords":[".bashrc","bash","debian","nagios","trap","webops"],"articleSection":["Operations"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.streppone.it\/cosimo\/blog\/2013\/03\/logging-nagios-remote-commands\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2013\/03\/logging-nagios-remote-commands\/","url":"https:\/\/www.streppone.it\/cosimo\/blog\/2013\/03\/logging-nagios-remote-commands\/","name":"Logging nagios remote commands - Random hacking","isPartOf":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#website"},"datePublished":"2013-03-30T10:50:07+00:00","dateModified":"2013-03-30T10:53:37+00:00","breadcrumb":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2013\/03\/logging-nagios-remote-commands\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.streppone.it\/cosimo\/blog\/2013\/03\/logging-nagios-remote-commands\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2013\/03\/logging-nagios-remote-commands\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.streppone.it\/cosimo\/blog\/"},{"@type":"ListItem","position":2,"name":"Logging nagios remote commands"}]},{"@type":"WebSite","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#website","url":"https:\/\/www.streppone.it\/cosimo\/blog\/","name":"Random hacking","description":"Assume nothing. Code defensively. Keep it simple, stupid!","publisher":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.streppone.it\/cosimo\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1","name":"cosimo","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g","caption":"cosimo"},"logo":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/"},"url":"https:\/\/www.streppone.it\/cosimo\/blog\/author\/cosimo\/"}]}},"_links":{"self":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/posts\/774"}],"collection":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/comments?post=774"}],"version-history":[{"count":3,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/posts\/774\/revisions"}],"predecessor-version":[{"id":776,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/posts\/774\/revisions\/776"}],"wp:attachment":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/media?parent=774"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/categories?post=774"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/tags?post=774"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}