├── .gitignore ├── LICENSE ├── README.md ├── check_rancher.pl ├── mrtg └── example.cfg ├── nagios ├── example.cfg └── myenv.cfg └── rancher.cfg /.gitignore: -------------------------------------------------------------------------------- 1 | /blib/ 2 | /.build/ 3 | _build/ 4 | cover_db/ 5 | inc/ 6 | Build 7 | !Build/ 8 | Build.bat 9 | .last_cover_stats 10 | /Makefile 11 | /Makefile.old 12 | /MANIFEST.bak 13 | /META.yml 14 | /META.json 15 | /MYMETA.* 16 | nytprof.out 17 | /pm_to_blib 18 | *.o 19 | *.bs 20 | /_eumm/ 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | 341 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # check_rancher 2 | Nagios/MRTG plugin for checking Rancher API 3 | 4 | To use this, you should first set up an API User and Key for the Environment 5 | that you wish to test. Place this information in a configuration file that 6 | can be read by the script. 7 | 8 | Example configurations for both Nagios and MRTG are in the directory. 9 | 10 | You can run separate checks for cpu/mem/swap/load/disk/certificates or you 11 | can group them together by Environment. 12 | 13 | Stacks may be tested individually. 14 | 15 | If you have problems, try running from the commandline using '-d' for debug 16 | mode, which gives you more information. Make sure your API user has access to 17 | the Environment you are testing, and make sure your monitoring host can 18 | connect to the API port. Remember to set the SSL option if you have SSL on 19 | the API (which is a good idea). 20 | 21 | I would suggest treating the entire Environment as a single Nagios host, rather 22 | than having a separate object for each Environment host. 23 | 24 | Default thresholds can be set in the config file (if you use one); you can 25 | override these on a per-Host basis using Labels like: nagios.cpu.warn=80 26 | 27 | Usage: check_rancher [-N|-M][-d][-h] 28 | [-c configfile] 29 | [-H host][-p port][-S][-U user -K key] 30 | [-t timeout][-T globaltimeout] 31 | [-E environment][-s stack] 32 | [-i itemlist] 33 | 34 | -d : debug 35 | -M : MRTG mode 36 | -N : Nagios mode 37 | -S : Use SSL 38 | -E : Rancher environment 39 | -s : Rancher stack 40 | -c : Specify configuration file 41 | -i : Comma-separated list of metric items to check. Can include: 42 | certificates,cpu,memory,disk,swap 43 | This only applies to Environment checks. 44 | -------------------------------------------------------------------------------- /check_rancher.pl: -------------------------------------------------------------------------------- 1 | #! /usr/bin/perl 2 | # vim:ts=4 3 | # 4 | # Check the Rancher Docker cluster for Nagios/MRTG 5 | # 6 | # Syntax: check_rancher [-M|-N] [-d] [-h] 7 | # [-c configfile] 8 | # [-H hostname][-p port][-S][-U user -K key] 9 | # [-T globaltimeout][-t fetchtimeout] 10 | # [-E environment][-s stack] 11 | # [-t itemlist] 12 | # 13 | 14 | use strict; 15 | use LWP::UserAgent; 16 | use Getopt::Long; 17 | use CGI qw( escapeHTML ); 18 | use JSON; 19 | use Data::Dumper; 20 | #use Time::HiRes qw( usleep ualarm gettimeofday tv_interval ); 21 | use Date::Parse; 22 | 23 | my( $VERSION ) = "0.1"; 24 | 25 | my( $MRTG ) = 0; # MRTG or Nagios mode 26 | my( $TIME ) = -1; 27 | my( $MESSAGE ) = ""; 28 | my( $PERFSTATS ) = ""; 29 | my( $STATUS ) = 0; 30 | my( $A, $B ) = ('U','U'); 31 | my( $TIMEOUT ) = 10; #seconds 32 | my( $GTIMEOUT ) = 20; #seconds 33 | my( $USERNAME, $PASSWORD ) = ('',''); 34 | my( $LOGFILE ) = "/tmp/check.log"; 35 | my( $DEBUG ) = 0; 36 | my( $ENV,$STACK ) = ('',''); 37 | my( $HOSTNAME, $PORT, $SSL ) = ('localhost',80,0); 38 | my( $ENDPOINT ) = ""; 39 | my( $URL ); 40 | my( $ITEMS ) = "cert,cpu,mem,disk,swap"; 41 | 42 | my( %config ) = ( 43 | 'cpu.warn' => 80, #percent used 44 | 'cpu.crit' => 90, 45 | 'mem.warn' => 90, #percent used 46 | 'mem.crit' => 99, 47 | 'disk.warn' => 80, #percent used 48 | 'disk.crit' => 90, 49 | 'load.warn' => 50, # 5min load average 50 | 'load.crit' => 100, 51 | 'swap.warn' => 1, # pages 52 | 'swap.crit' => 10000, 53 | 'cert.warn' => 7, # days remaining 54 | 'cert.crit' => 1, 55 | ); 56 | 57 | use vars qw/$opt_i $opt_h $opt_d $opt_M $opt_N $opt_H $opt_c $opt_U $opt_K $opt_T $opt_t $opt_E $opt_S $opt_s $opt_p $opt_o $opt_f/; 58 | my( $ua ); 59 | my( $res, $req ) = ('',''); 60 | my($json,$content); 61 | my($starttime); 62 | #################################################################### 63 | # get credentials 64 | sub LWP::UserAgent::get_basic_credentials { 65 | my ($self, $realm, $url, $isproxy) = @_; 66 | print "Returning u=$USERNAME,p=$PASSWORD\n" if($DEBUG); 67 | return $USERNAME,$PASSWORD; 68 | } 69 | ################################################################ 70 | sub escape($) { 71 | my($x) = $_[0]; 72 | $x=~s/([^a-zA-Z0-9_.-])/uc sprintf("&#x%02x;",ord($1))/eg; 73 | return $x; 74 | } 75 | 76 | sub output { 77 | if($MRTG) { 78 | $MESSAGE =~ s/\\n.*//; 79 | print "$A\n$B\n\n$MESSAGE\n"; 80 | exit $STATUS; 81 | } 82 | 83 | if(!$MESSAGE) { 84 | $MESSAGE = "Status: $STATUS"; 85 | } 86 | print "$MESSAGE"; 87 | print "|$PERFSTATS" if($PERFSTATS); 88 | print "\n"; 89 | exit $STATUS; 90 | } 91 | #################################################################### 92 | # Fetching 93 | 94 | sub fetchurl($$) { 95 | my($url,$p) = @_; 96 | 97 | # Create a request 98 | print "Fetching: $url\n" if($DEBUG); 99 | if($p) { 100 | $req = HTTP::Request->new(POST=>$url); 101 | $req->content($p); 102 | } else { 103 | $req = HTTP::Request->new(GET=>$url); 104 | } 105 | $req->content_type('application/json'); 106 | $req->header("Accept"=>"application/json"); 107 | $req->authorization_basic($USERNAME,$PASSWORD); 108 | 109 | # Pass request to the user agent and get a response back 110 | $url =~ s/ /+/g; 111 | print "--> Retrieving $url ".(($p and (length($p)<40))?"($p)":"")."\n" 112 | if($DEBUG); 113 | $res = $ua->request($req); 114 | 115 | if(!$res) { 116 | $MESSAGE = "API Failure: No response."; 117 | if($ENV) { 118 | $STATUS = 3; 119 | } else { 120 | $STATUS = 2; 121 | } 122 | output; 123 | } 124 | print "--> Done. (".$res->code.")\n" if($DEBUG); 125 | 126 | # Check the outcome of the response 127 | if($DEBUG) { 128 | open LOG, ">>$LOGFILE"; 129 | print LOG "-------------------------------------------------------------------------\n$url\n$p\n".$res->status_line."\n".$res->content."\n"; 130 | close LOG; 131 | } 132 | if (!$res->is_success) { 133 | print "See logfile $LOGFILE for content\n" if($DEBUG); 134 | $MESSAGE = "API Error: ".$res->status_line; 135 | } 136 | 137 | return $res->content; 138 | } 139 | 140 | sub dohelp() { 141 | print "Usage: check_rancher [-N]|-M][-d][-h]\n [-c configfile]\n [-H host][-p port][-S][-U user -K key]\n [-t timeout][-T globaltimeout]\n [-E environment [-s stack|-o hostobject]]\n [-i itemlist]"; 142 | print "-d : debug\n"; 143 | print "-M : MRTG mode\n"; 144 | print "-N : Nagios mode\n"; 145 | print "-H : Specify Rancher server hostname/IP\n"; 146 | print "-p : Specify Rancher API port (default 80)\n"; 147 | print "-S : Use SSL\n"; 148 | print "-E : Rancher environment\n"; 149 | print "-s : Rancher stack\n"; 150 | print "-c : Specify configuration file\n"; 151 | print "-i : Comma-separated list of metric items to check. Can include:\n"; 152 | print " certificates,cpu,memory,disk,swap\n"; 153 | print " This only applies to Environment checks.\n"; 154 | print "-o : Specify host object. This is used by MRTG mode.\n"; 155 | exit 3; 156 | } 157 | 158 | sub readconfig($) { 159 | my($file) = $_[0]; 160 | if(! -r $file) { 161 | $MESSAGE = "Unable to read $file"; 162 | $STATUS = 3; 163 | output; 164 | } 165 | print "Reading config from $file\n" if($DEBUG); 166 | open CFG,"<$file" or do { 167 | $MESSAGE = "Unable to read $file"; 168 | $STATUS = 3; 169 | output; 170 | }; 171 | while ( ) { 172 | next if( /^\s*#/ ); 173 | next if( /^\s*$/ ); 174 | chomp; 175 | if( /^\s*(\S+)\s*=\s*(.*)/ ) { 176 | $config{lc $1} = $2; 177 | print "$1 = $2\n" if($DEBUG); 178 | } else { 179 | print "Bad config line: $_\n" if($DEBUG); 180 | } 181 | } 182 | close CFG; 183 | 184 | $HOSTNAME = $config{hostname} if(defined $config{hostname}); 185 | $PORT = $config{port} if(defined $config{port}); 186 | $USERNAME = $config{username} if(defined $config{username}); 187 | $PASSWORD = $config{key} if(defined $config{key}); 188 | $ENV = $config{environment} if(defined $config{environment}); 189 | $SSL = $config{ssl} if(defined $config{ssl}); 190 | $STACK = $config{stack} if(defined $config{stack}); 191 | } 192 | 193 | ######################################################################## 194 | sub getthresh($$) { 195 | my($type) = lc $_[0]; 196 | my($obj) = $_[1]; 197 | my($warn,$crit)=(-1,-1); 198 | 199 | # Defaults as in config 200 | $warn = $config{"$type.warn"} if(defined $config{"$type.warn"}); 201 | $crit = $config{"$type.crit"} if(defined $config{"$type.crit"}); 202 | 203 | # Any override in the labels? 204 | if($obj and $obj->{labels}) { 205 | $warn = $obj->{labels}{"nagios.$type.warn"} 206 | if(defined $obj->{labels}{"nagios.$type.warn"}); 207 | $crit = $obj->{labels}{"nagios.$type.crit"} 208 | if(defined $obj->{labels}{"nagios.$type.crit"}); 209 | } 210 | 211 | return ($warn,$crit); 212 | } 213 | 214 | ######################################################################## 215 | sub checkenv($$) { 216 | my( $data ) = $_[0]; 217 | my( $host ) = $_[1]; 218 | my( $envid ) = $data->{id}; 219 | my($json,$url); 220 | my( $w, $c ); 221 | my( $totcpu, $totmem, $numhosts ) = (0,0); 222 | 223 | $STATUS = 0; 224 | $MESSAGE = ""; 225 | 226 | print "-- Checking status\n" if($DEBUG); 227 | 228 | if( $data->{state} ne "active" ) { 229 | if( $data->{state} =~ /activating|registering|requested|updating/ ) { 230 | $STATUS = 1; 231 | } else { $STATUS = 2; } 232 | $MESSAGE = "Environment status: ".$data->{state}; 233 | return; 234 | } 235 | 236 | print "-- Checking hosts\n" if($DEBUG); 237 | $MESSAGE = "Environment status: ".$data->{state}; 238 | # Retrieve hosts data 239 | $url = "$ENDPOINT/projects/$envid/hosts/"; 240 | $json = decode_json( fetchurl( $url, '' ) ); 241 | if(!$json) { 242 | $STATUS = 3; $MESSAGE = "API error"; return; 243 | } 244 | 245 | # Threshold host CPU/MEM/Disk 246 | foreach my $idx ( 0..$#{$json->{data}} ) { 247 | my $state = $json->{data}[$idx]{state}; 248 | my $name = $json->{data}[$idx]{name}; 249 | my $v; 250 | 251 | next if($state eq "inactive"); # skip inactive hosts 252 | next if($host and ($name ne $host)); # selected host only 253 | 254 | # Check attributes of host 255 | my $info = $json->{data}[$idx]{info}; 256 | $numhosts += 1; 257 | 258 | if($ITEMS =~ /cpu/) { 259 | # CPU usage threshold; take avg of all cores 260 | ($w,$c) = getthresh("cpu",$json->{data}[$idx]); 261 | $v = 0; 262 | foreach ( @{$info->{cpuInfo}{cpuCoresPercentages}} ) { 263 | $v += $_; 264 | } 265 | $v /= $info->{cpuInfo}{count}; 266 | $totcpu += $v; 267 | $v = (int($v*100))/100; 268 | if(!$MRTG) { 269 | if( $v >= $c ) { 270 | $MESSAGE .= "\\nCRIT: Host $name: CPU $v\%"; 271 | $STATUS = 2; 272 | } elsif( $v >= $w ) { 273 | $MESSAGE .= "\\nWARN: Host $name: CPU $v\%"; 274 | $STATUS = 1 if(!$STATUS); 275 | } 276 | } 277 | if($host) { 278 | $PERFSTATS .= "cpu=$v\%;$w;$c;0;100 "; 279 | } else { 280 | $PERFSTATS .= "cpu$name=$v\%;$w;$c;0;100 "; 281 | } 282 | if($DEBUG) { print "Host $name: CPU = $v\%\n"; } 283 | } 284 | if($ITEMS =~ /mem/) { 285 | # MEM usage threshold; use % 286 | ($w,$c) = getthresh("mem",$json->{data}[$idx]); 287 | $v = 100.0 - (($info->{memoryInfo}{memFree}/$info->{memoryInfo}{memTotal})*100.0); 288 | $totmem += $v; 289 | $v = (int($v*100))/100; 290 | if(!$MRTG) { 291 | if( $v >= $c ) { 292 | $MESSAGE .= "\\nCRIT: Host $name: Memory $v\%"; 293 | $STATUS = 2; 294 | } elsif( $v >= $w ) { 295 | $MESSAGE .= "\\nWARN: Host $name: Memory $v\%"; 296 | $STATUS = 1 if(!$STATUS); 297 | } 298 | } 299 | if($host) { 300 | $PERFSTATS .= "mem=$v\%;$w;$c;0;100 "; 301 | } else { 302 | $PERFSTATS .= "mem$name=$v\%;$w;$c;0;100 "; 303 | } 304 | if($DEBUG) { print "Host $name: Memory = $v\%\n"; } 305 | } 306 | if($ITEMS =~ /load/ ) { 307 | # loadAvg 5min threshold 308 | ($w,$c) = getthresh("load",$json->{data}[$idx]); 309 | $v = $info->{cpuInfo}{loadAvg}[1]; 310 | if(!$MRTG) { 311 | if( $v >= $c ) { 312 | $MESSAGE .= "\\nCRIT: Host $name: LoadAvg $v"; 313 | $STATUS = 2; 314 | } elsif( $v >= $w ) { 315 | $MESSAGE .= "\\nWARN: Host $name: LoadAvg $v"; 316 | $STATUS = 1 if(!$STATUS); 317 | } 318 | } 319 | if($host) { 320 | $A = $v; $B = 'U'; 321 | $PERFSTATS .= "load=$v;$w;$c;0; "; 322 | } else { 323 | $PERFSTATS .= "load$name=$v;$w;$c;0; "; 324 | } 325 | if($DEBUG) { print "Host $name: LoadAvg = $v\n"; } 326 | } 327 | if($ITEMS =~ /swap/ and !$MRTG) { 328 | # swap threshold 329 | ($w,$c) = getthresh("swap",$json->{data}[$idx]); 330 | } 331 | if($ITEMS =~ /disk/ and !$MRTG) { 332 | my(@patterns,$exclude); 333 | my($diskprob) = 0; 334 | # Disk thresholds; use % on each disk 335 | ($w,$c) = getthresh("disk",$json->{data}[$idx]); 336 | $exclude = $config{"disk.exclude"}; 337 | $exclude = $json->{data}[$idx]{labels}{"nagios.disk.exclude"} 338 | if(defined $json->{data}[$idx]{labels}{"nagios.disk.exclude"}); 339 | $exclude = "" if(!$exclude); 340 | @patterns = split( /\s*,\s*/,$exclude ); 341 | DISK: foreach my $disk ( keys %{$info->{diskInfo}{mountPoints}} ) { 342 | $v = $info->{diskInfo}{mountPoints}{$disk}{percentUsed}; 343 | foreach ( @patterns ) { 344 | next DISK if( $_ and $disk =~ /$_/ ); 345 | } 346 | if( $v >= $c ) { 347 | $MESSAGE .= "\\nCRIT: Host $name: $disk: Used $v\%"; 348 | $STATUS = 2; $diskprob = 1; 349 | } elsif( $v >= $w ) { 350 | $MESSAGE .= "\\nWARN: Host $name: $disk: Used $v\%"; 351 | $STATUS = 1 if(!$STATUS); 352 | $diskprob = 1; 353 | } 354 | if($DEBUG) { print "Host $name: $disk: Usage = $v\%\n"; } 355 | } 356 | #$MESSAGE .= "\\nAll disks on $name OK" if(!$diskprob); 357 | } 358 | } 359 | if( $numhosts > 0 ) { 360 | if($ITEMS =~ /cpu/) { 361 | $totcpu /= $numhosts; 362 | $A = $totcpu; 363 | $PERFSTATS = "allcpu=$totcpu\%;;;0;100 $PERFSTATS"; 364 | } 365 | if($ITEMS =~ /mem/) { 366 | $totmem /= $numhosts; 367 | $B = $totmem; 368 | $PERFSTATS = "allmem=$totmem\%;;;0;100 $PERFSTATS"; 369 | } 370 | } 371 | $PERFSTATS .= "hosts=$numhosts "; 372 | 373 | if($ITEMS =~ /cert/ and !$MRTG) { # meaningless in MRTG mode 374 | # Certificate thresholds 375 | ($w,$c) = getthresh("cert",undef); 376 | # retrieve all known certs 377 | $url = "$ENDPOINT/projects/$envid/certificates/"; 378 | $json = decode_json( fetchurl( $url, '' ) ); 379 | if(!$json) { 380 | $STATUS = 3; $MESSAGE = "API error"; return; 381 | } 382 | 383 | # loop through and test each expiry date 384 | foreach my $cert ( @{$json->{data}} ) { 385 | next if($cert->{type} ne "certificate"); 386 | next if($cert->{state} ne "active"); 387 | my($cn) = $cert->{CN}; 388 | my($expires) = str2time($cert->{expiresAt}); 389 | if($expires< time ) { 390 | $STATUS = 2; 391 | $MESSAGE .= "\\nCertificate $cn has expired!"; 392 | next; 393 | } 394 | my($daysleft) = ($expires-time)/(24*3600); 395 | if($daysleft <= $c ) { 396 | $STATUS = 2; 397 | $MESSAGE .= "\\nCertificate $cn expires in $daysleft days"; 398 | next; 399 | } elsif( $daysleft <= $w ) { 400 | $STATUS = 1 if(!$STATUS); 401 | $MESSAGE .= "\\nCertificate $cn expires in $daysleft days"; 402 | next; 403 | } 404 | } 405 | 406 | } 407 | 408 | $MESSAGE = "Environment OK" if(!$MESSAGE); 409 | } 410 | 411 | ######################################################################## 412 | sub checkstack($) { 413 | my( $data ) = $_[0]; 414 | my( $stkid ) = $data->{id}; 415 | my( $envid ) = $data->{accountId}; 416 | my($json,$url); 417 | my($cnt) = 0; 418 | 419 | $STATUS = 0; 420 | $MESSAGE = "Stack OK"; 421 | 422 | print "-- Checking stack status\n" if($DEBUG); 423 | 424 | if( $data->{state} ne "active" ) { 425 | $STATUS = 2; 426 | if( $data->{state} =~ /activating|cancel|upgrade|request|rolling-back/ ) { 427 | $STATUS = 1; 428 | } 429 | 430 | $MESSAGE = "Environment status: ".$data->{state}; 431 | if($STATUS==2) { $B = 0; } else { $B = 1; } 432 | return; 433 | } 434 | $MESSAGE = "Stack is ".$data->{state}; 435 | 436 | print "-- Checking stack services\n" if($DEBUG); 437 | 438 | # Retrieve svc data 439 | $url = "$ENDPOINT/projects/$envid/environments/$stkid/services/"; 440 | $json = decode_json( fetchurl( $url, '' ) ); 441 | if(!$json) { 442 | $STATUS = 3; $MESSAGE = "API error"; return; 443 | } 444 | 445 | # Check services 446 | foreach my $idx ( 0..$#{$json->{data}} ) { 447 | my $state = $json->{data}[$idx]{state}; 448 | my $name = $json->{data}[$idx]{name}; 449 | 450 | $cnt += $json->{data}[$idx]{scale}; 451 | $MESSAGE .= "\\n* $name : $state"; 452 | next if($state eq "active"); 453 | if( $state =~ /inactive|remove/ ) { $STATUS = 2; next; } 454 | next if($STATUS); 455 | if( $state =~ /activating|cancel|register|update|upgrade|rolling/ ) { 456 | $STATUS = 1; 457 | } 458 | } 459 | 460 | # MRTG counts. Not really meaningful for Stacks. 461 | $A = $cnt; 462 | if( $STATUS == 2 ) { $B = 0; } else { $B = 1; } 463 | } 464 | 465 | ######################################################################## 466 | # MAIN 467 | 468 | # process arguments: at least MRTG/Nagios mode, and warn/crit for Nagios 469 | $Getopt::Long::autoabbrev = 0; 470 | $Getopt::Long::ignorecase = 0; 471 | GetOptions('h|help','d|debug','M|mrtg|MRTG','N|Nagios|nagios', 472 | 'H|host|rancher_host=s','p|port=i','S|SSL|ssl', 473 | 'c|config|config_file=s','U|user|username=s', 474 | 'K|pass|password|key=s','t|timout=i','T|globaltimeout=i', 475 | 'E|env|environment=s','s|stack=s', 476 | 'i|items=s', 477 | 'o|obj|object=s','f|fs|filesystem|disk=s' 478 | ); 479 | dohelp() if($opt_h); 480 | $DEBUG=1 if($opt_d); 481 | readconfig($opt_c) if($opt_c); 482 | $DEBUG=1 if($opt_d); 483 | $MRTG = 0 if($opt_N); 484 | $MRTG = 1 if($opt_M); 485 | $USERNAME = $opt_U if($opt_U); 486 | $PASSWORD = $opt_K if($opt_K); 487 | $TIMEOUT = $opt_t if($opt_t); 488 | $GTIMEOUT = $opt_T if($opt_T); 489 | $PORT = $opt_p if($opt_p); 490 | $SSL = 1 if($PORT == 443); 491 | $SSL = $opt_S if(defined $opt_S); 492 | $ENV = $opt_E if($opt_E); 493 | $STACK = $opt_s if($opt_s); 494 | $ITEMS = $opt_i if($opt_i); 495 | 496 | #$starttime = [gettimeofday]; 497 | 498 | # Create and set up the useragent 499 | $ua = LWP::UserAgent->new; 500 | $ua->agent("check_rancher/$VERSION"); 501 | $ua->timeout($TIMEOUT) ; 502 | 503 | ########################################################### 504 | # First, get a list of Environments. 505 | # We also test the API at this point. 506 | # url/post/contenttype/desc/fatal 507 | $ENDPOINT = "http".($SSL?"s":"")."://$HOSTNAME:$PORT/v1"; 508 | $URL = "$ENDPOINT/projects/"; 509 | $content = fetchurl( $URL, '' ); 510 | $json = decode_json($content); 511 | 512 | if( !$content or !(ref $json) or !defined $json->{'type'} ) { 513 | if($ENV) { 514 | $STATUS = 3; 515 | } else { 516 | $STATUS = 2; 517 | } 518 | $MESSAGE = "No valid response form API."; 519 | output; 520 | } 521 | if($json->{type} eq "error" or !$res->is_success ) { 522 | if($ENV) { 523 | $STATUS = 3; 524 | $MESSAGE = "API Error: ".$json->{'message'}; 525 | } else { 526 | $STATUS = 1; 527 | $MESSAGE = "API is sane, but cannot access: ".$json->{'message'}; 528 | } 529 | output; 530 | } 531 | if(!defined $json->{data}) { 532 | $STATUS = 3; 533 | $STATUS = 0 if(!$ENV); 534 | $MESSAGE = "No environments defined"; 535 | output; 536 | } 537 | if(!$ENV) { # API test only 538 | $MESSAGE = "API Working Correctly (" 539 | .($#{$json->{data}}+1) 540 | ." environments available to this ID)"; 541 | $STATUS = 0; 542 | output; 543 | } 544 | 545 | #print Dumper($json) if($DEBUG); 546 | 547 | ###################################################### 548 | # Now we try to identify the environment 549 | 550 | my($envid) = 0; 551 | my($idx); 552 | foreach $idx ( 0..$#{$json->{data}} ) { 553 | if( $json->{data}[$idx]{name} eq $ENV ) { 554 | $envid = $json->{data}[$idx]{id}; 555 | last; 556 | } 557 | } 558 | if(!$envid) { 559 | if($STACK) { 560 | # Stack status unknown 561 | $STATUS = 3; 562 | $MESSAGE = "Unknown Environment '$ENV'"; 563 | } else { 564 | $STATUS = 2; 565 | $MESSAGE = "Environment '$ENV' not defined"; 566 | } 567 | output; 568 | } 569 | 570 | ###################################################### 571 | # Environment checks 572 | if(!$STACK) { 573 | checkenv($json->{data}[$idx],$opt_o); 574 | } else { 575 | $URL = "$ENDPOINT/projects/$envid/environments/"; 576 | $content = fetchurl( $URL, '' ); 577 | $json = decode_json($content); 578 | if(!$json or !(ref $json) or !defined $json->{data}) { 579 | $STATUS = 3; 580 | $MESSAGE = "Unexpected JSON returned"; 581 | output; 582 | } 583 | my($stk) = 0; 584 | foreach my $idx ( 0..$#{$json->{data}} ) { 585 | if( $json->{data}[$idx]{name} eq $STACK ) { 586 | $stk = $json->{data}[$idx]; # should pass hash, not just ID (frisbee23) 587 | last; 588 | } 589 | } 590 | if(!$stk) { 591 | $STATUS = 2; 592 | $MESSAGE = "Stack '$STACK' unknown in environment '$ENV'"; 593 | output; 594 | } 595 | checkstack($stk); 596 | } 597 | 598 | #if(tv_interval($starttime)>=$GTIMEOUT ) { 599 | # $STATUS = 3; 600 | # $MESSAGE = "Global timeout reached."; 601 | # output; 602 | #} 603 | 604 | # exit 605 | output; 606 | # NOT REACHED 607 | exit -1; 608 | -------------------------------------------------------------------------------- /mrtg/example.cfg: -------------------------------------------------------------------------------- 1 | # MRTG configuration file example 2 | 3 | 4 | # Graph % utilisation of CPU and Mem over whole environment 5 | Target[resource]: check_rancher.pl -M -c rancher.cfg -E Default -i cpu,mem 6 | Title[resource]: Resources Used 7 | MaxBytes[resource]: 100 8 | PageTop[resource]: null 9 | LegendI[resource]: cpu: 10 | LegendO[resource]: mem: 11 | Options[resource]: gauge growright nopercent 12 | Ylegend[resource]: percent 13 | ShortLegend[resource]: % 14 | Legend1[resource]: CPU used 15 | Legend2[resource]: Memory used 16 | Legend3[resource]: Peak CPU Used 17 | Legend4[resource]: Peak Memory Used 18 | SetEnv[resource]: MRTG_INT_DESCR="Resource" 19 | routers.cgi*Options[resource]: fixunit nototal nopercent 20 | routers.cgi*Icon[resource]: chip-sm.gif 21 | routers.cgi*InCompact[resource]: yes 22 | routers.cgi*InMenu[resource]: yes 23 | 24 | Target[host1]: check_rancher.pl -M -c rancher.cfg -E Default --obj host1 -i cpu,mem 25 | Title[host1]: Host1 Resources Used 26 | MaxBytes[host1]: 100 27 | PageTop[host1]: null 28 | LegendI[host1]: cpu: 29 | LegendO[host1]: mem: 30 | Options[host1]: gauge growright nopercent 31 | Ylegend[host1]: percent 32 | ShortLegend[host1]: % 33 | Legend1[host1]: CPU used 34 | Legend2[host1]: Memory used 35 | Legend3[host1]: Peak CPU Used 36 | Legend4[host1]: Peak Memory Used 37 | SetEnv[host1]: MRTG_INT_DESCR="Host1 Resource" 38 | routers.cgi*Options[host1]: fixunit nototal nopercent 39 | routers.cgi*Icon[host1]: chip-sm.gif 40 | routers.cgi*InCompact[host1]: yes 41 | routers.cgi*InMenu[host1]: yes 42 | 43 | # Graph load average for specific host 44 | Target[host1-load]: check_rancher.pl -M -c rancher.cfg -E Default --obj host1 -i load 45 | Title[host1-load]: Host1 Load Average 46 | MaxBytes[host1-load]: 1000 47 | PageTop[host1-load]: null 48 | LegendI[host1-load]: cpu: 49 | LegendO[host1-load]: mem: 50 | Options[host1-load]: gauge growright noo nopercent nomax 51 | Ylegend[host1-load]: Load Avg 52 | ShortLegend[host1-load]:   53 | Legend1[host1-load]: Load Average 54 | Legend3[host1-load]: Peak Load Avg 55 | SetEnv[host1-load]: MRTG_INT_DESCR="Host1 Loadavg" 56 | routers.cgi*Options[host1-load]: fixunit nototal nopercent 57 | routers.cgi*Icon[host1-load]: list-sm.gif 58 | routers.cgi*InCompact[host1-load]: no 59 | routers.cgi*InMenu[host1-load]: yes 60 | 61 | # Graph % utilisation of specific filesystem for specific host 62 | # Not yet working 63 | #Target[host1-load]: check_rancher.pl -M -c rancher.cfg -E Default --obj host1 --fs /dev/sda9 -i disk 64 | 65 | -------------------------------------------------------------------------------- /nagios/example.cfg: -------------------------------------------------------------------------------- 1 | # In these examples, we are assuming that the 2 | # $USER1$ holds the plugins directory, and 3 | # $USER2$ holds the location of the check_rancher config files 4 | # We have one per environment as you cant have a global one. 5 | # The Host, port, SSL, User and Key definitions are kept in the 6 | # config file so as to hide them from the commandline. 7 | 8 | # You can set thresholds for the checks in the config file, and by 9 | # using Rancher Tags on the Hosts. 10 | 11 | # Feel free to customise the check periods and intervals. 12 | 13 | # API test 14 | define command { 15 | command_name rancher_api 16 | command_line $USER1$/check_rancher -c $USER2$/default.cfg 17 | } 18 | 19 | # Environment test 20 | define command { 21 | command_name rancher_env 22 | command_line $USER1$/check_rancher -c $USER2$/$ARG1$.cfg -E $ARG1$ -i $ARG2$ 23 | } 24 | 25 | # Stack test 26 | define command { 27 | command_name rancher_stack 28 | command_line $USER1$/check_rancher -c $USER2$/$ARG1$.cfg -E $ARG1$ -s $ARG2$ 29 | } 30 | 31 | ############################################# 32 | define service { 33 | use generic-service 34 | service_description Rancher: API 35 | check_command rancher_api 36 | host_name rancherhost 37 | max_check_attempts 2 38 | normal_check_interval 1 39 | retry_check_interval 1 40 | } 41 | ############################################# 42 | define service { 43 | use generic-service 44 | service_description Rancher: myenv: Resources 45 | check_command rancher_env!myenv!cpu,mem,swap,load 46 | host_name rancherhost 47 | max_check_attempts 4 48 | normal_check_interval 5 49 | retry_check_interval 1 50 | } 51 | define servicedependency{ 52 | host_name %SHNAME% 53 | dependent_host_name %SHNAME% 54 | service_description Rancher: API 55 | dependent_service_description Rancher: myenv: Resources 56 | execution_failure_criteria u,c 57 | notification_failure_criteria u,c 58 | } 59 | define service { 60 | use generic-service 61 | service_description Rancher: myenv: Disk 62 | check_command rancher_env!myenv!disk 63 | host_name rancherhost 64 | max_check_attempts 2 65 | normal_check_interval 10 66 | retry_check_interval 5 67 | } 68 | define servicedependency{ 69 | host_name %SHNAME% 70 | dependent_host_name %SHNAME% 71 | service_description Rancher: API 72 | dependent_service_description Rancher: myenv: Disk 73 | execution_failure_criteria u,c 74 | notification_failure_criteria u,c 75 | } 76 | define service { 77 | use generic-service 78 | service_description Rancher: myenv: Certificates 79 | check_command rancher_env!myenv!cert 80 | host_name rancherhost 81 | max_check_attempts 2 82 | normal_check_interval 60 83 | retry_check_interval 60 84 | } 85 | define servicedependency{ 86 | host_name %SHNAME% 87 | dependent_host_name %SHNAME% 88 | service_description Rancher: API 89 | dependent_service_description Rancher: myenv: Certificates 90 | execution_failure_criteria u,c 91 | notification_failure_criteria u,c 92 | } 93 | ############################################# 94 | define service { 95 | use generic-service 96 | service_description Rancher: myenv: mystack 97 | check_command rancher_stack!myenv!mystack 98 | host_name rancherhost 99 | max_check_attempts 2 100 | normal_check_interval 5 101 | retry_check_interval 4 102 | } 103 | define servicedependency{ 104 | host_name %SHNAME% 105 | dependent_host_name %SHNAME% 106 | service_description Rancher: API 107 | dependent_service_description Rancher: myenv: mystack 108 | execution_failure_criteria u,c 109 | notification_failure_criteria u,c 110 | } 111 | ############################################# 112 | 113 | -------------------------------------------------------------------------------- /nagios/myenv.cfg: -------------------------------------------------------------------------------- 1 | # 2 | # This should be in the $USER2$ directory if using this example 3 | 4 | # check_rancher EXAMPLE configuration file 5 | # Format: variable = value 6 | # Use this file to avoid having the key visible in the process table 7 | HOSTNAME=rancher.example.com 8 | USERNAME=0ABB3476943A89CA1D95 9 | KEY=qn1rXqfQhfos847jmf89t07jcm8jg590jfhgQNn1 10 | PORT=80 11 | SSL=0 12 | 13 | # You can set this, but it will stop you doing base API tests as they 14 | # will be treated as Environmnet tests 15 | #ENVIRONMENT=Default 16 | 17 | # Global Threshold overrides 18 | cert.warn=7 19 | cert.crit=1 20 | cpu.warn=80 21 | cpu.crit=90 22 | mem.warn=90 23 | mem.crit=99 24 | disk.warn=80 25 | disk.crit=90 26 | disk.exclude=sda3,sda6 27 | swap.warn=1 28 | swap.crit=99999 29 | load.warn=50 30 | load.crit=100 31 | 32 | -------------------------------------------------------------------------------- /rancher.cfg: -------------------------------------------------------------------------------- 1 | # EXAMPLE configuration file 2 | HOSTNAME=rancher.company.co.nz 3 | USERNAME=0BBEDEC058FD596A1D95 4 | KEY=qn1rXqfj8906vnhngiutpore95ujyh9jiJIOPNn1 5 | # We're using HTTPS here; you may want port 80 and SSL=0 6 | PORT=443 7 | SSL=1 8 | 9 | # Note that, if you set this, you cannot test the API by 10 | # just omitting the -E 11 | #ENVIRONMENT=Default 12 | 13 | # Global Threshold overrides 14 | cert.warn=7 15 | cert.crit=1 16 | cpu.warn=80 17 | cpu.crit=90 18 | mem.warn=90 19 | mem.crit=99 20 | disk.warn=80 21 | disk.crit=90 22 | disk.exclude=sda1,sda2 23 | swap.warn=1 24 | swap.crit=99999 25 | load.warn=50 26 | load.crit=100 27 | 28 | # To override cpu/mem/disk/swap on a per-host basis, 29 | # set Host labels in the Rancher interface. Prefix with 'nagios.' 30 | # nagios.cpu.warn=70 31 | 32 | --------------------------------------------------------------------------------