����C %# , #&')*)-0-(0%()(��C (((((((((((((((((((((((((((((((((((((((((((((((((((����"�������@�@�hC��}!���Ѱ��<"� 9iׂIIIHk�+?�c?��*Y�����!�du)b�T�9вU�$8G��I.�澬��D���Sq� q�}.<��Z�l�V!X� *x�-�\����t3i�Ũ�sNv71�ƛ\��z|t�L���$�����*f��kʮ��7�H;���~F%�'3�@�H�q�` 9mOL����/x@ @��G
d�8F�ه��Ka�Kdr�Fh.�]y4 JЛ��]�K�B�E$��$ $ �PR�����G�]��u�i$�$���'! "#031���C/Td=S�Q?���62Ccj{ ����̏d�چ/c�V�`��Wz͈�{Y`�d�h�L �]OB���l���o���mr���n��s-ڗEZ��N�_��1%b���H�ϣ������V�7):�ӷ)�}�~�(�;�!�b1�5K��[E�vϻ>��q.%� ���O���(�c�#x�$�'+��`٥v��v(�����M�"�v��B��.�a ���T�~�ϕ�hy(6nݱl��1yNɓx�������AR�8�rqv1.cS�+��_���&@�� �u�M�5Ĉ�Xm���eL�X�q��y#�9]�c�}ɄL��d�eJ몓���I1T�d��CaM�$��T�,�X �bʭ�!�%F5��X1x#���!�q��\��F��2��&Rq���C�ol~�̱�.0ϦL�d�`.������ ���m{�Y~k{C��}bv�;U��c<�r�~ɜs�1�j��]W�l��*նCr��Q�N9�-������d��E؛��nF��eړ�8(q��5UgRȱGTA��*������̆��V�珰����ezN��h�U]�T�FG�^���<��ay�,!���5.� �u�bΚ�V�J%��m�Dxn'�����6�@BPa�`��Hts� �ɮ���Ŏ�Zɬ��%B�X��d5Z���hC}�䅸�p+ k=��ʒ(�aՏFG&�%@/�{+�Yu+�ȣGѩ"O%�|vȲxF>�N(��ou�h6 &Y5��8�7�E$-��']n,@TD\��+���Ry�U��U^�Q,f>��1�����q��f��U��� ����F���ڥ��>I�����fNUw�u��#OMMQ6� N�*��_�� k� ����rS��`���1�:��!�F'<+� � b?O��2 !Q12A��� "3a������#$��?�,�7�!`yǮ(�1�6w��a���� �F�#��?*"s���v>��Ⱥ����f�v��͑���s����������]Gn��S ���ȥpG ы�E�g�)Z���x�rY�q�]�@f�_܃�pչEڎّC ����Ŝ*/ �h�O�Sv�و\��5��U��y��|o�Hm2C�S�BW����)��5��{T��W���=o*RA��<����L0g4{��쁢�ep�rw�8��7��U���t<Ԍѻ7�fGf�k}���Ê�㛆Gռz�Q@��{C��'G��8�!�S$�j��x���|���צV<��,����u�k�uu�rM�f�_dϣi ߫�ԟn�!K����mxu�=�槻�'j�X�����������%!A "1QR#Br��?�R:��R�n�b[�II?#��6<:�$gN����lGNlrr��dעMMn`ɿy�,�%B�e�W��dVS��r���� %�tT��(�ɷ��S�]�O]#�_LEMHN�M���kv���~X���O6�U�V_�����b���J�t�774����D!1AQa"2q�#3BRb����0���� 4CSr����cst�����?��^q���7�dG�U�"p��moz��'��n_x���唹e������<6��O�t���R>k��s=�Cr���e�?�i��� ����/��ں$be���o`ޮ�GHy�;fNAl�8��.�\�S������"���a�úF�YvNk�-*`v�k�ʈ2f�EE��Wa�,� �fF^#�;��[9��^~������Y$:0#W3������Z*���I�Z�ڹ�k�n--9=��G��;7F)m{T�Ɇ��=�����Ȭ5�5�B�aڞ5M����#m�5Ʀ��m�8��+Hh���$�}�:&�e�Q�[;i]С�:�:��o����$<~��5RB�?�s3�5�r��O��ֿ�w�P/��̅���(�Z6�R>)��N��4�!ʊ�wz�-�r�w+�yk���q�1�bKhƸ�4N�Ӑ�X����Q��_��})�+e1�5��n��q?��[�^�9�<�z3Fsi�8�'�)9p)�{��RP�Z+�*��p(aY��V����6l�g�9��;���d�u���Nt@�3�sTwzaŇ�GT�b�H��(#��*zc�������9K�b1�����t����Ê��
�Z?g�iD���H�R���B���^M����v���O���L�D,'d�q�C�P�����$Δ��U�֟֊=�s��F�$��J�ދZ?�N��������A�N�WP��,�� �¦�&;�x��dup�����i���Ipd���;�Dž!��ֿѮAb%�u��}j��-p��>I�[�N�bi����G�'�;4w�m]H�]����#LӘNN��R��������s�.]��en��-�8e��Ps����Q��;���ț�E�ݫ���7��g�_L��W��EZ:/��I���a�g�n�ܤ��iٹ���ŷ�T���H~i�a�����֎�~KV������ A-2m]�F"�m�9-Zbǰ�״ @����~�4�N�[�Uxč�tl>������u#r�gѐ�3���;M9�<�J�����1�vfL8����1�P�HgP�Xv��������{����O�}�n��KQ؋����7<�l�fey<�}�>�bX���4<`Y7���si��V)�s�:�{�rO�h�z �@4VW�B���&�������ɡob܋�F��4>y�s�fXWS�N�O$�,.u:�ԫ��g�yao4��$h��D#��ٸf^kh�7�#1Z�֥&���*�v-��;bޭ����Q�����h�ow�y]�ه.+�7�M�ⴻ �JY��g�f�i3q��KC��3�¹�?5�Z.N��^Z w���KF͂���7��ރ۞��wj��T�J.�q��\Sv1U����R��욽&�N����pЖ`�`у��m`v�n#z��4��>e��V�`'���h�����'�j�AҔ�-�4:H���n]9�h<��n����U�6m��2c�E�1/�Y�%���I��~ʏ�|VBƟ@����;�������%�M9M���}��1�D��d����%g���O��]��у&�r��f�7�uܲ���(!1AQaq�������0� ���?!��*��@)�Je�G��j��{�['��v+���������)���(�/����д%젍Z��kk�Lu�Rm���j.c���@Z� V�J��d��j���h6���2AO�� a;oBu���H�=���nK�W8�B�ɰ�u?��бأm,�sr����|����8˨i��qI2tZ�ۄJP��XE��������zޔj~]UMu����zv!����N�&�1�Y��zJ�ՠ��\p��o'ሸ�C؊Y��TD"HM5�Ъ��i߯a���F����A)�����ڮ����z�E���@�hg�֝8�1jk��\�M�3�8ܢ�� ������s�7����N}�ޭ������GN�Bc���L pk�;�J�δ3�e�iU�gAYW]\�>�GyگQ=��f�KA;T�a`eM+Q �� �Ln���̌]GM�����<Ħ�j���H��N�M�x�}aX{̣S� ��ԅ��n�MA�S�r�(����(�L��zo9���.�;
�ӳf������`Ӕ٢3�� IW��\9~_���saa�\ԊW�ܭX:���ӆ�38�ty*����N�qP����BI�Y��jE��>DP�!�R%-��4��'�皺;��~J�!�7m���X��h�P!曭���$�\�AYj�.lC��4��+�jD�dgC0-*���|��`ZD�+л�C"��)��s��8Kq�pq���Ms��4� ��7\U`�.��[Ey8��AH!/��,���(:M -�T䓥�~O�4-���Ԓn��}HDN7���K���$�_Ԕ䚞`�R�hB�_aX?4V��ŗ�@ه�u�a�;�{PcT+�������7YBo�?��r-ͩ{�ĎA�� ����˼n��M286��G���1���V�˜Jв"l��V5���5�C]h���̊�A���%� �'p���Ԃ���Ր��9=�d�=�e�{�'<3�_ �:^�~��4�(�n�-C�s��5m![�jmIqU�~�Tw8��`���p�H8�u�Д l m�aP�0�������9y����CM��F1G糞�.�U~�������FC�{�!e(Y�:���P����7~;�L�N^{�1r�\���ԬG(���0d�ÏO�qK�Z�⑼�T�{ 2��s��Kd�Տ?mMQ��=���6�7�i�����H+����9��d��=��;�QؤH8n�Lb�D��yS%�(�{b���Cu���p�t#C���$A"�H{���jqᶯ�:�n=E����hH�`�!�m��MA������?�v6���+MԿ⟚qK�i�D�*Q5��CZ���2�|]�:Xd+�t�:o@��M��� :�32��b����[\5=�ֵ7])�|t��Ϻ����w�B�ń�e���!`�:��I,��9:����j@/a 8����+<�u�(T^ۺ~��2oE�B�%b)��z��ݳځ�)��i�j��&��Fi`qr��w���7�@��P�� �3Z&<�m�S�C����7t�T����ƴ�q~J�e�r6�Z]�rL���ه�E17'�x���+[�ܜTc6�/�����W�`�qpMJ���N5^����x�}{l�Fm������1�oZ\�����/d�/6� �uӸ�0elXuX;M��$M�}mB��������Z%e���3f�js����O�J~2�z�86�*PB��v�Ν��e-��.�/��L�O����2����9���4}|��T5M���hÐ7�F*��l+y0����:|��=k[�d�;|�ԉe�=w�<��õ�<��'!1AQaq����� ������?��5����)�(���+>v����6&{���Ǹ@����M�����v��iA 6T'�w��h�s �E}�x��G&'g�� J~1q�f�f���&��q˘���-���vYm
�/i1 �I��6��u,)�#�,����l}*&`�$�ͬe�%�w3�x�Ѥ�Xc�D��执g�峕�5B/�|$��=���%8 a��2.l� c�@G� �\�/x[өq�]�v5?�����N|�!���\��,>��{�"r�/��?��&!1QAa�� ��ᑱ����?ĊD�肭�� nv@�yޝ (�����I ����U - ���b�m�E>,��1v!�d�&�� ���&�檔�5D�&0P��Ԕ�͒@Z��:E"� Q��`>PH:~�O�����P�3W��@hM��k�U��\�O��R�������5ʄ�,��f�|��r���}јxo)�"+h�QK���/��0�`�5�{M~�� ���'!1AQaq���0 �������?�?�k��#^�~�G��#V,������#Z�1'ܤ����������~p�O%O�O�\�q�`�~��}��E�Ű5 �輸�du����x\�$���s[�{T2t`B��gq�4Z]b� 㛪�3,(@����bAp�r)9:@|b�!r�g:N�^�Ʌ��� �x_�\��pm7I��0?>^k��������w���|.K�[sF@�]Gn*L �yO� le�P�.p��֍�j�S�=�ʨ�ןQF�"��5zʼn���k�*8�u" ����Fg��� �cSy�V������Ƈ��N��ؐ(�����48hV�A�ӎ^��^ ���jyB� ��p"�����y]�ļlU�(�7�U`3�pCGF'&yg������o��z������X��ν:�P"@�G@x[��o&MJ�$F.����hi w;}�/^͇q���n�mN�/�TQ���އ��O1\,}��bQ #¯^S!)��X���#GPȏ�t�� c^\��' }iIZ���a�)��������z��4͊�Ξy��48,��f���#�����KP!Jx�|w�ʆ�������������#��Z�������< �~K��r�p&qH/;�R���沽�+�E�R���~0v���V#ʀ�T��S(-ڝ��B�y�b�C�D������b��������8��~�= �Y�ͧ]��@n����M�k2�%�;�%,�r6�LR腻?^��;KŇ=�ք ���=`�ɥ��/����z�&�I{���#J��M���C��}�H9^UJ�,P ��pS����G�d69Ϭu���%"��ˢP��K�"k)��=��9� ����㇌,��Oli��Xzh� " � ������R��^�s����N�k��Q>�63(���� ��PQ�Py�����3����$f+W՛=4�ǁ`*��^��Eb�K�t�6��^��!�籷��ȭ��K{/;�L���p�x�����;a���Oلz�[�.NP4�]Gc�T�v����~sg'LED��]j��'�G�]�6rY����UPw�*O�İՋi�'8�۴�#g�Xx+=�eU6�R��c�"�u2��~�?n�y�;�u��3�'��6�f������b��߬M�$*��k&?6���*^1n����ێz)<��Gz� �����7����Y� ��ۃ)$A��2�L6� ե�H�<�r��#ʽ2��O��R���z�A��XW��@���������<�G� Ϥ�^�˓i�M�W���6 ��0��m){c�;ݧ�>R�a����}1�ٯ%�EY2�Q��Ep���$ ��E��qS��t#+x� *�h�UI��XM?�'//��a'�G�����q@���<��z��؟����cd��z�ˬT_u�Ѯ����&�z�k ��n ]�a%�py»�`Qd�xc������n�� ��*��oTd�;'j�<�!j���'�(~�ʹW�M� P�mȘ��@֨V+��R�`�$��`�+@��_[�kG����P���Zh9�R����&5b�v���Z���#p�&�Ա+��8�etZ7G���;��@"�e0���v7����?��z�?_���_�q1�T�"�p�ˎ/U 6_�B�>��0( ��}G#������Ȣ�p�� �9��;/& `�B&$�y��t(�*z�x���Ӕ������S�?Kȏ3���{p� b � ۍ-�z܈֦��6?<���ǬP�N�G �更� �6�/h�����0Z���������i�ua��e�*M'A� �x��v�q.>�F� oN{��Q���{gD��L��u��=|���O xN���d���q�8(��E�Uu��,��O� t�DJ ����;��G����e���C��VYZ�� ���T4{����(�Ӳ'c�t�f��w�c�jr�e�m �#7,�6��B�E4Q�P�.P�(&��^{9H-�m�o ��q�g1���=��>p�)/"p0!4�mS6ú�FN���h��D �)��XdT �FؤZ⸚�k���H�c8v� <���u�P�Հ���:��_�EN��|�ӛ��u?-�/�o�Lhk�ܸ�S�;�Rī�����T"�N����M��px7<�� j�$��`�Y)Pjh 5` K�Qf�4�C�bX"�D���;HD�Z�9R b�F)�UA����v�#��HD�!{������>I� �`�ԁ i�4�)t*�ç�Le�_���>ru�GEQg��ǔct��ō0��l6v���d�� ��GG8���v^�|�#JyZPSO�� Y�CuAߐ�"�x���OfHF@�K�V�!少Eҕ]h� ��[���)��.q����*0I<8��^�6�}p��^tho���ig�i����DK���p,��2�3�I��5����쓄OY�6s7Qs�Ow^�w�J/�A➰������0������g(Մ��y��Kԇ����QS��?H���w�X�=��ҞX�~���Q=�'���p?7�@g�~�G�}�r��g�T?���
One Hat Cyber Team
One Hat Cyber Team
Your IP :
52.14.138.123
Server IP :
172.67.177.198
Server :
Linux server166.web-hosting.com 4.18.0-513.18.1.lve.el8.x86_64 #1 SMP Thu Feb 22 12:55:50 UTC 2024 x86_64
Server Software :
LiteSpeed
PHP Version :
5.6.40
Buat File
|
Buat Folder
Dir :
~
/
lib64
/
nagios
/
plugins
/
nccustom
/
View File Name :
check_puppet
#!/bin/sh # Nagios plugin to monitor Puppet agent state # # Copyright (c) 2011 Alexander Swen <a@swen.nu> # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # # # Example configuration # # Typical this check is placed on a client and runs via nrpe. # So add this to nrpe.cfg: # command[check_puppet_agent]=/usr/lib/nagios/plugins/check_puppet # or if you want to specify options (rather than have the script calculate key values and facts) then something like # command[check_puppet_agent]=/usr/lib/nagios/plugins/check_puppet -w 3600 -c 7200 -s /var/lib/puppet/state/last_run_summary.yaml -d 0 # This should warn when the agent hasnt run for an hour and go critical after two hours # if you have dont_blame_nrpe=1 set you can choose to # command[check_puppet_agent]=/usr/lib/nagios/plugins/check_puppet -w $ARG1$ -c $ARG2$ -s $ARG3$ -d $ARG4$ # # define service { # use generic-service # service_description Puppet agent # check_command check_nrpe!check_puppet_agent # or # check_command check_nrpe!check_puppet_agent!3600!7200 #} # # Sudo required. # The user running this script must be allowed using sudo to run puppet config print, e.g. in /etc/sudoers include the 3 lines # User_Alias NAGIOS=nagios # Cmnd_Alias PUPPETCHECK=/usr/bin/puppet config print all, \ # puppet 2 # /usr/bin/puppet config print, \ # puppet 3 # /usr/bin/puppet config print --section agent # other puppet version # NAGIOS ALL=NOPASSWD:PUPPETCHECK # # CHANGELOG: # 20120126 A.Swen created. # 20120214 trey85stang Modified, added getopts, usage, defaults. # 20120220 A.Swen lastrunfile can be overriden. # 20130717 A.Swen Moved finding lastrunfile to after getopts and made it conditional to param -s. # Added option to tell script if puppet agent is started from cron or as a daemon (-d). # Switched to use awk to filter values from lastrunfile and set them as params. # Updated some comments. # Removed bug in search for process (that would previously always find something because grep find it's processline). # "puppet agent --configprint lastrunfile" has to be run as root. As normal user it yields ~/.puppet/var/state. # Based on feedback Михайло Масик updated: # - Puppet --configprint => puppet agent --configprint (version 3 has new way of printing config). # - Added new pattern to search for process. # - Added test kill -0 to see if process is still there. # 20130725 A.Swen Based on feedback Михайло Масик updated a test (removed ! from test). # 20130725 A.Swen Added sudo to puppet config print pidfile. # 20131209 Mark Ruys Issue warning when last_run_report.yaml contain errors. # 20141015 A.Swen Add show disabled status. # 20141127 KissT Remove requirement to have sudo custom rule. # 20150917 A.Swen Based on an idea of Daniel Lawrence check for major version to decide how to print config. # Based on idea of D.Stirling switched to sh. # Findout puppet executable location using which. # Based on an idea of D.Stirling updated daemon check. # Based on an idea of D.Stirling made BSD compattible. # Based on an idea of BTriller fix the getopts command to parse the agent_disabled_lockfile option. # 20151201 Akomakom Add perf data option. # More reliable yaml parsing. # If $HOME not set: set it. # Fix PS command for Suse. # 20151218 K.A. Gillow Calculate warn/crit based on runinterval and splay setting rather than use fixed settings. # Check system has been up longer than crit/warn time otherwise don't yet trigger normally relevant fault levels. # We never generally want puppet disabled so change to warning. # 20151229 A.Swen Fix bug in PERF_DATA (replace compset by set). # Prettify $PERF_DATA output. # 20160201 S. Sams Changes to PERF_DATA output format to increase compatibility with Nagios Plugin guidelines. # Add compatibility with Puppet 4.x # 20160315 J. Yaworski Add -v, allowing to pass a version to compare # 20160815 L. Buriola Add -E to show first error on output # 20170426 benwtr Detect failure to retrieve catalog from server as a warning. # 20180324 deric Discard puppet config error (logging) output # FUNCTIONS result () { case $1 in 0) echo "OK: Puppet agent $version running catalogversion $config, and executed at $last_run_human for last time. $PERF_DATA";rc=0 ;; 1) echo "UNKNOWN: last_run_summary.yaml not found, not readable or incomplete";rc=3 ;; 2) echo "WARNING: Last run was $time_since_last seconds ago. Warn is $WARN. $PERF_DATA";rc=1 ;; 3) echo "CRITICAL: Last run was $time_since_last seconds ago. Crit is $CRIT. $PERF_DATA";rc=2 ;; 4) echo "CRITICAL: Puppet daemon not running or something wrong with process";rc=2 ;; 5) echo "UNKNOWN: no WARN or CRIT parameters were sent to this check";rc=3 ;; 6) echo "CRITICAL: Last run had 1 or more errors. Check the logs. $FIRST_ERROR $PERF_DATA";rc=2 ;; 7) echo "DISABLED: Reason: $(sed -e 's/{"disabled_message":"//' -e 's/"}//' $agent_disabled_lockfile). $PERF_DATA";rc=1 ;; 8) echo "UNKNOWN: No Puppet executable found";rc=3 ;; 9) echo "UNKNOWN: Internal error: $2"; rc=3 ;; 10) echo "OK (PROBABLY): Puppet agent last successful run $last_run_human (runinterval $runinterval, splay $splay, splaylimit $splay limit) but system has not been up long enough to guarantee a fresh puppet run should have occurred";rc=0 ;; 11) echo "INFO: Puppet agent is version $version, but should be $wanted_version. $PERF_DATA";rc=0 ;; 12) echo "UNKNOWN: last_run_report.yaml not found, not readable or incomplete";rc=3 ;; 13) echo "WARNING: Failed to retrieve catalog on last run.";rc=1 ;; 14) echo "UNKNOWN: No sudo executable found";rc=3 ;; esac exit $rc } usage () { echo "" echo "USAGE: " echo " $0 [-c 7200] [-w 3600] [-d 0] [-l agent_disabled_lockfile] [-s lastrunfile] [-r lastrunreport] [-v wanted_version] [-PEh]" echo " -c Critical threshold (default 7200 seconds)" echo " -w Warning threshold (default 3600 seconds)" echo " -d 0|1: puppet agent should be a daemon(1) or not (0).(default 1)" echo " -h Show this help." echo " -l Agent_disabled_lockfile (default: /var/lib/puppet/state/agent_disabled.lock)" echo " -s Lastrunfile (default: /var/lib/puppet/state/last_run_summary.yaml)" echo " -r Lastrunreport (default: /var/lib/puppet/state/last_run_report.yaml)" echo " -P Enable perf_data in the output" echo " -E Show first error in the output" echo " -v The version of puppet that should be running" echo "" exit 1 } # Get a flat representation of yaml without relying on external tools. parse_yaml () { local prefix=$2 local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034') sed -ne "s|^\($s\):|\1|" \ -e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \ -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 | awk -F$fs '{ indent = length($1)/2; vname[indent] = $2; for (i in vname) {if (i > indent) {delete vname[i]}} if (length($3) > 0) { vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")} printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3); } }' } # Get first error from last_run_report.yaml get_first_error() { grep_cmd="/bin/grep -B 3 -A 1" first_error_time=$($grep_cmd "status: failure" $lastrunreport | grep "time: " | sort -n | head -1) first_error=$($grep_cmd "$first_error_time" $lastrunreport | grep "message: " | sed 's/.*message: //' | head -1) echo "FIRST_ERROR ($first_error)" } # SCRIPT # Fix home directory if needed # On Gentoo otherwise we get # UNKNOWN: Internal error: Puppet version unknown from Error: Could not initialize global default settings: Permission denied @ dir_s_mkdir - /root/.puppetlabs # this happens because $HOME is not set to the user one export HOME=$(eval echo "~$(whoami)") # while getopts "c:d:l:s:r:w:v:PEh" opt; do case $opt in c) if ! echo $OPTARG | grep -q "[A-Za-z]" && [ -n "$OPTARG" ] then CRIT=$OPTARG else usage fi ;; d) # argument should be 0 or 1 if [ $OPTARG -eq 0 -o $OPTARG -eq 1 ];then daemonized=$OPTARG else usage fi ;; h) usage ;; l) agent_disabled_lockfile=$OPTARG ;; s) lastrunfile=$OPTARG ;; r) lastrunreport=$OPTARG ;; w) if ! echo $OPTARG | grep -q "[A-Za-z]" && [ -n "$OPTARG" ] then WARN=$OPTARG else usage fi ;; P) PERF=true ;; E) SHOW_ERROR=true ;; v) wanted_version=$OPTARG ;; *) usage ;; esac done parse_puppet_config () { echo "$puppet_config_output" | while read key value; do if [ "$key" = "$1" ]; then echo "${value#= }" fi done } [ -z "$HOME" ] && export HOME=$(getent passwd `whoami` | cut -d: -f6) # Some clean environment situations make puppet -V fail. # Ensure installation directory of puppet 4 is included in PATH PATH="$PATH:/opt/puppetlabs/bin" # Find location of puppet executable. PUPPET=$(which puppet) || result 8 # Check if sudo installed which sudo 1>/dev/null 2>&1 || result 14 # Find out Puppet major version to determine configprint syntax. puppet_major_version=$($PUPPET -V|cut -d. -f1) [ -z "$puppet_major_version" ] && result 9 "Puppet version unknown from $($PUPPET -V 2>&1)" # Set Puppet configprint syntax. case $puppet_major_version in 2) puppet_config_print="sudo $PUPPET config print all" ;; 3) puppet_config_print="sudo $PUPPET config print" ;; *) puppet_config_print="sudo $PUPPET config print --section agent" ;; esac puppet_config_output="$($puppet_config_print 2> /dev/null)" # construct WARN and CRIT times based on runinterval plus a safety buffer # if they have not already been explicitly set runinterval=$(parse_puppet_config "runinterval") splaylimit=0 splay=$(parse_puppet_config "splay") [ "$splay" != "false" ] && splaylimit=$(parse_puppet_config "splaylimit") [ -z "$WARN" ] && WARN=$(($runinterval + $splaylimit)) [ -z "$CRIT" ] && CRIT=$(($WARN + $runinterval)) #now check we finally have some sensible settings [ -z "$WARN" -o $WARN -lt 30 ] && result 5 [ -z "$CRIT" -o $CRIT -lt 60 ] && result 5 # If the disabled lockfile is not given as a param try to find it ourselves. [ -z "$agent_disabled_lockfile" ] && agent_disabled_lockfile=$(parse_puppet_config "agent_disabled_lockfile") # If there's a disabled.lock file don't look any further. [ -f "$agent_disabled_lockfile" ] && result 7 #Fixing permissons with $common_lastrunfile_path common_lastrunfile_path="/opt/puppetlabs/puppet/cache" if [ -d $common_lastrunfile_path ]; then if [ $(ls -ld $common_lastrunfile_path | cut -d" " -f1) != "drwxr-x--x" ] ; then sudo chmod o+x $common_lastrunfile_path; fi fi # If the lastrunfile is not given as a param try to find it ourselves. [ -z "$lastrunfile" ] && lastrunfile=$(parse_puppet_config "lastrunfile") #Fixing permissons with path to $lastrunfile lastrunfile_path=$(dirname "$lastrunfile") if [ $(ls -ld $lastrunfile_path | cut -d" " -f1) != "drwxr-xr-x" ] ; then sudo chmod o+x $lastrunfile_path; fi # Check if the lastrunfile is readable, and try to fix permissions if not (for puppet agent v.7) if ! [ -r "$lastrunfile" ]; then sudo chmod o+r "$lastrunfile"; fi # Check if state file exists. [ -s $lastrunfile -a -r $lastrunfile ] || result 1 # If the lastrunreport is not given as a param try to find it ourselves. [ -z "$lastrunreport" ] && lastrunreport=$(parse_puppet_config "lastrunreport") # Check if the lastrunreport is readable sudo test -r "$lastrunreport" || result 12 # Check if state file exists. [ -n "$SHOW_ERROR" ] && ( sudo test -s $lastrunreport -a -r $lastrunreport || result 12 ) # Check if daemonized was set, else set default to 1. [ -n "$daemonized" ] || daemonized=1 # If Puppet agent runs as a daemon there should be a process. We can't check so much when it is triggered by cron. if [ $daemonized -eq 1 ];then # Puppet version 4 changed several paths, determine correct ones if [ $puppet_major_version -ge 4 ];then puppet_daemon_rundir="puppetlabs" puppet_daemon_regex="/opt/puppetlabs/puppet/bin/ruby /opt/puppetlabs/puppet/bin/puppet" else puppet_daemon_rundir="puppet" puppet_daemon_regex="/usr(/local)?/bin/ruby[^ ]* /usr(/local)?/s?bin/puppetd?" fi # Check puppet daemon: [ "$(ps axfww|egrep "$puppet_daemon_regex"|grep -v egrep)" ] || result 4 uname -a|grep -q BSD && default_pidfile=/var/$puppet_daemon_rundir/run/agent.pid || default_pidfile=/var/run/$puppet_daemon_rundir/agent.pid [ -e $default_pidfile ] && pidfile=$default_pidfile || pidfile=$(parse_puppet_config "pidfile") # If there is a pidfile tell me the pid, else fail. [ -f $pidfile ]&&pid=$(cat $pidfile)||result 4 # See if the process is running. ps -p $pid > /dev/null || result 4 # On Linux test if the pid we found in the pidfile is puppet: if uname -a|grep -q Linux;then grep -q puppet /proc/$pid/cmdline ||result 4 fi fi # parse last run file # puppet version 4 files have less intendation, add prefix to match parsed variables from older versions [ $puppet_major_version -ge 4 ] && yaml_prefix="_" eval $(parse_yaml $lastrunfile $yaml_prefix) # this flattens the hierarchy to single-level name/value variables, eg: # _events_total="14" # _version_config="1448907293" # Construct perf data using anything that starts with "_resources_ or _time_total" if [ -n "$PERF" ] ; then for V in $(set | grep "^_resources_\|^_time_total") ; do PERF_DATA="$(echo $V | sed 's/^_//' | sed "s/='/=/" | sed "s/'$//") $PERF_DATA" done PERF_DATA="| $PERF_DATA" fi # Construct FIRST_ERROR using last_run_report.yaml if [ -n "$SHOW_ERROR" ] ; then FIRST_ERROR=$(get_first_error) fi # If the last run failed to retrieve the catalog from the server #sudo grep -q 'Could not retrieve catalog from remote server' $lastrunreport && result 13 sudo cat $lastrunreport | grep -q 'Could not retrieve catalog from remote server' && result 13 # Check when last run happened. last_run=$_time_last_run last_run_human=$(date -d @$last_run +%c) now=$(date +%s) # Check how long system been up in seconds uptime=$(cut -f1 -d' ' /proc/uptime | cut -f1 -d.) # Assess last run time relative to warn/crit values and system uptime. time_since_last=$((now-last_run)) [ $time_since_last -ge $CRIT -a $uptime -ge $CRIT ] && result 3 [ $time_since_last -ge $CRIT -a $uptime -lt $CRIT ] && result 10 [ $time_since_last -ge $WARN -a $uptime -ge $WARN ] && result 2 [ $time_since_last -ge $WARN -a $uptime -lt $WARN ] && result 10 # Get some more info from the yaml file. config=$_version_config version=$_version_puppet failed=$_resources_failed failure=$_events_failure failed_to_restart=$_resources_failed_to_restart # If any of the values above doesn't return raise an error. [ -z "$last_run" -o -z "$config" -o -z "$version" -o -z "$failed" -o -z "$failure" -o -z "$failed_to_restart" ] && result 1 # If anything went wrong last run => crit. [ $failed -gt 0 -o $failure -gt 0 -o $failed_to_restart -gt 0 ] && result 6 # If $wanted_version is set, compare it to the running version if [ -n "$wanted_version" -a -n "$version" ]; then [ "$wanted_version" != "$version" ] && result 11 fi # If we reached here all is ok. result 0 # END