From 1c15d3490a9bc5504667b577a2593c9c65af6272 Mon Sep 17 00:00:00 2001 From: Gerhard Lausser Date: Sun, 16 Feb 2014 02:11:47 +0100 Subject: [PATCH] moremore rewrite --- AUTHORS | 2 +- COPYING | 680 +++--- ChangeLog | 496 ++--- INSTALL | 480 ++--- Makefile.am | 12 +- README | 212 +- THANKS | 4 +- TODO | 12 +- acinclude.m4 | 156 +- check_nwc_health.php | 116 +- configure.ac | 230 +- install-sh | 1054 ++++----- .../AVOS/Component/ConnectionSubsystem.pm | 10 +- .../Classes/AVOS/Component/CpuSubsystem.pm | 25 +- .../Classes/AVOS/Component/KeySubsystem.pm | 10 +- .../Classes/AVOS/Component/MemSubsystem.pm | 16 +- .../AVOS/Component/SecuritySubsystem.pm | 10 +- .../Classes/BGP/Component/PeerSubsystem.pm | 13 +- plugins-scripts/Classes/Bluecoat.pm | 3 +- plugins-scripts/Classes/Brocade.pm | 5 +- plugins-scripts/Classes/CheckPoint.pm | 4 +- .../Classes/CheckPoint/Firewall1.pm | 96 +- .../Firewall1/Component/CpuSubsystem.pm | 13 +- .../Firewall1/Component/DiskSubsystem.pm | 18 +- .../Component/EnvironmentalSubsystem.pm | 27 +- .../Firewall1/Component/FanSubsystem.pm | 14 +- .../Firewall1/Component/FwSubsystem.pm | 14 +- .../Firewall1/Component/HaSubsystem.pm | 14 +- .../Firewall1/Component/MemSubsystem.pm | 12 +- .../Firewall1/Component/MngmtSubsystem.pm | 14 +- .../Firewall1/Component/SvnSubsystem.pm | 14 +- .../Component/TemperatureSubsystem.pm | 14 +- .../Firewall1/Component/VoltageSubsystem.pm | 14 +- .../CiscoAsyncOS/Component/CpuSubsystem.pm | 12 +- .../Component/EnvironmentalSubsystem.pm | 29 +- .../CiscoAsyncOS/Component/FanSubsystem.pm | 11 +- .../CiscoAsyncOS/Component/KeySubsystem.pm | 12 +- .../CiscoAsyncOS/Component/MemSubsystem.pm | 11 +- .../CiscoAsyncOS/Component/RaidSubsystem.pm | 12 +- .../CiscoAsyncOS/Component/SupplySubsystem.pm | 12 +- .../Component/TemperatureSubsystem.pm | 12 +- .../Classes/CiscoCCM/Component/CmSubsystem.pm | 15 +- .../CiscoCCM/Component/PhoneSubsystem.pm | 13 +- plugins-scripts/Classes/CiscoIOS.pm | 2 + .../CiscoIOS/Component/ConfigSubsystem.pm | 14 +- .../CiscoIOS/Component/ConnectionSubsystem.pm | 15 +- .../CiscoIOS/Component/CpuSubsystem.pm | 14 +- .../Component/EnvironmentalSubsystem.pm | 27 +- .../CiscoIOS/Component/FanSubsystem.pm | 12 +- .../CiscoIOS/Component/MemSubsystem.pm | 20 +- .../CiscoIOS/Component/SupplySubsystem.pm | 14 +- .../Component/TemperatureSubsystem.pm | 15 +- .../CiscoIOS/Component/VoltageSubsystem.pm | 13 +- .../CiscoNXOS/Component/CpuSubsystem.pm | 14 +- .../Component/EnvironmentalSubsystem.pm | 16 +- .../CiscoNXOS/Component/MemSubsystem.pm | 14 +- .../CiscoNXOS/Component/SensorSubsystem.pm | 15 +- plugins-scripts/Classes/CiscoWLC.pm | 75 +- .../CiscoWLC/Component/CpuSubsystem.pm | 12 +- .../Component/EnvironmentalSubsystem.pm | 32 +- .../CiscoWLC/Component/FanSubsystem.pm | 13 +- .../CiscoWLC/Component/MemSubsystem.pm | 12 +- .../CiscoWLC/Component/SupplySubsystem.pm | 13 +- .../Component/TemperatureSubsystem.pm | 15 +- .../CiscoWLC/Component/VoltageSubsystem.pm | 13 +- .../CiscoWLC/Component/WlanSubsystem.pm | 25 +- plugins-scripts/Classes/Device.pm | 24 +- plugins-scripts/Classes/F5.pm | 12 +- plugins-scripts/Classes/F5/F5BIGIP.pm | 69 +- .../F5/F5BIGIP/Component/CpuSubsystem.pm | 17 +- .../Component/EnvironmentalSubsystem.pm | 29 +- .../F5/F5BIGIP/Component/FanSubsystem.pm | 14 +- .../Classes/F5/F5BIGIP/Component/LTM.pm | 20 +- .../F5/F5BIGIP/Component/MemSubsystem.pm | 13 +- .../F5BIGIP/Component/PowersupplySubsystem.pm | 13 +- .../F5BIGIP/Component/TemperatureSubsystem.pm | 13 +- plugins-scripts/Classes/FCEOS.pm | 6 +- .../Components/EnvironmentalSubsystem.pm | 19 +- .../Classes/FCEOS/Components/FruSubsystem.pm | 15 +- plugins-scripts/Classes/FCMGMT.pm | 6 +- .../Component/EnvironmentalSubsystem.pm | 20 +- .../FCMGMT/Component/SensorSubsystem.pm | 16 +- plugins-scripts/Classes/FabOS.pm | 57 +- .../Classes/FabOS/Component/CpuSubsystem.pm | 12 +- .../FabOS/Component/EnvironmentalSubsystem.pm | 18 +- .../Classes/FabOS/Component/MemSubsystem.pm | 17 +- .../FabOS/Component/SensorSubsystem.pm | 18 +- plugins-scripts/Classes/Fortigate.pm | 57 +- .../Fortigate/Component/CpuSubsystem.pm | 11 +- .../Fortigate/Component/DiskSubsystem.pm | 13 +- .../Component/EnvironmentalSubsystem.pm | 22 +- .../Fortigate/Component/MemSubsystem.pm | 15 +- .../Fortigate/Component/SensorSubsystem.pm | 15 +- plugins-scripts/Classes/Foundry.pm | 63 +- .../Classes/Foundry/Component/CpuSubsystem.pm | 14 +- .../Component/EnvironmentalSubsystem.pm | 26 +- .../Classes/Foundry/Component/FanSubsystem.pm | 13 +- .../Classes/Foundry/Component/MemSubsystem.pm | 16 +- .../Foundry/Component/PowersupplySubsystem.pm | 13 +- .../Classes/Foundry/Component/SLBSubsystem.pm | 27 +- .../Foundry/Component/TemperatureSubsystem.pm | 13 +- plugins-scripts/Classes/Generic.pm | 40 - plugins-scripts/Classes/HOSTRESOURCESMIB.pm | 6 +- .../Component/CpuSubsystem.pm | 14 +- .../Component/DiskSubsystem.pm | 17 +- .../Component/EnvironmentalSubsystem.pm | 21 +- .../Component/MemSubsystem.pm | 15 +- plugins-scripts/Classes/HP.pm | 12 +- plugins-scripts/Classes/HP/Procurve.pm | 60 +- .../HP/Procurve/Component/CpuSubsystem.pm | 11 +- .../Component/EnvironmentalSubsystem.pm | 20 +- .../HP/Procurve/Component/MemSubsystem.pm | 15 +- .../HP/Procurve/Component/SensorSubsystem.pm | 16 +- plugins-scripts/Classes/HSRP.pm | 6 +- .../Classes/HSRP/Component/HSRPSubsystem.pm | 14 +- plugins-scripts/Classes/IFMIB.pm | 6 +- .../IFMIB/Component/InterfaceSubsystem.pm | 14 +- .../IFMIB/Component/LinkAggregation.pm | 13 +- plugins-scripts/Classes/Juniper.pm | 20 +- plugins-scripts/Classes/Juniper/IVE.pm | 71 +- .../Juniper/IVE/Component/CpuSubsystem.pm | 14 +- .../Juniper/IVE/Component/DiskSubsystem.pm | 14 +- .../IVE/Component/EnvironmentalSubsystem.pm | 21 +- .../Juniper/IVE/Component/MemSubsystem.pm | 15 +- .../Juniper/IVE/Component/UserSubsystem.pm | 15 +- plugins-scripts/Classes/Juniper/NetScreen.pm | 53 +- .../NetScreen/Component/CpuSubsystem.pm | 42 +- .../NetScreen/Component/MemSubsystem.pm | 15 +- plugins-scripts/Classes/MEOS.pm | 51 +- plugins-scripts/Classes/MIBII.pm | 6 +- plugins-scripts/Classes/Nortel.pm | 78 +- plugins-scripts/Classes/SGOS.pm | 79 +- .../SGOS/Component/ConnectionSubsystem.pm | 15 +- .../Classes/SGOS/Component/CpuSubsystem.pm | 15 +- .../Classes/SGOS/Component/DiskSubsystem.pm | 14 +- .../SGOS/Component/EnvironmentalSubsystem.pm | 23 +- .../Classes/SGOS/Component/MemSubsystem.pm | 18 +- .../SGOS/Component/SecuritySubsystem.pm | 13 +- .../Classes/SGOS/Component/SensorSubsystem.pm | 15 +- plugins-scripts/Classes/SecureOS.pm | 57 +- plugins-scripts/Classes/UCDMIB.pm | 6 +- .../Classes/UCDMIB/Components/CpuSubsystem.pm | 16 +- .../Classes/UCDMIB/Components/MemSubsystem.pm | 18 +- plugins-scripts/GLPlugin.pm | 1894 +++++++++++++++++ plugins-scripts/Makefile.am | 1 - plugins-scripts/Nagios/MiniPlugin.pm | 994 ++++----- plugins-scripts/Server/Linux.pm | 664 +++--- plugins-scripts/UPNP.pm | 136 +- plugins-scripts/UPNP/AVM.pm | 40 +- plugins-scripts/UPNP/AVM/FritzBox7390.pm | 342 +-- .../Components/InterfaceSubsystem.pm | 344 +-- .../Components/SmartHomeSubsystem.pm | 614 +++--- plugins-scripts/check_nwc_health.pl | 1 - 153 files changed, 5604 insertions(+), 5544 deletions(-) delete mode 100644 plugins-scripts/Classes/Generic.pm create mode 100755 plugins-scripts/GLPlugin.pm diff --git a/AUTHORS b/AUTHORS index a9c78ca4..6206f022 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1 +1 @@ -Gerhard Lausser +Gerhard Lausser diff --git a/COPYING b/COPYING index f89b4fa4..60549be5 100644 --- a/COPYING +++ b/COPYING @@ -1,340 +1,340 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) 19yy - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) 19yy name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) 19yy + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) 19yy name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/ChangeLog b/ChangeLog index 3f8dd5c5..17e0b56d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,248 +1,248 @@ -############################################ -# Changelog of the check_nwc_health plugin # -############################################ - -2014 - -2014-02-07 2.6.5.2 -- add another cisco unified communication model - -2014-01-31 2.6.5.1 -- handle a missing brocade fabric watch license in cpu-load & memory-usage -- add CISCO-ENHANCED-MEMPOOL-MIB - -2014-01-24 2.6.5 -- add mode --check-config, which finds unsaved (cisco only) configs (Thanks Simon Meggle) - -2014-01-18 2.6.4.3 -- bugfix in uptime (Thanks Finn Christiansen) - -2014-01-15 2.6.4.2 -- add http connection checks for bluecoat sg - -2014-01-14 2.6.4 -- add cisco ccm - -2014-01-11 2.6.3.1 -- support more SecureOS devices (i bought Juniper SSG5) -- bugfix in upnp-detection - -2013-12-21 2.6.3 -- output number of sessions for f5 bigip load balancer pools -- deal with obviously wrong values from devices (20000% cpu usage) -- foundry server load balancing -- bugfix in interface-* for Juniper IVE -- filter hsrp groups by name - -2013-11-08 -- added support for role based login for Fritz Boxes (available since - FRITZ!OS 5.50). Use --community for password, --username for username if - role based security is switched on. - -2013-11-09 -- bugfix for fritzbox - -2013-11-08 2.6.1 -- hardware-health for Checkpoint Firewall-1 - -2013-11-07 2.6 -- finished bgp-peer-status (focus on as numbers with --name2) -- admin down with --interface-status can have any level with --mitigation - -2013-10-31 2.5.4.1 -- add Fujitsu Intelligent Blade Panel 30/12 - -2013-10-30 2.5.4 -- add bgp - -2013-10-01 2.5.3 -- detect more brocade devices - -2013-09-26 2.5.2.1 -- supress double output for html f5 pool members - -2013-09-25 2.5.2 -- add html output for f5 pool members - -2013-09-18 2.5.1.2 -- removed a leftover Data::Dumper (Thanks Frank Belau) - -2013-09-17 2.5.1.1 -- bugfix in lsmpi_io memory pools of Cisco ASR (100% even with --warning/--critical) - -2013-09-11 2.5.1 -- set a 100% threshold for lsmpi_io memory pools of Cisco ASR (Thanks James Clark & Perun) - -2013-09-10 2.5 -- implemented offline mode with --snmpwalk & --offline - -2013-09-03 2.4 -- add Cisco IronPort AsyncOS - -2013-08-27 2.3 -- add Juniper IVE (ex. Pulse-Gateway MAG4610) -- add count-connections for cisco asa - -2013-07-11 2.2 -- add memory-usage for checkpoint -- add detection for cpx - -2013-07-09 2.1.1 -- skip non-interface files in /sys/class/net for servertype linuxlocal (Thanks Sven Nierlein) -- better error handling on unwritable statefiles/dirs - -2013-06-12 2.1 -- added "--servertype ifmib" so you can use "--mode interface*" with every kind of ifmib-capable device - -2013-06-01 2.0 -- added support for AVM FRITZ!DECT 200 smart plug - -2013-05-27 1.9.8.1 -- bugfix for the bugfix in commandline options (Thanks webspace Mario) - -2013-05-23 1.9.8 -- add Brocade Communications Systems, Inc. ICX6610-24-HPOE, IronWare -- bugfix in commandline options (Thanks TheCry) - -2013-05-17 1.9.7.4 -- added another fallback for snmp-get_entries -- fixed a bug in uptime (only first minute after reboot) - -2013-04-20 1.9.7.3 -- fixed a bug in snmpwalk simulation and savestate - -2013-04-08 1.9.7.2 -- bugfix, interfaces were shown twice in list-interfaces - -2013-03-26 1.9.7.1 -- set automatic thresholds for link-aggregation-availability - -2013-03-25 1.9.7 -- added link-aggregation-availability - -2013-03-19 1.9.6 -- fixed a bug in interface-* -- speedup in interface-* (with --name and 64bit) -- added a hostname/community hash to statefiles - -2013-02-13 1.9.5.1 -- fixed a bug deep inside snmp bulkwalks and lots of interfaces (Thanks Uestuen Oender) - -2013-02-24 1.9.5 -- add interface-availability - -2013-02-11 1.9.4 -- add Cisco Wireless LAN Controller 5500 - -2013-02-11 1.9.3.1 -- fixed a bug in statefiles with uppercase directory names. (Thanks Matthias Gallinger) - -2013-02-10 1.9.3 -- add blue coat sg600 - -2013-02-02 1.9.2 -- removed my static ip from FRITZ!BOX interface-usage (Thanks Stef) - -2013-01- 1.9.1 -- fixed a bug in FFritz!BOX uptime (Thanks Lars Urban) - -3013-01 1.9 -- add uptime and interface-usage for AVM FRITZ!Box 7390 -- add cpu-load and memory-usage for AVM FRITZ!Box 7390 - -2013-01-13 1.8 --add cpu&memory check for juniper netscreen - -2013-01-12 1.7.1 -- add a name caching mechanism for f5 bigip pools - -2013-01-08 1.7 -- add f5 bigip pool completeness -- add member info for failed f5 pools - -2012-12-10 1.6 -- add checkpoint firewall-1 - -2012-11-23 1.5 -- add 64bit interfaces - -2012-09-26 1.4.9.1 -- fix a bug in uptime calculation - -2012-09-24 1.4.9 -- add hp procurve cpu-load and memory-usage -- fix a bug in cisco memory perfdata - -2012-08-28 1.4.8 -- add hp procurve hardware - -2012-08-21 1.4.7.1 -- fix a bug in servertype locallinux, interfaces and --name (Thanks Simon Meggle) - -2012-08-21 1.4.7 -- add f5 bigip -- bugfix in mode uptime - -2012-08-10 1.4.6 -- add mode uptime - -2012-08-10 1.4.5.2 -- fix a bug in statefilesdir creation under omd - -2012-08-02 1.4.5.1 -- add more hardware info for EMC-DS24M2 (McData Sphereon 4500) - -2012-07-31 1.4.5 -- add UCD-MIB for SecureOS (McAfee Sidewinder) - -2012-07-31 1.4.4 -- add fibre alliance mib sensor table for MeOS/DS-4700M - -2012-07-20 1.4.3.1 -- add the index to interface names, if interfaces all have the same name -- first experiments with MeOS - -2012-07-12 1.4.3 -- fix a bug in the role parameter for hsrp -- fix a temperature index where ios doesn't set the counter itself -- add mib2-interface-modes to brocade fabos - -2012-07-05 1.4.2 -- add mode encode for interface names with ' or " - -2012-07-05 1.4.1 -- add --ifspeedin, --ifspeedout, --ifspeed (used for asymmetric mpls) - -2012-06-22 1.4 -- add linux local interfaces (interface-usage/errors only) with --servertype linuxlocal -- add mode walk -- rename brocade300 -> fabos - -2012-04-23 1.3 -- add mode list-interfaces-detail (Cisco only) -- add brocade300 (hardware-health,memory-usage,cpu-load only) - -2012-03-29 1.2 -- add support for Cisco Nexus (cpu, mem, ) -- add Nexus sensors -- add Allied Telesyn (only interfaces so far) - -2012-03-19 1.1.1.1 -- bugfix in list-hsrp-groups -- --units KBi/MBi/GBi for interface-usage - -2012-02-22 1.1.1 -- add mode hsrp-failover (Thanks Munich) - -2012-02-22 1.1 -- add mode hsrp-state (Thanks Munich) - -2012-01-05 -- some more debug messages - -2012-01-04 1.0 -- Nortel devices are recognized. (only interfaces can be queried by now) - - - -- no official changes yet +############################################ +# Changelog of the check_nwc_health plugin # +############################################ + +2014 + +2014-02-07 2.6.5.2 +- add another cisco unified communication model + +2014-01-31 2.6.5.1 +- handle a missing brocade fabric watch license in cpu-load & memory-usage +- add CISCO-ENHANCED-MEMPOOL-MIB + +2014-01-24 2.6.5 +- add mode --check-config, which finds unsaved (cisco only) configs (Thanks Simon Meggle) + +2014-01-18 2.6.4.3 +- bugfix in uptime (Thanks Finn Christiansen) + +2014-01-15 2.6.4.2 +- add http connection checks for bluecoat sg + +2014-01-14 2.6.4 +- add cisco ccm + +2014-01-11 2.6.3.1 +- support more SecureOS devices (i bought Juniper SSG5) +- bugfix in upnp-detection + +2013-12-21 2.6.3 +- output number of sessions for f5 bigip load balancer pools +- deal with obviously wrong values from devices (20000% cpu usage) +- foundry server load balancing +- bugfix in interface-* for Juniper IVE +- filter hsrp groups by name + +2013-11-08 +- added support for role based login for Fritz Boxes (available since + FRITZ!OS 5.50). Use --community for password, --username for username if + role based security is switched on. + +2013-11-09 +- bugfix for fritzbox + +2013-11-08 2.6.1 +- hardware-health for Checkpoint Firewall-1 + +2013-11-07 2.6 +- finished bgp-peer-status (focus on as numbers with --name2) +- admin down with --interface-status can have any level with --mitigation + +2013-10-31 2.5.4.1 +- add Fujitsu Intelligent Blade Panel 30/12 + +2013-10-30 2.5.4 +- add bgp + +2013-10-01 2.5.3 +- detect more brocade devices + +2013-09-26 2.5.2.1 +- supress double output for html f5 pool members + +2013-09-25 2.5.2 +- add html output for f5 pool members + +2013-09-18 2.5.1.2 +- removed a leftover Data::Dumper (Thanks Frank Belau) + +2013-09-17 2.5.1.1 +- bugfix in lsmpi_io memory pools of Cisco ASR (100% even with --warning/--critical) + +2013-09-11 2.5.1 +- set a 100% threshold for lsmpi_io memory pools of Cisco ASR (Thanks James Clark & Perun) + +2013-09-10 2.5 +- implemented offline mode with --snmpwalk & --offline + +2013-09-03 2.4 +- add Cisco IronPort AsyncOS + +2013-08-27 2.3 +- add Juniper IVE (ex. Pulse-Gateway MAG4610) +- add count-connections for cisco asa + +2013-07-11 2.2 +- add memory-usage for checkpoint +- add detection for cpx + +2013-07-09 2.1.1 +- skip non-interface files in /sys/class/net for servertype linuxlocal (Thanks Sven Nierlein) +- better error handling on unwritable statefiles/dirs + +2013-06-12 2.1 +- added "--servertype ifmib" so you can use "--mode interface*" with every kind of ifmib-capable device + +2013-06-01 2.0 +- added support for AVM FRITZ!DECT 200 smart plug + +2013-05-27 1.9.8.1 +- bugfix for the bugfix in commandline options (Thanks webspace Mario) + +2013-05-23 1.9.8 +- add Brocade Communications Systems, Inc. ICX6610-24-HPOE, IronWare +- bugfix in commandline options (Thanks TheCry) + +2013-05-17 1.9.7.4 +- added another fallback for snmp-get_entries +- fixed a bug in uptime (only first minute after reboot) + +2013-04-20 1.9.7.3 +- fixed a bug in snmpwalk simulation and savestate + +2013-04-08 1.9.7.2 +- bugfix, interfaces were shown twice in list-interfaces + +2013-03-26 1.9.7.1 +- set automatic thresholds for link-aggregation-availability + +2013-03-25 1.9.7 +- added link-aggregation-availability + +2013-03-19 1.9.6 +- fixed a bug in interface-* +- speedup in interface-* (with --name and 64bit) +- added a hostname/community hash to statefiles + +2013-02-13 1.9.5.1 +- fixed a bug deep inside snmp bulkwalks and lots of interfaces (Thanks Uestuen Oender) + +2013-02-24 1.9.5 +- add interface-availability + +2013-02-11 1.9.4 +- add Cisco Wireless LAN Controller 5500 + +2013-02-11 1.9.3.1 +- fixed a bug in statefiles with uppercase directory names. (Thanks Matthias Gallinger) + +2013-02-10 1.9.3 +- add blue coat sg600 + +2013-02-02 1.9.2 +- removed my static ip from FRITZ!BOX interface-usage (Thanks Stef) + +2013-01- 1.9.1 +- fixed a bug in FFritz!BOX uptime (Thanks Lars Urban) + +3013-01 1.9 +- add uptime and interface-usage for AVM FRITZ!Box 7390 +- add cpu-load and memory-usage for AVM FRITZ!Box 7390 + +2013-01-13 1.8 +-add cpu&memory check for juniper netscreen + +2013-01-12 1.7.1 +- add a name caching mechanism for f5 bigip pools + +2013-01-08 1.7 +- add f5 bigip pool completeness +- add member info for failed f5 pools + +2012-12-10 1.6 +- add checkpoint firewall-1 + +2012-11-23 1.5 +- add 64bit interfaces + +2012-09-26 1.4.9.1 +- fix a bug in uptime calculation + +2012-09-24 1.4.9 +- add hp procurve cpu-load and memory-usage +- fix a bug in cisco memory perfdata + +2012-08-28 1.4.8 +- add hp procurve hardware + +2012-08-21 1.4.7.1 +- fix a bug in servertype locallinux, interfaces and --name (Thanks Simon Meggle) + +2012-08-21 1.4.7 +- add f5 bigip +- bugfix in mode uptime + +2012-08-10 1.4.6 +- add mode uptime + +2012-08-10 1.4.5.2 +- fix a bug in statefilesdir creation under omd + +2012-08-02 1.4.5.1 +- add more hardware info for EMC-DS24M2 (McData Sphereon 4500) + +2012-07-31 1.4.5 +- add UCD-MIB for SecureOS (McAfee Sidewinder) + +2012-07-31 1.4.4 +- add fibre alliance mib sensor table for MeOS/DS-4700M + +2012-07-20 1.4.3.1 +- add the index to interface names, if interfaces all have the same name +- first experiments with MeOS + +2012-07-12 1.4.3 +- fix a bug in the role parameter for hsrp +- fix a temperature index where ios doesn't set the counter itself +- add mib2-interface-modes to brocade fabos + +2012-07-05 1.4.2 +- add mode encode for interface names with ' or " + +2012-07-05 1.4.1 +- add --ifspeedin, --ifspeedout, --ifspeed (used for asymmetric mpls) + +2012-06-22 1.4 +- add linux local interfaces (interface-usage/errors only) with --servertype linuxlocal +- add mode walk +- rename brocade300 -> fabos + +2012-04-23 1.3 +- add mode list-interfaces-detail (Cisco only) +- add brocade300 (hardware-health,memory-usage,cpu-load only) + +2012-03-29 1.2 +- add support for Cisco Nexus (cpu, mem, ) +- add Nexus sensors +- add Allied Telesyn (only interfaces so far) + +2012-03-19 1.1.1.1 +- bugfix in list-hsrp-groups +- --units KBi/MBi/GBi for interface-usage + +2012-02-22 1.1.1 +- add mode hsrp-failover (Thanks Munich) + +2012-02-22 1.1 +- add mode hsrp-state (Thanks Munich) + +2012-01-05 +- some more debug messages + +2012-01-04 1.0 +- Nortel devices are recognized. (only interfaces can be queried by now) + + + +- no official changes yet diff --git a/INSTALL b/INSTALL index b187af1f..ab8dd4f2 100644 --- a/INSTALL +++ b/INSTALL @@ -1,240 +1,240 @@ -Copyright (C) Gerhard Lausser, gerhard.lausser@consol.de - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - -Basic Installation -================== - - These are generic installation instructions. - - The `configure' shell script attempts to guess correct values for -various system-dependent variables used during compilation. It uses -those values to create a `Makefile' in each directory of the package. -It may also create one or more `.h' files containing system-dependent -definitions. Finally, it creates a shell script `config.status' that -you can run in the future to recreate the current configuration, and a -file `config.log' containing compiler output (useful mainly for -debugging `configure'). - - It can also use an optional file (typically called `config.cache' -and enabled with `--cache-file=config.cache' or simply `-C') that saves -the results of its tests to speed up reconfiguring. (Caching is -disabled by default to prevent problems with accidental use of stale -cache files.) - - If you need to do unusual things to compile the package, please try -to figure out how `configure' could check whether to do them, and mail -diffs or instructions to the address given in the `README' so they can -be considered for the next release. If you are using the cache, and at -some point `config.cache' contains results you don't want to keep, you -may remove or edit it. - - The file `configure.ac' (or `configure.in') is used to create -`configure' by a program called `autoconf'. You only need -`configure.ac' if you want to change it or regenerate `configure' using -a newer version of `autoconf'. - -The simplest way to compile this package is: - - 1. `cd' to the directory containing the package's source code and type - `./configure' to configure the package for your system. If you're - using `csh' on an old version of System V, you might need to type - `sh ./configure' instead to prevent `csh' from trying to execute - `configure' itself. - - Running `configure' takes awhile. While running, it prints some - messages telling which features it is checking for. - - 2. Type `make' to compile the package. - - 3. Optionally, type `make check' to run any self-tests that come with - the package. - - 4. Type `make install' to install the programs and any data files and - documentation. - - 5. You can remove the program binaries and object files from the - source code directory by typing `make clean'. To also remove the - files that `configure' created (so you can compile the package for - a different kind of computer), type `make distclean'. There is - also a `make maintainer-clean' target, but that is intended mainly - for the package's developers. If you use it, you may have to get - all sorts of other programs in order to regenerate files that came - with the distribution. - -Compilers and Options -===================== - - Some systems require unusual options for compilation or linking that -the `configure' script does not know about. Run `./configure --help' -for details on some of the pertinent environment variables. - - You can give `configure' initial values for configuration parameters -by setting variables in the command line or in the environment. Here -is an example: - - ./configure CC=c89 CFLAGS=-O2 LIBS=-lposix - - *Note Defining Variables::, for more details. - -Compiling For Multiple Architectures -==================================== - - You can compile the package for more than one kind of computer at the -same time, by placing the object files for each architecture in their -own directory. To do this, you must use a version of `make' that -supports the `VPATH' variable, such as GNU `make'. `cd' to the -directory where you want the object files and executables to go and run -the `configure' script. `configure' automatically checks for the -source code in the directory that `configure' is in and in `..'. - - If you have to use a `make' that does not support the `VPATH' -variable, you have to compile the package for one architecture at a -time in the source code directory. After you have installed the -package for one architecture, use `make distclean' before reconfiguring -for another architecture. - -Installation Names -================== - - By default, `make install' will install the package's files in -`/usr/local/bin', `/usr/local/man', etc. You can specify an -installation prefix other than `/usr/local' by giving `configure' the -option `--prefix=PATH'. - - You can specify separate installation prefixes for -architecture-specific files and architecture-independent files. If you -give `configure' the option `--exec-prefix=PATH', the package will use -PATH as the prefix for installing programs and libraries. -Documentation and other data files will still use the regular prefix. - - In addition, if you use an unusual directory layout you can give -options like `--bindir=PATH' to specify different values for particular -kinds of files. Run `configure --help' for a list of the directories -you can set and what kinds of files go in them. - - If the package supports it, you can cause programs to be installed -with an extra prefix or suffix on their names by giving `configure' the -option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. - -Optional Features -================= - - Some packages pay attention to `--enable-FEATURE' options to -`configure', where FEATURE indicates an optional part of the package. -They may also pay attention to `--with-PACKAGE' options, where PACKAGE -is something like `gnu-as' or `x' (for the X Window System). The -`README' should mention any `--enable-' and `--with-' options that the -package recognizes. - - For packages that use the X Window System, `configure' can usually -find the X include and library files automatically, but if it doesn't, -you can use the `configure' options `--x-includes=DIR' and -`--x-libraries=DIR' to specify their locations. - -Specifying the System Type -========================== - - There may be some features `configure' cannot figure out -automatically, but needs to determine by the type of machine the package -will run on. Usually, assuming the package is built to be run on the -_same_ architectures, `configure' can figure that out, but if it prints -a message saying it cannot guess the machine type, give it the -`--build=TYPE' option. TYPE can either be a short name for the system -type, such as `sun4', or a canonical name which has the form: - - CPU-COMPANY-SYSTEM - -where SYSTEM can have one of these forms: - - OS KERNEL-OS - - See the file `config.sub' for the possible values of each field. If -`config.sub' isn't included in this package, then this package doesn't -need to know the machine type. - - If you are _building_ compiler tools for cross-compiling, you should -use the `--target=TYPE' option to select the type of system they will -produce code for. - - If you want to _use_ a cross compiler, that generates code for a -platform different from the build platform, you should specify the -"host" platform (i.e., that on which the generated programs will -eventually be run) with `--host=TYPE'. - -Sharing Defaults -================ - - If you want to set default values for `configure' scripts to share, -you can create a site shell script called `config.site' that gives -default values for variables like `CC', `cache_file', and `prefix'. -`configure' looks for `PREFIX/share/config.site' if it exists, then -`PREFIX/etc/config.site' if it exists. Or, you can set the -`CONFIG_SITE' environment variable to the location of the site script. -A warning: not all `configure' scripts look for a site script. - -Defining Variables -================== - - Variables not defined in a site shell script can be set in the -environment passed to `configure'. However, some packages may run -configure again during the build, and the customized values of these -variables may be lost. In order to avoid this problem, you should set -them in the `configure' command line, using `VAR=value'. For example: - - ./configure CC=/usr/local2/bin/gcc - -will cause the specified gcc to be used as the C compiler (unless it is -overridden in the site shell script). - -`configure' Invocation -====================== - - `configure' recognizes the following options to control how it -operates. - -`--help' -`-h' - Print a summary of the options to `configure', and exit. - -`--version' -`-V' - Print the version of Autoconf used to generate the `configure' - script, and exit. - -`--cache-file=FILE' - Enable the cache: use and save the results of the tests in FILE, - traditionally `config.cache'. FILE defaults to `/dev/null' to - disable caching. - -`--config-cache' -`-C' - Alias for `--cache-file=config.cache'. - -`--quiet' -`--silent' -`-q' - Do not print messages saying which checks are being made. To - suppress all normal output, redirect it to `/dev/null' (any error - messages will still be shown). - -`--srcdir=DIR' - Look for the package's source code in directory DIR. Usually - `configure' can determine that directory automatically. - -`configure' also accepts some other, not widely useful, options. Run -`configure --help' for more details. - +Copyright (C) Gerhard Lausser, gerhard.lausser@consol.de + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + +Basic Installation +================== + + These are generic installation instructions. + + The `configure' shell script attempts to guess correct values for +various system-dependent variables used during compilation. It uses +those values to create a `Makefile' in each directory of the package. +It may also create one or more `.h' files containing system-dependent +definitions. Finally, it creates a shell script `config.status' that +you can run in the future to recreate the current configuration, and a +file `config.log' containing compiler output (useful mainly for +debugging `configure'). + + It can also use an optional file (typically called `config.cache' +and enabled with `--cache-file=config.cache' or simply `-C') that saves +the results of its tests to speed up reconfiguring. (Caching is +disabled by default to prevent problems with accidental use of stale +cache files.) + + If you need to do unusual things to compile the package, please try +to figure out how `configure' could check whether to do them, and mail +diffs or instructions to the address given in the `README' so they can +be considered for the next release. If you are using the cache, and at +some point `config.cache' contains results you don't want to keep, you +may remove or edit it. + + The file `configure.ac' (or `configure.in') is used to create +`configure' by a program called `autoconf'. You only need +`configure.ac' if you want to change it or regenerate `configure' using +a newer version of `autoconf'. + +The simplest way to compile this package is: + + 1. `cd' to the directory containing the package's source code and type + `./configure' to configure the package for your system. If you're + using `csh' on an old version of System V, you might need to type + `sh ./configure' instead to prevent `csh' from trying to execute + `configure' itself. + + Running `configure' takes awhile. While running, it prints some + messages telling which features it is checking for. + + 2. Type `make' to compile the package. + + 3. Optionally, type `make check' to run any self-tests that come with + the package. + + 4. Type `make install' to install the programs and any data files and + documentation. + + 5. You can remove the program binaries and object files from the + source code directory by typing `make clean'. To also remove the + files that `configure' created (so you can compile the package for + a different kind of computer), type `make distclean'. There is + also a `make maintainer-clean' target, but that is intended mainly + for the package's developers. If you use it, you may have to get + all sorts of other programs in order to regenerate files that came + with the distribution. + +Compilers and Options +===================== + + Some systems require unusual options for compilation or linking that +the `configure' script does not know about. Run `./configure --help' +for details on some of the pertinent environment variables. + + You can give `configure' initial values for configuration parameters +by setting variables in the command line or in the environment. Here +is an example: + + ./configure CC=c89 CFLAGS=-O2 LIBS=-lposix + + *Note Defining Variables::, for more details. + +Compiling For Multiple Architectures +==================================== + + You can compile the package for more than one kind of computer at the +same time, by placing the object files for each architecture in their +own directory. To do this, you must use a version of `make' that +supports the `VPATH' variable, such as GNU `make'. `cd' to the +directory where you want the object files and executables to go and run +the `configure' script. `configure' automatically checks for the +source code in the directory that `configure' is in and in `..'. + + If you have to use a `make' that does not support the `VPATH' +variable, you have to compile the package for one architecture at a +time in the source code directory. After you have installed the +package for one architecture, use `make distclean' before reconfiguring +for another architecture. + +Installation Names +================== + + By default, `make install' will install the package's files in +`/usr/local/bin', `/usr/local/man', etc. You can specify an +installation prefix other than `/usr/local' by giving `configure' the +option `--prefix=PATH'. + + You can specify separate installation prefixes for +architecture-specific files and architecture-independent files. If you +give `configure' the option `--exec-prefix=PATH', the package will use +PATH as the prefix for installing programs and libraries. +Documentation and other data files will still use the regular prefix. + + In addition, if you use an unusual directory layout you can give +options like `--bindir=PATH' to specify different values for particular +kinds of files. Run `configure --help' for a list of the directories +you can set and what kinds of files go in them. + + If the package supports it, you can cause programs to be installed +with an extra prefix or suffix on their names by giving `configure' the +option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. + +Optional Features +================= + + Some packages pay attention to `--enable-FEATURE' options to +`configure', where FEATURE indicates an optional part of the package. +They may also pay attention to `--with-PACKAGE' options, where PACKAGE +is something like `gnu-as' or `x' (for the X Window System). The +`README' should mention any `--enable-' and `--with-' options that the +package recognizes. + + For packages that use the X Window System, `configure' can usually +find the X include and library files automatically, but if it doesn't, +you can use the `configure' options `--x-includes=DIR' and +`--x-libraries=DIR' to specify their locations. + +Specifying the System Type +========================== + + There may be some features `configure' cannot figure out +automatically, but needs to determine by the type of machine the package +will run on. Usually, assuming the package is built to be run on the +_same_ architectures, `configure' can figure that out, but if it prints +a message saying it cannot guess the machine type, give it the +`--build=TYPE' option. TYPE can either be a short name for the system +type, such as `sun4', or a canonical name which has the form: + + CPU-COMPANY-SYSTEM + +where SYSTEM can have one of these forms: + + OS KERNEL-OS + + See the file `config.sub' for the possible values of each field. If +`config.sub' isn't included in this package, then this package doesn't +need to know the machine type. + + If you are _building_ compiler tools for cross-compiling, you should +use the `--target=TYPE' option to select the type of system they will +produce code for. + + If you want to _use_ a cross compiler, that generates code for a +platform different from the build platform, you should specify the +"host" platform (i.e., that on which the generated programs will +eventually be run) with `--host=TYPE'. + +Sharing Defaults +================ + + If you want to set default values for `configure' scripts to share, +you can create a site shell script called `config.site' that gives +default values for variables like `CC', `cache_file', and `prefix'. +`configure' looks for `PREFIX/share/config.site' if it exists, then +`PREFIX/etc/config.site' if it exists. Or, you can set the +`CONFIG_SITE' environment variable to the location of the site script. +A warning: not all `configure' scripts look for a site script. + +Defining Variables +================== + + Variables not defined in a site shell script can be set in the +environment passed to `configure'. However, some packages may run +configure again during the build, and the customized values of these +variables may be lost. In order to avoid this problem, you should set +them in the `configure' command line, using `VAR=value'. For example: + + ./configure CC=/usr/local2/bin/gcc + +will cause the specified gcc to be used as the C compiler (unless it is +overridden in the site shell script). + +`configure' Invocation +====================== + + `configure' recognizes the following options to control how it +operates. + +`--help' +`-h' + Print a summary of the options to `configure', and exit. + +`--version' +`-V' + Print the version of Autoconf used to generate the `configure' + script, and exit. + +`--cache-file=FILE' + Enable the cache: use and save the results of the tests in FILE, + traditionally `config.cache'. FILE defaults to `/dev/null' to + disable caching. + +`--config-cache' +`-C' + Alias for `--cache-file=config.cache'. + +`--quiet' +`--silent' +`-q' + Do not print messages saying which checks are being made. To + suppress all normal output, redirect it to `/dev/null' (any error + messages will still be shown). + +`--srcdir=DIR' + Look for the package's source code in directory DIR. Usually + `configure' can determine that directory automatically. + +`configure' also accepts some other, not widely useful, options. Run +`configure --help' for more details. + diff --git a/Makefile.am b/Makefile.am index 21be03ac..23522dc5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,6 @@ -## Process this file with automake to produce Makefile.in - -SUBDIRS = plugins-scripts - -dist-hook: - make +## Process this file with automake to produce Makefile.in + +SUBDIRS = plugins-scripts + +dist-hook: + make diff --git a/README b/README index a3b36f6f..71ca09b4 100644 --- a/README +++ b/README @@ -1,106 +1,106 @@ -check_nwc_health Nagios Plugin README ---------------------- - -This plugin checks the hardware health and various interface metrics -of network components like switches and routers. - -Copyright (C) Gerhard Lausser, gerhard.lausser@consol.de - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - -* For instructions on installing this plugin for use with Nagios, - see below. In addition, generic instructions for the GNU toolchain - can be found in the INSTALL file. - -* For major changes between releases, read the CHANGES file. - -* For information on detailed changes that have been made, - read the Changelog file. - -* This plugin is self-documenting. All plugins that comply with - the basic guidelines for development will provide detailed help when - invoked with the '-h' or '--help' options. - -You can check for the latest plugin at: - http://labs.consol.de/nagios/check_nwc_health - -Send mail to gerhard.lausser@consol.de for assistance. -Please include the OS type and version that you are using. -Also, run the plugin with the '-vvv' option and provide the resulting -version information. Of course, there may be additional diagnostic information -required as well. Use good judgment. - - -How to "compile" the check_nwc_health script. --------------------------------------------------------- - -1) Run the configure script to initialize variables and create a Makefile, etc. - - ./configure --prefix=BASEDIRECTORY --with-nagios-user=SOMEUSER --with-nagios-group=SOMEGROUP --with-perl=PATH_TO_PERL - - a) Replace BASEDIRECTORY with the path of the directory under which Nagios - is installed (default is '/usr/local/nagios') - b) Replace SOMEUSER with the name of a user on your system that will be - assigned permissions to the installed plugins (default is 'nagios') - c) Replace SOMEGRP with the name of a group on your system that will be - assigned permissions to the installed plugins (default is 'nagios') - d) Replace PATH_TO_PERL with the path where a perl binary can be found. - Besides the system wide perl you might have installed a private perl - just for the nagios plugins (default is the perl in your path). - - -2) "Compile" the plugin with the following command: - - make - - This will produce a "check_nwc_health" script. You will also find - a "check_nwc_health.pl" which you better ignore. It is the base for - the compilation filled with placeholders. These will be replaced during - the make process. - - -3) Install the compiled plugin script with the following command: - - make install - - The installation procedure will attempt to place the plugin in a - 'libexec/' subdirectory in the base directory you specified with - the --prefix argument to the configure script. - - -4) Verify that your configuration files for Nagios contains - the correct paths to the new plugin. - - - -Command line parameters ------------------------ - -You'll find the command line parameters on the website mentioned above. -If it does not exist or is not up to date, this means that i hadn't the -time to write/update it yet. I am aware of it, so please don't send me -mails. Just accept it. - - - -Sample data from real machines ------------------------------- -If you think check_nwc_health is not working correctly, send me the output of snmpwalk -snmpwalk .... 1.3.6.1.4.1.232 - - --- -Gerhard Lausser +check_nwc_health Nagios Plugin README +--------------------- + +This plugin checks the hardware health and various interface metrics +of network components like switches and routers. + +Copyright (C) Gerhard Lausser, gerhard.lausser@consol.de + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + +* For instructions on installing this plugin for use with Nagios, + see below. In addition, generic instructions for the GNU toolchain + can be found in the INSTALL file. + +* For major changes between releases, read the CHANGES file. + +* For information on detailed changes that have been made, + read the Changelog file. + +* This plugin is self-documenting. All plugins that comply with + the basic guidelines for development will provide detailed help when + invoked with the '-h' or '--help' options. + +You can check for the latest plugin at: + http://labs.consol.de/nagios/check_nwc_health + +Send mail to gerhard.lausser@consol.de for assistance. +Please include the OS type and version that you are using. +Also, run the plugin with the '-vvv' option and provide the resulting +version information. Of course, there may be additional diagnostic information +required as well. Use good judgment. + + +How to "compile" the check_nwc_health script. +-------------------------------------------------------- + +1) Run the configure script to initialize variables and create a Makefile, etc. + + ./configure --prefix=BASEDIRECTORY --with-nagios-user=SOMEUSER --with-nagios-group=SOMEGROUP --with-perl=PATH_TO_PERL + + a) Replace BASEDIRECTORY with the path of the directory under which Nagios + is installed (default is '/usr/local/nagios') + b) Replace SOMEUSER with the name of a user on your system that will be + assigned permissions to the installed plugins (default is 'nagios') + c) Replace SOMEGRP with the name of a group on your system that will be + assigned permissions to the installed plugins (default is 'nagios') + d) Replace PATH_TO_PERL with the path where a perl binary can be found. + Besides the system wide perl you might have installed a private perl + just for the nagios plugins (default is the perl in your path). + + +2) "Compile" the plugin with the following command: + + make + + This will produce a "check_nwc_health" script. You will also find + a "check_nwc_health.pl" which you better ignore. It is the base for + the compilation filled with placeholders. These will be replaced during + the make process. + + +3) Install the compiled plugin script with the following command: + + make install + + The installation procedure will attempt to place the plugin in a + 'libexec/' subdirectory in the base directory you specified with + the --prefix argument to the configure script. + + +4) Verify that your configuration files for Nagios contains + the correct paths to the new plugin. + + + +Command line parameters +----------------------- + +You'll find the command line parameters on the website mentioned above. +If it does not exist or is not up to date, this means that i hadn't the +time to write/update it yet. I am aware of it, so please don't send me +mails. Just accept it. + + + +Sample data from real machines +------------------------------ +If you think check_nwc_health is not working correctly, send me the output of snmpwalk +snmpwalk .... 1.3.6.1.4.1.232 + + +-- +Gerhard Lausser diff --git a/THANKS b/THANKS index a6387c0c..231629ad 100644 --- a/THANKS +++ b/THANKS @@ -1,2 +1,2 @@ -A big THANK YOU to Francois Mikus for pointing me to genDevConfig, where i found lots of useful oids. - +A big THANK YOU to Francois Mikus for pointing me to genDevConfig, where i found lots of useful oids. + diff --git a/TODO b/TODO index 1cae1b64..99c9b564 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,6 @@ -- interface up down, operstatus -- traffic, in, out, 2xthresholds? -- errors -- cpu -- mem -- load +- interface up down, operstatus +- traffic, in, out, 2xthresholds? +- errors +- cpu +- mem +- load diff --git a/acinclude.m4 b/acinclude.m4 index fe241c4b..788d68eb 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -1,78 +1,78 @@ -dnl @synopsis ACX_WHICH_GETHOSTBYNAME_R -dnl -dnl Provides a test to determine the correct way to call gethostbyname_r -dnl -dnl defines HAVE_GETHOSTBYNAME_R to the number of arguments required -dnl -dnl e.g. 6 arguments (linux) -dnl e.g. 5 arguments (solaris) -dnl e.g. 3 arguments (osf/1) -dnl -dnl @version $Id: acinclude.m4,v 1.5 2004/02/18 14:56:34 kdebisschop Exp $ -dnl @author Brian Stafford -dnl -dnl based on version by Caolan McNamara -dnl based on David Arnold's autoconf suggestion in the threads faq -dnl -AC_DEFUN([ACX_WHICH_GETHOSTBYNAME_R], -[AC_CACHE_CHECK(number of arguments to gethostbyname_r, - acx_which_gethostbyname_r, [ - AC_TRY_COMPILE([ -# include - ], [ - - char *name; - struct hostent *he; - struct hostent_data data; - (void) gethostbyname_r(name, he, &data); - - ],acx_which_gethostbyname_r=3, - [ -dnl acx_which_gethostbyname_r=0 - AC_TRY_COMPILE([ -# include - ], [ - char *name; - struct hostent *he, *res; - char *buffer = NULL; - int buflen = 2048; - int h_errnop; - (void) gethostbyname_r(name, he, buffer, buflen, &res, &h_errnop) - ],acx_which_gethostbyname_r=6, - - [ -dnl acx_which_gethostbyname_r=0 - AC_TRY_COMPILE([ -# include - ], [ - char *name; - struct hostent *he; - char *buffer = NULL; - int buflen = 2048; - int h_errnop; - (void) gethostbyname_r(name, he, buffer, buflen, &h_errnop) - ],acx_which_gethostbyname_r=5,acx_which_gethostbyname_r=0) - - ] - - ) - ] - ) - ]) - -if test $acx_which_gethostbyname_r -gt 0 ; then - AC_DEFINE_UNQUOTED([HAVE_GETHOSTBYNAME_R], $acx_which_gethostbyname_r, - [Number of parameters to gethostbyname_r or 0 if not available]) -fi - -]) - -dnl @synopsis ACX_HELP_STRING(OPTION,DESCRIPTION) -AC_DEFUN([ACX_HELP_STRING], - [ $1 builtin([substr],[ ],len($1))[$2]]) - - -dnl @synopsis ACX_FEATURE(ENABLE_OR_WITH,NAME[,VALUE]) -AC_DEFUN([ACX_FEATURE], - [echo "builtin([substr],[ ],len(--$1-$2))--$1-$2: ifelse($3,,[$]translit($1-$2,-,_),$3)"]) - +dnl @synopsis ACX_WHICH_GETHOSTBYNAME_R +dnl +dnl Provides a test to determine the correct way to call gethostbyname_r +dnl +dnl defines HAVE_GETHOSTBYNAME_R to the number of arguments required +dnl +dnl e.g. 6 arguments (linux) +dnl e.g. 5 arguments (solaris) +dnl e.g. 3 arguments (osf/1) +dnl +dnl @version $Id: acinclude.m4,v 1.5 2004/02/18 14:56:34 kdebisschop Exp $ +dnl @author Brian Stafford +dnl +dnl based on version by Caolan McNamara +dnl based on David Arnold's autoconf suggestion in the threads faq +dnl +AC_DEFUN([ACX_WHICH_GETHOSTBYNAME_R], +[AC_CACHE_CHECK(number of arguments to gethostbyname_r, + acx_which_gethostbyname_r, [ + AC_TRY_COMPILE([ +# include + ], [ + + char *name; + struct hostent *he; + struct hostent_data data; + (void) gethostbyname_r(name, he, &data); + + ],acx_which_gethostbyname_r=3, + [ +dnl acx_which_gethostbyname_r=0 + AC_TRY_COMPILE([ +# include + ], [ + char *name; + struct hostent *he, *res; + char *buffer = NULL; + int buflen = 2048; + int h_errnop; + (void) gethostbyname_r(name, he, buffer, buflen, &res, &h_errnop) + ],acx_which_gethostbyname_r=6, + + [ +dnl acx_which_gethostbyname_r=0 + AC_TRY_COMPILE([ +# include + ], [ + char *name; + struct hostent *he; + char *buffer = NULL; + int buflen = 2048; + int h_errnop; + (void) gethostbyname_r(name, he, buffer, buflen, &h_errnop) + ],acx_which_gethostbyname_r=5,acx_which_gethostbyname_r=0) + + ] + + ) + ] + ) + ]) + +if test $acx_which_gethostbyname_r -gt 0 ; then + AC_DEFINE_UNQUOTED([HAVE_GETHOSTBYNAME_R], $acx_which_gethostbyname_r, + [Number of parameters to gethostbyname_r or 0 if not available]) +fi + +]) + +dnl @synopsis ACX_HELP_STRING(OPTION,DESCRIPTION) +AC_DEFUN([ACX_HELP_STRING], + [ $1 builtin([substr],[ ],len($1))[$2]]) + + +dnl @synopsis ACX_FEATURE(ENABLE_OR_WITH,NAME[,VALUE]) +AC_DEFUN([ACX_FEATURE], + [echo "builtin([substr],[ ],len(--$1-$2))--$1-$2: ifelse($3,,[$]translit($1-$2,-,_),$3)"]) + diff --git a/check_nwc_health.php b/check_nwc_health.php index 9e5308b0..b08270cd 100644 --- a/check_nwc_health.php +++ b/check_nwc_health.php @@ -1,58 +1,58 @@ -$VAL) { - - # eth0_usage_in / out - if(preg_match('/^(.*?)_usage_in/', $NAME[$i])) { - $interface = preg_replace('/_.*$/', '', $NAME[$i]); - $ds_name[$num] = $interface.' usage'; - $opt[$num] = "--vertical-label \"Usage\" -l 0 -u 100 --title \"Interface Usage for $hostname - ".$interface."\" "; - $def[$num] = "DEF:percin=$RRDFILE[$i]:$DS[$i]:AVERAGE "; - $def[$num] .= "DEF:percout=".$RRDFILE[$i+1].":".$DS[$i+1].":AVERAGE "; - $def[$num] .= "LINE2:percin#00e060:\"in\t\" "; - $def[$num] .= "GPRINT:percin:LAST:\"%10.1lf %% last\" "; - $def[$num] .= "GPRINT:percin:AVERAGE:\"%7.1lf %% avg\" "; - $def[$num] .= "GPRINT:percin:MAX:\"%7.1lf %% max\\n\" "; - $def[$num] .= "LINE2:percout#0080e0:\"out\t\" "; - $def[$num] .= "GPRINT:percout:LAST:\"%10.1lf %% last\" "; - $def[$num] .= "GPRINT:percout:AVERAGE:\"%7.1lf %% avg\" "; - $def[$num] .= "GPRINT:percout:MAX:\"%7.1lf %% max\"\\n "; - $def[$num] .= "HRULE:$WARN[$num]$_WARNRULE "; - $def[$num] .= "HRULE:$CRIT[$num]$_CRITRULE "; - $num++; - } - - # eth0_traffic_in / out - if(preg_match('/^(.*?)_traffic_in/', $NAME[$i])) { - $interface = preg_replace('/_.*$/', '', $NAME[$i]); - $ds_name[$num] = $interface.' traffic'; - $opt[$num] = "--vertical-label \"Traffic\" -b 1024 --title \"Interface Traffic for $hostname - $interface\" "; - $def[$num] = "DEF:bitsin=$RRDFILE[$i]:$DS[$i]:AVERAGE "; - $def[$num] .= "DEF:bitsout=".$RRDFILE[$i+1].":".$DS[$i+1].":AVERAGE "; - $def[$num] .= "AREA:bitsin#00e060:\"in\t\" "; - $def[$num] .= "GPRINT:bitsin:LAST:\"%10.1lf %Sb/s last\" "; - $def[$num] .= "GPRINT:bitsin:AVERAGE:\"%7.1lf %Sb/s avg\" "; - $def[$num] .= "GPRINT:bitsin:MAX:\"%7.1lf %Sb/s max\\n\" "; - $def[$num] .= "CDEF:bitsminusout=0,bitsout,- "; - $def[$num] .= "AREA:bitsminusout#0080e0:\"out\t\" "; - $def[$num] .= "GPRINT:bitsout:LAST:\"%10.1lf %Sb/s last\" "; - $def[$num] .= "GPRINT:bitsout:AVERAGE:\"%7.1lf %Sb/s avg\" "; - $def[$num] .= "GPRINT:bitsout:MAX:\"%7.1lf %Sb/s max\\n\" "; - } -} - -?> +$VAL) { + + # eth0_usage_in / out + if(preg_match('/^(.*?)_usage_in/', $NAME[$i])) { + $interface = preg_replace('/_.*$/', '', $NAME[$i]); + $ds_name[$num] = $interface.' usage'; + $opt[$num] = "--vertical-label \"Usage\" -l 0 -u 100 --title \"Interface Usage for $hostname - ".$interface."\" "; + $def[$num] = "DEF:percin=$RRDFILE[$i]:$DS[$i]:AVERAGE "; + $def[$num] .= "DEF:percout=".$RRDFILE[$i+1].":".$DS[$i+1].":AVERAGE "; + $def[$num] .= "LINE2:percin#00e060:\"in\t\" "; + $def[$num] .= "GPRINT:percin:LAST:\"%10.1lf %% last\" "; + $def[$num] .= "GPRINT:percin:AVERAGE:\"%7.1lf %% avg\" "; + $def[$num] .= "GPRINT:percin:MAX:\"%7.1lf %% max\\n\" "; + $def[$num] .= "LINE2:percout#0080e0:\"out\t\" "; + $def[$num] .= "GPRINT:percout:LAST:\"%10.1lf %% last\" "; + $def[$num] .= "GPRINT:percout:AVERAGE:\"%7.1lf %% avg\" "; + $def[$num] .= "GPRINT:percout:MAX:\"%7.1lf %% max\"\\n "; + $def[$num] .= "HRULE:$WARN[$num]$_WARNRULE "; + $def[$num] .= "HRULE:$CRIT[$num]$_CRITRULE "; + $num++; + } + + # eth0_traffic_in / out + if(preg_match('/^(.*?)_traffic_in/', $NAME[$i])) { + $interface = preg_replace('/_.*$/', '', $NAME[$i]); + $ds_name[$num] = $interface.' traffic'; + $opt[$num] = "--vertical-label \"Traffic\" -b 1024 --title \"Interface Traffic for $hostname - $interface\" "; + $def[$num] = "DEF:bitsin=$RRDFILE[$i]:$DS[$i]:AVERAGE "; + $def[$num] .= "DEF:bitsout=".$RRDFILE[$i+1].":".$DS[$i+1].":AVERAGE "; + $def[$num] .= "AREA:bitsin#00e060:\"in\t\" "; + $def[$num] .= "GPRINT:bitsin:LAST:\"%10.1lf %Sb/s last\" "; + $def[$num] .= "GPRINT:bitsin:AVERAGE:\"%7.1lf %Sb/s avg\" "; + $def[$num] .= "GPRINT:bitsin:MAX:\"%7.1lf %Sb/s max\\n\" "; + $def[$num] .= "CDEF:bitsminusout=0,bitsout,- "; + $def[$num] .= "AREA:bitsminusout#0080e0:\"out\t\" "; + $def[$num] .= "GPRINT:bitsout:LAST:\"%10.1lf %Sb/s last\" "; + $def[$num] .= "GPRINT:bitsout:AVERAGE:\"%7.1lf %Sb/s avg\" "; + $def[$num] .= "GPRINT:bitsout:MAX:\"%7.1lf %Sb/s max\\n\" "; + } +} + +?> diff --git a/configure.ac b/configure.ac index a813ee66..f0bced37 100644 --- a/configure.ac +++ b/configure.ac @@ -1,115 +1,115 @@ -dnl Process this file with autoconf to produce a configure script. -AC_REVISION ($Revision: 1.150 $) -AC_PREREQ(2.58) -AC_INIT(check_nwc_health,2.6.5.2) -AM_INIT_AUTOMAKE([1.9 tar-pax]) -AC_CANONICAL_HOST - -RELEASE=1 -AC_SUBST(RELEASE) - -AC_PREFIX_DEFAULT(/usr/local/nagios) - -dnl Figure out how to invoke "install" and what install options to use. -AC_PROG_INSTALL -AC_SUBST(INSTALL) - -AC_PROG_MAKE_SET -AC_PROG_AWK - -WARRANTY="This plugin comes with ABSOLUTELY NO WARRANTY. You may redistribute\ncopies of the plugin under the terms of the GNU General Public License.\nFor more information about these matters, see the file named COPYING.\n" -AC_SUBST(WARRANTY) - -SUPPORT="Send email to gerhard.lausser@consol.de if you have questions\nregarding use of this software.\nPlease include version information with all correspondence (when possible,\nuse output from the --version option of the plugin itself).\n" -AC_SUBST(SUPPORT) - -AC_ARG_WITH(nagios_user, - ACX_HELP_STRING([--with-nagios-user=USER], - [set user name to run nagios]), - with_nagios_user=$withval, - with_nagios_user=nagios) -AC_ARG_WITH(nagios_group, - ACX_HELP_STRING([--with-nagios-group=GROUP], - [set group name to run nagios]), - with_nagios_group=$withval, - with_nagios_group=nagios) -AC_SUBST(with_nagios_user) -AC_SUBST(with_nagios_group) -INSTALL_OPTS="-o $with_nagios_user -g $with_nagios_group" -AC_SUBST(INSTALL_OPTS) -AC_ARG_WITH(noinst_level, - ACX_HELP_STRING([--with-noinst-level=LEVEL], - [error level if nwc_health is not installed]), - with_noinst_level=$withval, - with_noinst_level=unknown) -AC_SUBST(NOINSTLEVEL, $with_noinst_level) -AC_ARG_WITH(degrees, - ACX_HELP_STRING([--with-degrees=UNIT], - [which temperature unit to use. (celsius or fahrenheit)]), - with_degrees=$withval, - with_degrees=unknown) -case "$with_degrees" in - fahrenheit) - AC_SUBST(CELSIUS, 0) - ;; - *) - AC_SUBST(CELSIUS, 1) - ;; -esac -AC_ARG_ENABLE([perfdata], -[ --enable-perfdata wether to output perfdata (default=no)], ,enable_perfdata=no) -if test x"$enable_perfdata" = xyes ; then - AC_SUBST(PERFDATA, 1) -else - AC_SUBST(PERFDATA, 0) -fi -AC_ARG_ENABLE([extendedinfo], -[ --enable-extendedinfo wether to output extended info (default=no)], ,enable_extendedinfo=no) -if test x"$enable_extendedinfo" = xyes ; then - AC_SUBST(EXTENDEDINFO, 1) -else - AC_SUBST(EXTENDEDINFO, 0) -fi -AC_ARG_ENABLE([hwinfo], -[ --disable-hwinfo wether to output model desc., serial no., bios version (default=yes)], ,enable_hwinfo=yes) - -if test x"$enable_hwinfo" = xyes ; then - AC_SUBST(HWINFO, 1) -else - AC_SUBST(HWINFO, 0) -fi - - -case "$host_os" in - *hp*) - defaulttrustedpath=/bin:/sbin:/usr/bin:/usr/sbin:/usr/contrib/bin - ;; - *) - defaulttrustedpath=/bin:/sbin:/usr/bin:/usr/sbin - ;; -esac - -EXTRAS= -dnl PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/etc:/usr/local/bin:/usr/local/sbin:$PATH - -dnl Checks for programs. -AC_PATH_PROG(SH,sh) -AC_PATH_PROG(PERL,perl) - -dnl allow them to override the path of perl -AC_ARG_WITH(perl, - ACX_HELP_STRING([--with-perl=PATH], - [sets path to perl executable]), - with_perl=$withval,with_perl=$PERL) -AC_SUBST(PERL, $with_perl) - -AC_OUTPUT(Makefile plugins-scripts/Makefile plugins-scripts/subst) - -ACX_FEATURE([with],[perl]) -ACX_FEATURE([with],[nagios-user]) -ACX_FEATURE([with],[nagios-group]) -ACX_FEATURE([with],[noinst-level]) -ACX_FEATURE([with],[degrees]) -ACX_FEATURE([enable],[perfdata]) -ACX_FEATURE([enable],[extendedinfo]) -ACX_FEATURE([enable],[hwinfo]) +dnl Process this file with autoconf to produce a configure script. +AC_REVISION ($Revision: 1.150 $) +AC_PREREQ(2.58) +AC_INIT(check_nwc_health,2.6.5.2) +AM_INIT_AUTOMAKE([1.9 tar-pax]) +AC_CANONICAL_HOST + +RELEASE=1 +AC_SUBST(RELEASE) + +AC_PREFIX_DEFAULT(/usr/local/nagios) + +dnl Figure out how to invoke "install" and what install options to use. +AC_PROG_INSTALL +AC_SUBST(INSTALL) + +AC_PROG_MAKE_SET +AC_PROG_AWK + +WARRANTY="This plugin comes with ABSOLUTELY NO WARRANTY. You may redistribute\ncopies of the plugin under the terms of the GNU General Public License.\nFor more information about these matters, see the file named COPYING.\n" +AC_SUBST(WARRANTY) + +SUPPORT="Send email to gerhard.lausser@consol.de if you have questions\nregarding use of this software.\nPlease include version information with all correspondence (when possible,\nuse output from the --version option of the plugin itself).\n" +AC_SUBST(SUPPORT) + +AC_ARG_WITH(nagios_user, + ACX_HELP_STRING([--with-nagios-user=USER], + [set user name to run nagios]), + with_nagios_user=$withval, + with_nagios_user=nagios) +AC_ARG_WITH(nagios_group, + ACX_HELP_STRING([--with-nagios-group=GROUP], + [set group name to run nagios]), + with_nagios_group=$withval, + with_nagios_group=nagios) +AC_SUBST(with_nagios_user) +AC_SUBST(with_nagios_group) +INSTALL_OPTS="-o $with_nagios_user -g $with_nagios_group" +AC_SUBST(INSTALL_OPTS) +AC_ARG_WITH(noinst_level, + ACX_HELP_STRING([--with-noinst-level=LEVEL], + [error level if nwc_health is not installed]), + with_noinst_level=$withval, + with_noinst_level=unknown) +AC_SUBST(NOINSTLEVEL, $with_noinst_level) +AC_ARG_WITH(degrees, + ACX_HELP_STRING([--with-degrees=UNIT], + [which temperature unit to use. (celsius or fahrenheit)]), + with_degrees=$withval, + with_degrees=unknown) +case "$with_degrees" in + fahrenheit) + AC_SUBST(CELSIUS, 0) + ;; + *) + AC_SUBST(CELSIUS, 1) + ;; +esac +AC_ARG_ENABLE([perfdata], +[ --enable-perfdata wether to output perfdata (default=no)], ,enable_perfdata=no) +if test x"$enable_perfdata" = xyes ; then + AC_SUBST(PERFDATA, 1) +else + AC_SUBST(PERFDATA, 0) +fi +AC_ARG_ENABLE([extendedinfo], +[ --enable-extendedinfo wether to output extended info (default=no)], ,enable_extendedinfo=no) +if test x"$enable_extendedinfo" = xyes ; then + AC_SUBST(EXTENDEDINFO, 1) +else + AC_SUBST(EXTENDEDINFO, 0) +fi +AC_ARG_ENABLE([hwinfo], +[ --disable-hwinfo wether to output model desc., serial no., bios version (default=yes)], ,enable_hwinfo=yes) + +if test x"$enable_hwinfo" = xyes ; then + AC_SUBST(HWINFO, 1) +else + AC_SUBST(HWINFO, 0) +fi + + +case "$host_os" in + *hp*) + defaulttrustedpath=/bin:/sbin:/usr/bin:/usr/sbin:/usr/contrib/bin + ;; + *) + defaulttrustedpath=/bin:/sbin:/usr/bin:/usr/sbin + ;; +esac + +EXTRAS= +dnl PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/etc:/usr/local/bin:/usr/local/sbin:$PATH + +dnl Checks for programs. +AC_PATH_PROG(SH,sh) +AC_PATH_PROG(PERL,perl) + +dnl allow them to override the path of perl +AC_ARG_WITH(perl, + ACX_HELP_STRING([--with-perl=PATH], + [sets path to perl executable]), + with_perl=$withval,with_perl=$PERL) +AC_SUBST(PERL, $with_perl) + +AC_OUTPUT(Makefile plugins-scripts/Makefile plugins-scripts/subst) + +ACX_FEATURE([with],[perl]) +ACX_FEATURE([with],[nagios-user]) +ACX_FEATURE([with],[nagios-group]) +ACX_FEATURE([with],[noinst-level]) +ACX_FEATURE([with],[degrees]) +ACX_FEATURE([enable],[perfdata]) +ACX_FEATURE([enable],[extendedinfo]) +ACX_FEATURE([enable],[hwinfo]) diff --git a/install-sh b/install-sh index fd651cdb..377bb868 100644 --- a/install-sh +++ b/install-sh @@ -1,527 +1,527 @@ -#!/bin/sh -# install - install a program, script, or datafile - -scriptversion=2011-11-20.07; # UTC - -# This originates from X11R5 (mit/util/scripts/install.sh), which was -# later released in X11R6 (xc/config/util/install.sh) with the -# following copyright and license. -# -# Copyright (C) 1994 X Consortium -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to -# deal in the Software without restriction, including without limitation the -# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -# sell copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- -# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# -# Except as contained in this notice, the name of the X Consortium shall not -# be used in advertising or otherwise to promote the sale, use or other deal- -# ings in this Software without prior written authorization from the X Consor- -# tium. -# -# -# FSF changes to this file are in the public domain. -# -# Calling this script install-sh is preferred over install.sh, to prevent -# 'make' implicit rules from creating a file called install from it -# when there is no Makefile. -# -# This script is compatible with the BSD install script, but was written -# from scratch. - -nl=' -' -IFS=" "" $nl" - -# set DOITPROG to echo to test this script - -# Don't use :- since 4.3BSD and earlier shells don't like it. -doit=${DOITPROG-} -if test -z "$doit"; then - doit_exec=exec -else - doit_exec=$doit -fi - -# Put in absolute file names if you don't have them in your path; -# or use environment vars. - -chgrpprog=${CHGRPPROG-chgrp} -chmodprog=${CHMODPROG-chmod} -chownprog=${CHOWNPROG-chown} -cmpprog=${CMPPROG-cmp} -cpprog=${CPPROG-cp} -mkdirprog=${MKDIRPROG-mkdir} -mvprog=${MVPROG-mv} -rmprog=${RMPROG-rm} -stripprog=${STRIPPROG-strip} - -posix_glob='?' -initialize_posix_glob=' - test "$posix_glob" != "?" || { - if (set -f) 2>/dev/null; then - posix_glob= - else - posix_glob=: - fi - } -' - -posix_mkdir= - -# Desired mode of installed file. -mode=0755 - -chgrpcmd= -chmodcmd=$chmodprog -chowncmd= -mvcmd=$mvprog -rmcmd="$rmprog -f" -stripcmd= - -src= -dst= -dir_arg= -dst_arg= - -copy_on_change=false -no_target_directory= - -usage="\ -Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE - or: $0 [OPTION]... SRCFILES... DIRECTORY - or: $0 [OPTION]... -t DIRECTORY SRCFILES... - or: $0 [OPTION]... -d DIRECTORIES... - -In the 1st form, copy SRCFILE to DSTFILE. -In the 2nd and 3rd, copy all SRCFILES to DIRECTORY. -In the 4th, create DIRECTORIES. - -Options: - --help display this help and exit. - --version display version info and exit. - - -c (ignored) - -C install only if different (preserve the last data modification time) - -d create directories instead of installing files. - -g GROUP $chgrpprog installed files to GROUP. - -m MODE $chmodprog installed files to MODE. - -o USER $chownprog installed files to USER. - -s $stripprog installed files. - -t DIRECTORY install into DIRECTORY. - -T report an error if DSTFILE is a directory. - -Environment variables override the default commands: - CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG - RMPROG STRIPPROG -" - -while test $# -ne 0; do - case $1 in - -c) ;; - - -C) copy_on_change=true;; - - -d) dir_arg=true;; - - -g) chgrpcmd="$chgrpprog $2" - shift;; - - --help) echo "$usage"; exit $?;; - - -m) mode=$2 - case $mode in - *' '* | *' '* | *' -'* | *'*'* | *'?'* | *'['*) - echo "$0: invalid mode: $mode" >&2 - exit 1;; - esac - shift;; - - -o) chowncmd="$chownprog $2" - shift;; - - -s) stripcmd=$stripprog;; - - -t) dst_arg=$2 - # Protect names problematic for 'test' and other utilities. - case $dst_arg in - -* | [=\(\)!]) dst_arg=./$dst_arg;; - esac - shift;; - - -T) no_target_directory=true;; - - --version) echo "$0 $scriptversion"; exit $?;; - - --) shift - break;; - - -*) echo "$0: invalid option: $1" >&2 - exit 1;; - - *) break;; - esac - shift -done - -if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then - # When -d is used, all remaining arguments are directories to create. - # When -t is used, the destination is already specified. - # Otherwise, the last argument is the destination. Remove it from $@. - for arg - do - if test -n "$dst_arg"; then - # $@ is not empty: it contains at least $arg. - set fnord "$@" "$dst_arg" - shift # fnord - fi - shift # arg - dst_arg=$arg - # Protect names problematic for 'test' and other utilities. - case $dst_arg in - -* | [=\(\)!]) dst_arg=./$dst_arg;; - esac - done -fi - -if test $# -eq 0; then - if test -z "$dir_arg"; then - echo "$0: no input file specified." >&2 - exit 1 - fi - # It's OK to call 'install-sh -d' without argument. - # This can happen when creating conditional directories. - exit 0 -fi - -if test -z "$dir_arg"; then - do_exit='(exit $ret); exit $ret' - trap "ret=129; $do_exit" 1 - trap "ret=130; $do_exit" 2 - trap "ret=141; $do_exit" 13 - trap "ret=143; $do_exit" 15 - - # Set umask so as not to create temps with too-generous modes. - # However, 'strip' requires both read and write access to temps. - case $mode in - # Optimize common cases. - *644) cp_umask=133;; - *755) cp_umask=22;; - - *[0-7]) - if test -z "$stripcmd"; then - u_plus_rw= - else - u_plus_rw='% 200' - fi - cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; - *) - if test -z "$stripcmd"; then - u_plus_rw= - else - u_plus_rw=,u+rw - fi - cp_umask=$mode$u_plus_rw;; - esac -fi - -for src -do - # Protect names problematic for 'test' and other utilities. - case $src in - -* | [=\(\)!]) src=./$src;; - esac - - if test -n "$dir_arg"; then - dst=$src - dstdir=$dst - test -d "$dstdir" - dstdir_status=$? - else - - # Waiting for this to be detected by the "$cpprog $src $dsttmp" command - # might cause directories to be created, which would be especially bad - # if $src (and thus $dsttmp) contains '*'. - if test ! -f "$src" && test ! -d "$src"; then - echo "$0: $src does not exist." >&2 - exit 1 - fi - - if test -z "$dst_arg"; then - echo "$0: no destination specified." >&2 - exit 1 - fi - dst=$dst_arg - - # If destination is a directory, append the input filename; won't work - # if double slashes aren't ignored. - if test -d "$dst"; then - if test -n "$no_target_directory"; then - echo "$0: $dst_arg: Is a directory" >&2 - exit 1 - fi - dstdir=$dst - dst=$dstdir/`basename "$src"` - dstdir_status=0 - else - # Prefer dirname, but fall back on a substitute if dirname fails. - dstdir=` - (dirname "$dst") 2>/dev/null || - expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$dst" : 'X\(//\)[^/]' \| \ - X"$dst" : 'X\(//\)$' \| \ - X"$dst" : 'X\(/\)' \| . 2>/dev/null || - echo X"$dst" | - sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ - s//\1/ - q - } - /^X\(\/\/\)[^/].*/{ - s//\1/ - q - } - /^X\(\/\/\)$/{ - s//\1/ - q - } - /^X\(\/\).*/{ - s//\1/ - q - } - s/.*/./; q' - ` - - test -d "$dstdir" - dstdir_status=$? - fi - fi - - obsolete_mkdir_used=false - - if test $dstdir_status != 0; then - case $posix_mkdir in - '') - # Create intermediate dirs using mode 755 as modified by the umask. - # This is like FreeBSD 'install' as of 1997-10-28. - umask=`umask` - case $stripcmd.$umask in - # Optimize common cases. - *[2367][2367]) mkdir_umask=$umask;; - .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; - - *[0-7]) - mkdir_umask=`expr $umask + 22 \ - - $umask % 100 % 40 + $umask % 20 \ - - $umask % 10 % 4 + $umask % 2 - `;; - *) mkdir_umask=$umask,go-w;; - esac - - # With -d, create the new directory with the user-specified mode. - # Otherwise, rely on $mkdir_umask. - if test -n "$dir_arg"; then - mkdir_mode=-m$mode - else - mkdir_mode= - fi - - posix_mkdir=false - case $umask in - *[123567][0-7][0-7]) - # POSIX mkdir -p sets u+wx bits regardless of umask, which - # is incompatible with FreeBSD 'install' when (umask & 300) != 0. - ;; - *) - tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ - trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 - - if (umask $mkdir_umask && - exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 - then - if test -z "$dir_arg" || { - # Check for POSIX incompatibilities with -m. - # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or - # other-writable bit of parent directory when it shouldn't. - # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. - ls_ld_tmpdir=`ls -ld "$tmpdir"` - case $ls_ld_tmpdir in - d????-?r-*) different_mode=700;; - d????-?--*) different_mode=755;; - *) false;; - esac && - $mkdirprog -m$different_mode -p -- "$tmpdir" && { - ls_ld_tmpdir_1=`ls -ld "$tmpdir"` - test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" - } - } - then posix_mkdir=: - fi - rmdir "$tmpdir/d" "$tmpdir" - else - # Remove any dirs left behind by ancient mkdir implementations. - rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null - fi - trap '' 0;; - esac;; - esac - - if - $posix_mkdir && ( - umask $mkdir_umask && - $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" - ) - then : - else - - # The umask is ridiculous, or mkdir does not conform to POSIX, - # or it failed possibly due to a race condition. Create the - # directory the slow way, step by step, checking for races as we go. - - case $dstdir in - /*) prefix='/';; - [-=\(\)!]*) prefix='./';; - *) prefix='';; - esac - - eval "$initialize_posix_glob" - - oIFS=$IFS - IFS=/ - $posix_glob set -f - set fnord $dstdir - shift - $posix_glob set +f - IFS=$oIFS - - prefixes= - - for d - do - test X"$d" = X && continue - - prefix=$prefix$d - if test -d "$prefix"; then - prefixes= - else - if $posix_mkdir; then - (umask=$mkdir_umask && - $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break - # Don't fail if two instances are running concurrently. - test -d "$prefix" || exit 1 - else - case $prefix in - *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; - *) qprefix=$prefix;; - esac - prefixes="$prefixes '$qprefix'" - fi - fi - prefix=$prefix/ - done - - if test -n "$prefixes"; then - # Don't fail if two instances are running concurrently. - (umask $mkdir_umask && - eval "\$doit_exec \$mkdirprog $prefixes") || - test -d "$dstdir" || exit 1 - obsolete_mkdir_used=true - fi - fi - fi - - if test -n "$dir_arg"; then - { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && - { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && - { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || - test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 - else - - # Make a couple of temp file names in the proper directory. - dsttmp=$dstdir/_inst.$$_ - rmtmp=$dstdir/_rm.$$_ - - # Trap to clean up those temp files at exit. - trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 - - # Copy the file name to the temp name. - (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && - - # and set any options; do chmod last to preserve setuid bits. - # - # If any of these fail, we abort the whole thing. If we want to - # ignore errors from any of these, just make sure not to ignore - # errors from the above "$doit $cpprog $src $dsttmp" command. - # - { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && - { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && - { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && - { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && - - # If -C, don't bother to copy if it wouldn't change the file. - if $copy_on_change && - old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && - new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && - - eval "$initialize_posix_glob" && - $posix_glob set -f && - set X $old && old=:$2:$4:$5:$6 && - set X $new && new=:$2:$4:$5:$6 && - $posix_glob set +f && - - test "$old" = "$new" && - $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 - then - rm -f "$dsttmp" - else - # Rename the file to the real destination. - $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || - - # The rename failed, perhaps because mv can't rename something else - # to itself, or perhaps because mv is so ancient that it does not - # support -f. - { - # Now remove or move aside any old file at destination location. - # We try this two ways since rm can't unlink itself on some - # systems and the destination file might be busy for other - # reasons. In this case, the final cleanup might fail but the new - # file should still install successfully. - { - test ! -f "$dst" || - $doit $rmcmd -f "$dst" 2>/dev/null || - { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && - { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } - } || - { echo "$0: cannot unlink or rename $dst" >&2 - (exit 1); exit 1 - } - } && - - # Now rename the file to the real destination. - $doit $mvcmd "$dsttmp" "$dst" - } - fi || exit 1 - - trap '' 0 - fi -done - -# Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) -# time-stamp-start: "scriptversion=" -# time-stamp-format: "%:y-%02m-%02d.%02H" -# time-stamp-time-zone: "UTC" -# time-stamp-end: "; # UTC" -# End: +#!/bin/sh +# install - install a program, script, or datafile + +scriptversion=2011-11-20.07; # UTC + +# This originates from X11R5 (mit/util/scripts/install.sh), which was +# later released in X11R6 (xc/config/util/install.sh) with the +# following copyright and license. +# +# Copyright (C) 1994 X Consortium +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- +# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# Except as contained in this notice, the name of the X Consortium shall not +# be used in advertising or otherwise to promote the sale, use or other deal- +# ings in this Software without prior written authorization from the X Consor- +# tium. +# +# +# FSF changes to this file are in the public domain. +# +# Calling this script install-sh is preferred over install.sh, to prevent +# 'make' implicit rules from creating a file called install from it +# when there is no Makefile. +# +# This script is compatible with the BSD install script, but was written +# from scratch. + +nl=' +' +IFS=" "" $nl" + +# set DOITPROG to echo to test this script + +# Don't use :- since 4.3BSD and earlier shells don't like it. +doit=${DOITPROG-} +if test -z "$doit"; then + doit_exec=exec +else + doit_exec=$doit +fi + +# Put in absolute file names if you don't have them in your path; +# or use environment vars. + +chgrpprog=${CHGRPPROG-chgrp} +chmodprog=${CHMODPROG-chmod} +chownprog=${CHOWNPROG-chown} +cmpprog=${CMPPROG-cmp} +cpprog=${CPPROG-cp} +mkdirprog=${MKDIRPROG-mkdir} +mvprog=${MVPROG-mv} +rmprog=${RMPROG-rm} +stripprog=${STRIPPROG-strip} + +posix_glob='?' +initialize_posix_glob=' + test "$posix_glob" != "?" || { + if (set -f) 2>/dev/null; then + posix_glob= + else + posix_glob=: + fi + } +' + +posix_mkdir= + +# Desired mode of installed file. +mode=0755 + +chgrpcmd= +chmodcmd=$chmodprog +chowncmd= +mvcmd=$mvprog +rmcmd="$rmprog -f" +stripcmd= + +src= +dst= +dir_arg= +dst_arg= + +copy_on_change=false +no_target_directory= + +usage="\ +Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE + or: $0 [OPTION]... SRCFILES... DIRECTORY + or: $0 [OPTION]... -t DIRECTORY SRCFILES... + or: $0 [OPTION]... -d DIRECTORIES... + +In the 1st form, copy SRCFILE to DSTFILE. +In the 2nd and 3rd, copy all SRCFILES to DIRECTORY. +In the 4th, create DIRECTORIES. + +Options: + --help display this help and exit. + --version display version info and exit. + + -c (ignored) + -C install only if different (preserve the last data modification time) + -d create directories instead of installing files. + -g GROUP $chgrpprog installed files to GROUP. + -m MODE $chmodprog installed files to MODE. + -o USER $chownprog installed files to USER. + -s $stripprog installed files. + -t DIRECTORY install into DIRECTORY. + -T report an error if DSTFILE is a directory. + +Environment variables override the default commands: + CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG + RMPROG STRIPPROG +" + +while test $# -ne 0; do + case $1 in + -c) ;; + + -C) copy_on_change=true;; + + -d) dir_arg=true;; + + -g) chgrpcmd="$chgrpprog $2" + shift;; + + --help) echo "$usage"; exit $?;; + + -m) mode=$2 + case $mode in + *' '* | *' '* | *' +'* | *'*'* | *'?'* | *'['*) + echo "$0: invalid mode: $mode" >&2 + exit 1;; + esac + shift;; + + -o) chowncmd="$chownprog $2" + shift;; + + -s) stripcmd=$stripprog;; + + -t) dst_arg=$2 + # Protect names problematic for 'test' and other utilities. + case $dst_arg in + -* | [=\(\)!]) dst_arg=./$dst_arg;; + esac + shift;; + + -T) no_target_directory=true;; + + --version) echo "$0 $scriptversion"; exit $?;; + + --) shift + break;; + + -*) echo "$0: invalid option: $1" >&2 + exit 1;; + + *) break;; + esac + shift +done + +if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then + # When -d is used, all remaining arguments are directories to create. + # When -t is used, the destination is already specified. + # Otherwise, the last argument is the destination. Remove it from $@. + for arg + do + if test -n "$dst_arg"; then + # $@ is not empty: it contains at least $arg. + set fnord "$@" "$dst_arg" + shift # fnord + fi + shift # arg + dst_arg=$arg + # Protect names problematic for 'test' and other utilities. + case $dst_arg in + -* | [=\(\)!]) dst_arg=./$dst_arg;; + esac + done +fi + +if test $# -eq 0; then + if test -z "$dir_arg"; then + echo "$0: no input file specified." >&2 + exit 1 + fi + # It's OK to call 'install-sh -d' without argument. + # This can happen when creating conditional directories. + exit 0 +fi + +if test -z "$dir_arg"; then + do_exit='(exit $ret); exit $ret' + trap "ret=129; $do_exit" 1 + trap "ret=130; $do_exit" 2 + trap "ret=141; $do_exit" 13 + trap "ret=143; $do_exit" 15 + + # Set umask so as not to create temps with too-generous modes. + # However, 'strip' requires both read and write access to temps. + case $mode in + # Optimize common cases. + *644) cp_umask=133;; + *755) cp_umask=22;; + + *[0-7]) + if test -z "$stripcmd"; then + u_plus_rw= + else + u_plus_rw='% 200' + fi + cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; + *) + if test -z "$stripcmd"; then + u_plus_rw= + else + u_plus_rw=,u+rw + fi + cp_umask=$mode$u_plus_rw;; + esac +fi + +for src +do + # Protect names problematic for 'test' and other utilities. + case $src in + -* | [=\(\)!]) src=./$src;; + esac + + if test -n "$dir_arg"; then + dst=$src + dstdir=$dst + test -d "$dstdir" + dstdir_status=$? + else + + # Waiting for this to be detected by the "$cpprog $src $dsttmp" command + # might cause directories to be created, which would be especially bad + # if $src (and thus $dsttmp) contains '*'. + if test ! -f "$src" && test ! -d "$src"; then + echo "$0: $src does not exist." >&2 + exit 1 + fi + + if test -z "$dst_arg"; then + echo "$0: no destination specified." >&2 + exit 1 + fi + dst=$dst_arg + + # If destination is a directory, append the input filename; won't work + # if double slashes aren't ignored. + if test -d "$dst"; then + if test -n "$no_target_directory"; then + echo "$0: $dst_arg: Is a directory" >&2 + exit 1 + fi + dstdir=$dst + dst=$dstdir/`basename "$src"` + dstdir_status=0 + else + # Prefer dirname, but fall back on a substitute if dirname fails. + dstdir=` + (dirname "$dst") 2>/dev/null || + expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$dst" : 'X\(//\)[^/]' \| \ + X"$dst" : 'X\(//\)$' \| \ + X"$dst" : 'X\(/\)' \| . 2>/dev/null || + echo X"$dst" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q' + ` + + test -d "$dstdir" + dstdir_status=$? + fi + fi + + obsolete_mkdir_used=false + + if test $dstdir_status != 0; then + case $posix_mkdir in + '') + # Create intermediate dirs using mode 755 as modified by the umask. + # This is like FreeBSD 'install' as of 1997-10-28. + umask=`umask` + case $stripcmd.$umask in + # Optimize common cases. + *[2367][2367]) mkdir_umask=$umask;; + .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; + + *[0-7]) + mkdir_umask=`expr $umask + 22 \ + - $umask % 100 % 40 + $umask % 20 \ + - $umask % 10 % 4 + $umask % 2 + `;; + *) mkdir_umask=$umask,go-w;; + esac + + # With -d, create the new directory with the user-specified mode. + # Otherwise, rely on $mkdir_umask. + if test -n "$dir_arg"; then + mkdir_mode=-m$mode + else + mkdir_mode= + fi + + posix_mkdir=false + case $umask in + *[123567][0-7][0-7]) + # POSIX mkdir -p sets u+wx bits regardless of umask, which + # is incompatible with FreeBSD 'install' when (umask & 300) != 0. + ;; + *) + tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ + trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 + + if (umask $mkdir_umask && + exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 + then + if test -z "$dir_arg" || { + # Check for POSIX incompatibilities with -m. + # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or + # other-writable bit of parent directory when it shouldn't. + # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. + ls_ld_tmpdir=`ls -ld "$tmpdir"` + case $ls_ld_tmpdir in + d????-?r-*) different_mode=700;; + d????-?--*) different_mode=755;; + *) false;; + esac && + $mkdirprog -m$different_mode -p -- "$tmpdir" && { + ls_ld_tmpdir_1=`ls -ld "$tmpdir"` + test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" + } + } + then posix_mkdir=: + fi + rmdir "$tmpdir/d" "$tmpdir" + else + # Remove any dirs left behind by ancient mkdir implementations. + rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null + fi + trap '' 0;; + esac;; + esac + + if + $posix_mkdir && ( + umask $mkdir_umask && + $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" + ) + then : + else + + # The umask is ridiculous, or mkdir does not conform to POSIX, + # or it failed possibly due to a race condition. Create the + # directory the slow way, step by step, checking for races as we go. + + case $dstdir in + /*) prefix='/';; + [-=\(\)!]*) prefix='./';; + *) prefix='';; + esac + + eval "$initialize_posix_glob" + + oIFS=$IFS + IFS=/ + $posix_glob set -f + set fnord $dstdir + shift + $posix_glob set +f + IFS=$oIFS + + prefixes= + + for d + do + test X"$d" = X && continue + + prefix=$prefix$d + if test -d "$prefix"; then + prefixes= + else + if $posix_mkdir; then + (umask=$mkdir_umask && + $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break + # Don't fail if two instances are running concurrently. + test -d "$prefix" || exit 1 + else + case $prefix in + *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; + *) qprefix=$prefix;; + esac + prefixes="$prefixes '$qprefix'" + fi + fi + prefix=$prefix/ + done + + if test -n "$prefixes"; then + # Don't fail if two instances are running concurrently. + (umask $mkdir_umask && + eval "\$doit_exec \$mkdirprog $prefixes") || + test -d "$dstdir" || exit 1 + obsolete_mkdir_used=true + fi + fi + fi + + if test -n "$dir_arg"; then + { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && + { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && + { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || + test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 + else + + # Make a couple of temp file names in the proper directory. + dsttmp=$dstdir/_inst.$$_ + rmtmp=$dstdir/_rm.$$_ + + # Trap to clean up those temp files at exit. + trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 + + # Copy the file name to the temp name. + (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && + + # and set any options; do chmod last to preserve setuid bits. + # + # If any of these fail, we abort the whole thing. If we want to + # ignore errors from any of these, just make sure not to ignore + # errors from the above "$doit $cpprog $src $dsttmp" command. + # + { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && + { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && + { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && + { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && + + # If -C, don't bother to copy if it wouldn't change the file. + if $copy_on_change && + old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && + new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && + + eval "$initialize_posix_glob" && + $posix_glob set -f && + set X $old && old=:$2:$4:$5:$6 && + set X $new && new=:$2:$4:$5:$6 && + $posix_glob set +f && + + test "$old" = "$new" && + $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 + then + rm -f "$dsttmp" + else + # Rename the file to the real destination. + $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || + + # The rename failed, perhaps because mv can't rename something else + # to itself, or perhaps because mv is so ancient that it does not + # support -f. + { + # Now remove or move aside any old file at destination location. + # We try this two ways since rm can't unlink itself on some + # systems and the destination file might be busy for other + # reasons. In this case, the final cleanup might fail but the new + # file should still install successfully. + { + test ! -f "$dst" || + $doit $rmcmd -f "$dst" 2>/dev/null || + { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && + { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } + } || + { echo "$0: cannot unlink or rename $dst" >&2 + (exit 1); exit 1 + } + } && + + # Now rename the file to the real destination. + $doit $mvcmd "$dsttmp" "$dst" + } + fi || exit 1 + + trap '' 0 + fi +done + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-time-zone: "UTC" +# time-stamp-end: "; # UTC" +# End: diff --git a/plugins-scripts/Classes/AVOS/Component/ConnectionSubsystem.pm b/plugins-scripts/Classes/AVOS/Component/ConnectionSubsystem.pm index 2fe5c31d..c0f5ae65 100644 --- a/plugins-scripts/Classes/AVOS/Component/ConnectionSubsystem.pm +++ b/plugins-scripts/Classes/AVOS/Component/ConnectionSubsystem.pm @@ -1,19 +1,13 @@ package Classes::AVOS::Component::ConnectionSubsystem; our @ISA = qw(Classes::AVOS); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } diff --git a/plugins-scripts/Classes/AVOS/Component/CpuSubsystem.pm b/plugins-scripts/Classes/AVOS/Component/CpuSubsystem.pm index d652d362..d5ccb79d 100644 --- a/plugins-scripts/Classes/AVOS/Component/CpuSubsystem.pm +++ b/plugins-scripts/Classes/AVOS/Component/CpuSubsystem.pm @@ -1,20 +1,13 @@ package Classes::AVOS::Component::CpuSubsystem; our @ISA = qw(Classes::AVOS); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - cpus => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } @@ -62,18 +55,13 @@ sub dump { package Classes::AVOS::Component::CpuSubsystem::Cpu; our @ISA = qw(Classes::AVOS::Component::CpuSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; my %params = @_; - my $self = { - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; foreach (qw(sgProxyCpuCoreUpTime sgProxyCpuCoreBusyTime sgProxyCpuCoreIdleTime sgProxyCpuCoreUpTimeSinceLastAccess sgProxyCpuCoreBusyTimeSinceLastAccess @@ -124,18 +112,13 @@ sub dump { package Classes::AVOS::Component::CpuSubsystem::DevCpu; our @ISA = qw(Classes::AVOS::Component::CpuSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; my %params = @_; - my $self = { - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; foreach (qw(deviceUsageIndex deviceUsageTrapEnabled deviceUsageName deviceUsagePercent deviceUsageHigh deviceUsageStatus deviceUsageTime)) { if (exists $params{$_}) { diff --git a/plugins-scripts/Classes/AVOS/Component/KeySubsystem.pm b/plugins-scripts/Classes/AVOS/Component/KeySubsystem.pm index 48c98c56..c74cc91d 100644 --- a/plugins-scripts/Classes/AVOS/Component/KeySubsystem.pm +++ b/plugins-scripts/Classes/AVOS/Component/KeySubsystem.pm @@ -1,19 +1,13 @@ package Classes::AVOS::Component::KeySubsystem; our @ISA = qw(Classes::AVOS); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } diff --git a/plugins-scripts/Classes/AVOS/Component/MemSubsystem.pm b/plugins-scripts/Classes/AVOS/Component/MemSubsystem.pm index a6319a3f..ae7b1593 100644 --- a/plugins-scripts/Classes/AVOS/Component/MemSubsystem.pm +++ b/plugins-scripts/Classes/AVOS/Component/MemSubsystem.pm @@ -1,22 +1,13 @@ package Classes::AVOS::Component::MemSubsystem; our @ISA = qw(Classes::AVOS); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - mems => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } @@ -55,13 +46,12 @@ sub init { } } + package Classes::AVOS::Component::MemSubsystem::AVOS3; our @ISA = qw(Classes::AVOS::Component::MemSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - sub check { my $self = shift; my $errorfound = 0; diff --git a/plugins-scripts/Classes/AVOS/Component/SecuritySubsystem.pm b/plugins-scripts/Classes/AVOS/Component/SecuritySubsystem.pm index b022d823..7719249e 100644 --- a/plugins-scripts/Classes/AVOS/Component/SecuritySubsystem.pm +++ b/plugins-scripts/Classes/AVOS/Component/SecuritySubsystem.pm @@ -1,19 +1,13 @@ package Classes::AVOS::Component::SecuritySubsystem; our @ISA = qw(Classes::AVOS); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } diff --git a/plugins-scripts/Classes/BGP/Component/PeerSubsystem.pm b/plugins-scripts/Classes/BGP/Component/PeerSubsystem.pm index 5c8cba3c..494927f2 100644 --- a/plugins-scripts/Classes/BGP/Component/PeerSubsystem.pm +++ b/plugins-scripts/Classes/BGP/Component/PeerSubsystem.pm @@ -1,6 +1,5 @@ package Classes::BGP::Component::PeerSubsystem; our @ISA = qw(Classes::BGP); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; @@ -58,15 +57,9 @@ our $errorcodes = { sub new { my $class = shift; - my %params = @_; - my $self = { - peers => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } @@ -158,11 +151,9 @@ sub dump { package Classes::BGP::Component::PeerSubsystem::Peer; our @ISA = qw(Classes::BGP::Component::PeerSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - sub new { my $class = shift; my %params = @_; diff --git a/plugins-scripts/Classes/Bluecoat.pm b/plugins-scripts/Classes/Bluecoat.pm index eeebb497..b0d3171a 100644 --- a/plugins-scripts/Classes/Bluecoat.pm +++ b/plugins-scripts/Classes/Bluecoat.pm @@ -48,11 +48,12 @@ sub init { # iso.3.6.1.4.1.3417.2.11.1.3.0 = STRING: "Version: SGOS 5.5.8.1, Release id: 78642 Proxy Edition" bless $self, 'Classes::SGOS'; $self->debug('using Classes::SGOS'); - $self->init(); } elsif ($self->{productname} =~ /Blue.*Coat.*AV\d+/i) { # product Blue Coat AV510 Series, ProxyAV Version: 3.5.1.1, Release id: 111017 bless $self, 'Classes::AVOS'; $self->debug('using Classes::AVOS'); + } + if (ref($self) ne "Classes::Bluecoat") { $self->init(); } } diff --git a/plugins-scripts/Classes/Brocade.pm b/plugins-scripts/Classes/Brocade.pm index f9c994f9..c1dff41c 100644 --- a/plugins-scripts/Classes/Brocade.pm +++ b/plugins-scripts/Classes/Brocade.pm @@ -36,6 +36,9 @@ sub init { bless $self, 'Classes::Foundry'; $self->debug('using Classes::Foundry'); } - $self->init(); + if (ref($self) ne "Classes::Brocade") { + $self->init(); + } + } diff --git a/plugins-scripts/Classes/CheckPoint.pm b/plugins-scripts/Classes/CheckPoint.pm index fb073a79..b0186bf6 100644 --- a/plugins-scripts/Classes/CheckPoint.pm +++ b/plugins-scripts/Classes/CheckPoint.pm @@ -12,6 +12,8 @@ sub init { bless $self, 'Classes::CheckPoint::Firewall1'; $self->debug('using Classes::CheckPoint::Firewall1'); } - $self->init(); + if (ref($self) ne "Classes::CheckPoint") { + $self->init(); + } } diff --git a/plugins-scripts/Classes/CheckPoint/Firewall1.pm b/plugins-scripts/Classes/CheckPoint/Firewall1.pm index 18402dfc..1ab86259 100644 --- a/plugins-scripts/Classes/CheckPoint/Firewall1.pm +++ b/plugins-scripts/Classes/CheckPoint/Firewall1.pm @@ -1,88 +1,30 @@ package Classes::CheckPoint::Firewall1; - -use strict; - -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - our @ISA = qw(Classes::CheckPoint); +use strict; sub init { my $self = shift; - $self->{components} = { - powersupply_subsystem => undef, - fan_subsystem => undef, - temperature_subsystem => undef, - cpu_subsystem => undef, - }; - $self->{serial} = 'unknown'; - $self->{product} = 'unknown'; - $self->{romversion} = 'unknown'; - # serial is 1.3.6.1.2.1.47.1.1.1.1.11.1 - #$self->collect(); - if (! $self->check_messages()) { - ##$self->set_serial(); - if ($self->mode =~ /device::hardware::health/) { - $self->analyze_environmental_subsystem(); - $self->check_environmental_subsystem(); - } elsif ($self->mode =~ /device::hardware::load/) { - $self->analyze_cpu_subsystem(); - $self->check_cpu_subsystem(); - } elsif ($self->mode =~ /device::hardware::memory/) { - $self->analyze_mem_subsystem(); - $self->check_mem_subsystem(); - } elsif ($self->mode =~ /device::ha::/) { - $self->analyze_ha_subsystem(); - $self->check_ha_subsystem(); - } elsif ($self->mode =~ /device::fw::/) { - $self->analyze_fw_subsystem(); - $self->check_fw_subsystem(); - } elsif ($self->mode =~ /device::svn::/) { - $self->analyze_svn_subsystem(); - $self->check_svn_subsystem(); - } elsif ($self->mode =~ /device::mngmt::/) { - $self->analyze_mngmt_subsystem(); - $self->check_svn_subsystem(); - } + if ($self->mode =~ /device::hardware::health/) { + $self->analyze_and_check_environmental_subsystem("Classes::CheckPoint::Firewall1::Component::EnvironmentalSubsystem"); + } elsif ($self->mode =~ /device::hardware::load/) { + $self->analyze_and_check_cpu_subsystem("Classes::CheckPoint::Firewall1::Component::CpuSubsystem"); + } elsif ($self->mode =~ /device::hardware::memory/) { + $self->analyze_and_check_mem_subsystem("Classes::CheckPoint::Firewall1::Component::MemSubsystem"); + } elsif ($self->mode =~ /device::ha::/) { + $self->analyze_and_check_ha_subsystem("Classes::CheckPoint::Firewall1::Component::HaSubsystem"); + } elsif ($self->mode =~ /device::fw::/) { + $self->analyze_and_check_fw_subsystem("Classes::CheckPoint::Firewall1::Component::FwSubsystem"); + } elsif ($self->mode =~ /device::svn::/) { + $self->analyze_and_check_svn_subsystem("Classes::CheckPoint::Firewall1::Component::SvnSubsystem"); + } elsif ($self->mode =~ /device::mngmt::/) { + # not sure if this works fa25239716cb74c672f8dd390430dc4056caffa7 + $self->analyze_mngmt_subsystem(); + $self->check_mngmt_subsystem(); + } else { + $self->no_such_mode(); } } -sub analyze_environmental_subsystem { - my $self = shift; - $self->{components}->{environmental_subsystem} = - Classes::CheckPoint::Firewall1::Component::EnvironmentalSubsystem->new(); -} - -sub analyze_cpu_subsystem { - my $self = shift; - $self->{components}->{cpu_subsystem} = - Classes::CheckPoint::Firewall1::Component::CpuSubsystem->new(); -#printf "%s\n", Data::Dumper::Dumper($self->{components}); -} - -sub analyze_mem_subsystem { - my $self = shift; - $self->{components}->{mem_subsystem} = - Classes::CheckPoint::Firewall1::Component::MemSubsystem->new(); -} - -sub analyze_ha_subsystem { - my $self = shift; - $self->{components}->{ha_subsystem} = - Classes::CheckPoint::Firewall1::Component::HaSubsystem->new(); -} - -sub analyze_fw_subsystem { - my $self = shift; - $self->{components}->{fw_subsystem} = - Classes::CheckPoint::Firewall1::Component::FwSubsystem->new(); -} - -sub analyze_svn_subsystem { - my $self = shift; - $self->{components}->{svn_subsystem} = - Classes::CheckPoint::Firewall1::Component::SvnSubsystem->new(); -} - sub analyze_mngmt_subsystem { my $self = shift; $self->{components}->{mngmt_subsystem} = diff --git a/plugins-scripts/Classes/CheckPoint/Firewall1/Component/CpuSubsystem.pm b/plugins-scripts/Classes/CheckPoint/Firewall1/Component/CpuSubsystem.pm index 60a02102..d1bc68bc 100644 --- a/plugins-scripts/Classes/CheckPoint/Firewall1/Component/CpuSubsystem.pm +++ b/plugins-scripts/Classes/CheckPoint/Firewall1/Component/CpuSubsystem.pm @@ -1,33 +1,24 @@ package Classes::CheckPoint::Firewall1::Component::CpuSubsystem; our @ISA = qw(Classes::CheckPoint::Firewall1); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - cpus => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; $self->{procUsage} = $self->get_snmp_object('CHECKPOINT-MIB', 'procUsage'); $self->{procQueue} = $self->valid_response('CHECKPOINT-MIB', 'procQueue'); } sub check { my $self = shift; - my $errorfound = 0; $self->add_info('checking cpus'); my $info = sprintf 'cpu usage is %.2f%%', $self->{procUsage}; $self->add_info($info); diff --git a/plugins-scripts/Classes/CheckPoint/Firewall1/Component/DiskSubsystem.pm b/plugins-scripts/Classes/CheckPoint/Firewall1/Component/DiskSubsystem.pm index cc5736ef..94ff1b31 100644 --- a/plugins-scripts/Classes/CheckPoint/Firewall1/Component/DiskSubsystem.pm +++ b/plugins-scripts/Classes/CheckPoint/Firewall1/Component/DiskSubsystem.pm @@ -1,29 +1,18 @@ package Classes::CheckPoint::Firewall1::Component::DiskSubsystem; our @ISA = qw(Classes::CheckPoint::Firewall1::Component::EnvironmentalSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - storages => [], - volumes => [], - disks => [], - diskthresholds => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my $disks = {}; foreach ($self->get_snmp_table_objects( 'HOST-RESOURCES-MIB', 'hrStorageTable')) { next if $_->{hrStorageType} ne 'hrStorageFixedDisk'; @@ -45,7 +34,6 @@ sub init { sub check { my $self = shift; - my $errorfound = 0; $self->add_info('checking disks'); $self->blacklist('ses', ''); if (scalar (@{$self->{storages}}) == 0) { @@ -90,7 +78,6 @@ sub dump { package Classes::CheckPoint::Firewall1::Component::DiskSubsystem::Volume; our @ISA = qw(Classes::CheckPoint::Firewall1::Component::DiskSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; @@ -141,7 +128,6 @@ sub dump { package Classes::CheckPoint::Firewall1::Component::DiskSubsystem::Disk; our @ISA = qw(Classes::CheckPoint::Firewall1::Component::DiskSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/CheckPoint/Firewall1/Component/EnvironmentalSubsystem.pm b/plugins-scripts/Classes/CheckPoint/Firewall1/Component/EnvironmentalSubsystem.pm index 973f9d43..e9c10b12 100644 --- a/plugins-scripts/Classes/CheckPoint/Firewall1/Component/EnvironmentalSubsystem.pm +++ b/plugins-scripts/Classes/CheckPoint/Firewall1/Component/EnvironmentalSubsystem.pm @@ -1,45 +1,30 @@ package Classes::CheckPoint::Firewall1::Component::EnvironmentalSubsystem; our @ISA = qw(Classes::CheckPoint::Firewall1); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - method => $params{method}, - condition => $params{condition}, - status => $params{status}, - sensor_subsystem => undef, - disk_subsystem => undef, - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; $self->{disk_subsystem} = - Classes::CheckPoint::Firewall1::Component::DiskSubsystem->new(%params); + Classes::CheckPoint::Firewall1::Component::DiskSubsystem->new(); $self->{temperature_subsystem} = - Classes::CheckPoint::Firewall1::Component::TemperatureSubsystem->new(%params); + Classes::CheckPoint::Firewall1::Component::TemperatureSubsystem->new(); $self->{fan_subsystem} = - Classes::CheckPoint::Firewall1::Component::FanSubsystem->new(%params); + Classes::CheckPoint::Firewall1::Component::FanSubsystem->new(); $self->{voltage_subsystem} = - Classes::CheckPoint::Firewall1::Component::VoltageSubsystem->new(%params); + Classes::CheckPoint::Firewall1::Component::VoltageSubsystem->new(); } sub check { my $self = shift; - my $errorfound = 0; $self->{disk_subsystem}->check(); $self->{temperature_subsystem}->check(); $self->{fan_subsystem}->check(); diff --git a/plugins-scripts/Classes/CheckPoint/Firewall1/Component/FanSubsystem.pm b/plugins-scripts/Classes/CheckPoint/Firewall1/Component/FanSubsystem.pm index d0817a74..768958ff 100644 --- a/plugins-scripts/Classes/CheckPoint/Firewall1/Component/FanSubsystem.pm +++ b/plugins-scripts/Classes/CheckPoint/Firewall1/Component/FanSubsystem.pm @@ -1,27 +1,18 @@ package Classes::CheckPoint::Firewall1::Component::FanSubsystem; our @ISA = qw(Classes::CheckPoint::Firewall1); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - fans => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; - my $temp = 0; foreach ($self->get_snmp_table_objects( 'CHECKPOINT-MIB', 'sensorsFanTable')) { push(@{$self->{fans}}, @@ -46,7 +37,6 @@ sub dump { package Classes::CheckPoint::Firewall1::Component::FanSubsystem::Fan; our @ISA = qw(Classes::CheckPoint::Firewall1::Component::FanSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/CheckPoint/Firewall1/Component/FwSubsystem.pm b/plugins-scripts/Classes/CheckPoint/Firewall1/Component/FwSubsystem.pm index e8c5e05a..80aca3ca 100644 --- a/plugins-scripts/Classes/CheckPoint/Firewall1/Component/FwSubsystem.pm +++ b/plugins-scripts/Classes/CheckPoint/Firewall1/Component/FwSubsystem.pm @@ -1,26 +1,18 @@ package Classes::CheckPoint::Firewall1::Component::FwSubsystem; our @ISA = qw(Classes::CheckPoint::Firewall1); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - cpus => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; $self->{fwModuleState} = $self->get_snmp_object('CHECKPOINT-MIB', 'fwModuleState'); $self->{fwPolicyName} = $self->get_snmp_object('CHECKPOINT-MIB', 'fwPolicyName'); if ($self->mode =~ /device::fw::policy::installed/) { @@ -31,8 +23,6 @@ sub init { sub check { my $self = shift; - my %params = @_; - my $errorfound = 0; $self->add_info('checking fw module'); if ($self->{fwModuleState} ne 'Installed') { $self->add_message(CRITICAL, diff --git a/plugins-scripts/Classes/CheckPoint/Firewall1/Component/HaSubsystem.pm b/plugins-scripts/Classes/CheckPoint/Firewall1/Component/HaSubsystem.pm index 81f71df3..8d39b357 100644 --- a/plugins-scripts/Classes/CheckPoint/Firewall1/Component/HaSubsystem.pm +++ b/plugins-scripts/Classes/CheckPoint/Firewall1/Component/HaSubsystem.pm @@ -1,26 +1,18 @@ package Classes::CheckPoint::Firewall1::Component::HaSubsystem; our @ISA = qw(Classes::CheckPoint::Firewall1); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - cpus => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; if ($self->mode =~ /device::ha::role/) { $self->{haStarted} = $self->get_snmp_object('CHECKPOINT-MIB', 'haStarted'); $self->{haState} = $self->get_snmp_object('CHECKPOINT-MIB', 'haState'); @@ -33,8 +25,6 @@ sub init { sub check { my $self = shift; - my %params = @_; - my $errorfound = 0; $self->add_info('checking ha'); my $info = sprintf 'ha %sstarted, role is %s, status is %s', $self->{haStarted} eq 'yes' ? '' : 'not ', diff --git a/plugins-scripts/Classes/CheckPoint/Firewall1/Component/MemSubsystem.pm b/plugins-scripts/Classes/CheckPoint/Firewall1/Component/MemSubsystem.pm index 5bb10c97..16a2ca92 100644 --- a/plugins-scripts/Classes/CheckPoint/Firewall1/Component/MemSubsystem.pm +++ b/plugins-scripts/Classes/CheckPoint/Firewall1/Component/MemSubsystem.pm @@ -1,26 +1,18 @@ package Classes::CheckPoint::Firewall1::Component::MemSubsystem; our @ISA = qw(Classes::CheckPoint::Firewall1); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; - my $type = 0; $self->{total_memory} = $self->get_snmp_object( 'CHECKPOINT-MIB', 'memTotalReal64'); $self->{free_memory} = $self->get_snmp_object( diff --git a/plugins-scripts/Classes/CheckPoint/Firewall1/Component/MngmtSubsystem.pm b/plugins-scripts/Classes/CheckPoint/Firewall1/Component/MngmtSubsystem.pm index eaba81bc..5ed09031 100644 --- a/plugins-scripts/Classes/CheckPoint/Firewall1/Component/MngmtSubsystem.pm +++ b/plugins-scripts/Classes/CheckPoint/Firewall1/Component/MngmtSubsystem.pm @@ -1,26 +1,18 @@ package Classes::CheckPoint::Firewall1::Component::MngmtSubsystem; our @ISA = qw(Classes::CheckPoint::Firewall1); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - cpus => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; if ($self->mode =~ /device::mngmt::status/) { $self->{mgStatShortDescr} = $self->get_snmp_object('CHECKPOINT-MIB', 'mgStatShortDescr'); $self->{mgStatLongDescr} = $self->get_snmp_object('CHECKPOINT-MIB', 'mgStatLongDescr'); @@ -29,8 +21,6 @@ sub init { sub check { my $self = shift; - my %params = @_; - my $errorfound = 0; $self->add_info('checking mngmt'); if ($self->mode =~ /device::mngmt::status/) { if ($self->{mgStatShortDescr} ne 'OK') { diff --git a/plugins-scripts/Classes/CheckPoint/Firewall1/Component/SvnSubsystem.pm b/plugins-scripts/Classes/CheckPoint/Firewall1/Component/SvnSubsystem.pm index bb52898f..a679356b 100644 --- a/plugins-scripts/Classes/CheckPoint/Firewall1/Component/SvnSubsystem.pm +++ b/plugins-scripts/Classes/CheckPoint/Firewall1/Component/SvnSubsystem.pm @@ -1,26 +1,18 @@ package Classes::CheckPoint::Firewall1::Component::SvnSubsystem; our @ISA = qw(Classes::CheckPoint::Firewall1); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - cpus => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; if ($self->mode =~ /device::svn::status/) { $self->{svnStatShortDescr} = $self->get_snmp_object('CHECKPOINT-MIB', 'svnStatShortDescr'); $self->{svnStatLongDescr} = $self->get_snmp_object('CHECKPOINT-MIB', 'svnStatLongDescr'); @@ -29,8 +21,6 @@ sub init { sub check { my $self = shift; - my %params = @_; - my $errorfound = 0; $self->add_info('checking svn'); if ($self->mode =~ /device::svn::status/) { if ($self->{svnStatShortDescr} ne 'OK') { diff --git a/plugins-scripts/Classes/CheckPoint/Firewall1/Component/TemperatureSubsystem.pm b/plugins-scripts/Classes/CheckPoint/Firewall1/Component/TemperatureSubsystem.pm index 375f5445..22fe1f15 100644 --- a/plugins-scripts/Classes/CheckPoint/Firewall1/Component/TemperatureSubsystem.pm +++ b/plugins-scripts/Classes/CheckPoint/Firewall1/Component/TemperatureSubsystem.pm @@ -1,27 +1,18 @@ package Classes::CheckPoint::Firewall1::Component::TemperatureSubsystem; our @ISA = qw(Classes::CheckPoint::Firewall1); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - temperatures => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; - my $temp = 0; foreach ($self->get_snmp_table_objects( 'CHECKPOINT-MIB', 'sensorsTemperatureTable')) { push(@{$self->{temperatures}}, @@ -46,7 +37,6 @@ sub dump { package Classes::CheckPoint::Firewall1::Component::TemperatureSubsystem::Temperature; our @ISA = qw(Classes::CheckPoint::Firewall1::Component::TemperatureSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/CheckPoint/Firewall1/Component/VoltageSubsystem.pm b/plugins-scripts/Classes/CheckPoint/Firewall1/Component/VoltageSubsystem.pm index 6b09df58..c5898d40 100644 --- a/plugins-scripts/Classes/CheckPoint/Firewall1/Component/VoltageSubsystem.pm +++ b/plugins-scripts/Classes/CheckPoint/Firewall1/Component/VoltageSubsystem.pm @@ -1,27 +1,18 @@ package Classes::CheckPoint::Firewall1::Component::VoltageSubsystem; our @ISA = qw(Classes::CheckPoint::Firewall1); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - voltages => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; - my $temp = 0; foreach ($self->get_snmp_table_objects( 'CHECKPOINT-MIB', 'sensorsVoltageTable')) { push(@{$self->{voltages}}, @@ -46,7 +37,6 @@ sub dump { package Classes::CheckPoint::Firewall1::Component::VoltageSubsystem::Voltage; our @ISA = qw(Classes::CheckPoint::Firewall1::Component::VoltageSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/CiscoAsyncOS/Component/CpuSubsystem.pm b/plugins-scripts/Classes/CiscoAsyncOS/Component/CpuSubsystem.pm index 5d1ef83a..e8dbf4e1 100644 --- a/plugins-scripts/Classes/CiscoAsyncOS/Component/CpuSubsystem.pm +++ b/plugins-scripts/Classes/CiscoAsyncOS/Component/CpuSubsystem.pm @@ -1,20 +1,13 @@ package Classes::CiscoAsyncOS::Component::CpuSubsystem; our @ISA = qw(Classes::CiscoAsyncOS); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - cpus => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } @@ -43,7 +36,6 @@ sub check { ); } - sub dump { my $self = shift; printf "[CPU]\n"; diff --git a/plugins-scripts/Classes/CiscoAsyncOS/Component/EnvironmentalSubsystem.pm b/plugins-scripts/Classes/CiscoAsyncOS/Component/EnvironmentalSubsystem.pm index afd3580e..b27838e8 100644 --- a/plugins-scripts/Classes/CiscoAsyncOS/Component/EnvironmentalSubsystem.pm +++ b/plugins-scripts/Classes/CiscoAsyncOS/Component/EnvironmentalSubsystem.pm @@ -1,50 +1,33 @@ package Classes::CiscoAsyncOS::Component::EnvironmentalSubsystem; our @ISA = qw(Classes::CiscoAsyncOS); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - method => $params{method}, - condition => $params{condition}, - status => $params{status}, - fan_subsystem => undef, - temperature_subsystem => undef, - powersupply_subsystem => undef, - raid_subsystem => undef, - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; # # 1.3.6.1.4.1.9.9.13.1.1.0 ciscoEnvMonPresent (irgendein typ of envmon) # $self->{fan_subsystem} = - Classes::CiscoAsyncOS::Component::FanSubsystem->new(%params); + Classes::CiscoAsyncOS::Component::FanSubsystem->new(); $self->{temperature_subsystem} = - Classes::CiscoAsyncOS::Component::TemperatureSubsystem->new(%params); + Classes::CiscoAsyncOS::Component::TemperatureSubsystem->new(); $self->{powersupply_subsystem} = - Classes::CiscoAsyncOS::Component::SupplySubsystem->new(%params); + Classes::CiscoAsyncOS::Component::SupplySubsystem->new(); $self->{raid_subsystem} = - Classes::CiscoAsyncOS::Component::RaidSubsystem->new(%params); + Classes::CiscoAsyncOS::Component::RaidSubsystem->new(); } sub check { my $self = shift; - my $errorfound = 0; $self->{fan_subsystem}->check(); $self->{temperature_subsystem}->check(); $self->{powersupply_subsystem}->check(); diff --git a/plugins-scripts/Classes/CiscoAsyncOS/Component/FanSubsystem.pm b/plugins-scripts/Classes/CiscoAsyncOS/Component/FanSubsystem.pm index 7abf7f45..9ebad5bf 100644 --- a/plugins-scripts/Classes/CiscoAsyncOS/Component/FanSubsystem.pm +++ b/plugins-scripts/Classes/CiscoAsyncOS/Component/FanSubsystem.pm @@ -6,15 +6,9 @@ use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - fans => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } @@ -51,7 +45,6 @@ sub dump { package Classes::CiscoAsyncOS::Component::FanSubsystem::Fan; our @ISA = qw(Classes::CiscoAsyncOS::Component::FanSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/CiscoAsyncOS/Component/KeySubsystem.pm b/plugins-scripts/Classes/CiscoAsyncOS/Component/KeySubsystem.pm index a7663121..38bbbdd5 100644 --- a/plugins-scripts/Classes/CiscoAsyncOS/Component/KeySubsystem.pm +++ b/plugins-scripts/Classes/CiscoAsyncOS/Component/KeySubsystem.pm @@ -1,20 +1,13 @@ package Classes::CiscoAsyncOS::Component::KeySubsystem; our @ISA = qw(Classes::CiscoAsyncOS::Component); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - keys => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } @@ -51,7 +44,6 @@ sub dump { package Classes::CiscoAsyncOS::Component::KeySubsystem::Key; our @ISA = qw(Classes::CiscoAsyncOS::Component::KeySubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/CiscoAsyncOS/Component/MemSubsystem.pm b/plugins-scripts/Classes/CiscoAsyncOS/Component/MemSubsystem.pm index 117ff6aa..85427c77 100644 --- a/plugins-scripts/Classes/CiscoAsyncOS/Component/MemSubsystem.pm +++ b/plugins-scripts/Classes/CiscoAsyncOS/Component/MemSubsystem.pm @@ -1,20 +1,13 @@ package Classes::CiscoAsyncOS::Component::MemSubsystem; our @ISA = qw(Classes::CiscoAsyncOS); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - cpus => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } diff --git a/plugins-scripts/Classes/CiscoAsyncOS/Component/RaidSubsystem.pm b/plugins-scripts/Classes/CiscoAsyncOS/Component/RaidSubsystem.pm index 5fbe515a..9f44e532 100644 --- a/plugins-scripts/Classes/CiscoAsyncOS/Component/RaidSubsystem.pm +++ b/plugins-scripts/Classes/CiscoAsyncOS/Component/RaidSubsystem.pm @@ -1,20 +1,13 @@ package Classes::CiscoAsyncOS::Component::RaidSubsystem; our @ISA = qw(Classes::CiscoAsyncOS::Component::EnvironmentalSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - raids => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } @@ -53,7 +46,6 @@ sub dump { package Classes::CiscoAsyncOS::Component::RaidSubsystem::Raid; our @ISA = qw(Classes::CiscoAsyncOS::Component::RaidSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/CiscoAsyncOS/Component/SupplySubsystem.pm b/plugins-scripts/Classes/CiscoAsyncOS/Component/SupplySubsystem.pm index 1ab3b1a8..52d89685 100644 --- a/plugins-scripts/Classes/CiscoAsyncOS/Component/SupplySubsystem.pm +++ b/plugins-scripts/Classes/CiscoAsyncOS/Component/SupplySubsystem.pm @@ -1,20 +1,13 @@ package Classes::CiscoAsyncOS::Component::SupplySubsystem; our @ISA = qw(Classes::CiscoAsyncOS::Component::EnvironmentalSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - supplies => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } @@ -51,7 +44,6 @@ sub dump { package Classes::CiscoAsyncOS::Component::SupplySubsystem::Supply; our @ISA = qw(Classes::CiscoAsyncOS::Component::SupplySubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/CiscoAsyncOS/Component/TemperatureSubsystem.pm b/plugins-scripts/Classes/CiscoAsyncOS/Component/TemperatureSubsystem.pm index 0e0f1ebd..603e2c6e 100644 --- a/plugins-scripts/Classes/CiscoAsyncOS/Component/TemperatureSubsystem.pm +++ b/plugins-scripts/Classes/CiscoAsyncOS/Component/TemperatureSubsystem.pm @@ -1,20 +1,13 @@ package Classes::CiscoAsyncOS::Component::TemperatureSubsystem; our @ISA = qw(Classes::CiscoAsyncOS::Component::EnvironmentalSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - temperatures => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } @@ -52,7 +45,6 @@ sub dump { package Classes::CiscoAsyncOS::Component::TemperatureSubsystem::Temperature; our @ISA = qw(Classes::CiscoAsyncOS::Component::TemperatureSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/CiscoCCM/Component/CmSubsystem.pm b/plugins-scripts/Classes/CiscoCCM/Component/CmSubsystem.pm index 984bd6f2..b255b2a8 100644 --- a/plugins-scripts/Classes/CiscoCCM/Component/CmSubsystem.pm +++ b/plugins-scripts/Classes/CiscoCCM/Component/CmSubsystem.pm @@ -1,23 +1,13 @@ package Classes::CiscoCCM::Component::CmSubsystem; our @ISA = qw(Classes::CiscoCCM); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - method => $params{method}, - ccms => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } @@ -52,7 +42,6 @@ sub dump { package Classes::CiscoCCM::Component::CmSubsystem::Cm; our @ISA = qw(Classes::CiscoCCM); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/CiscoCCM/Component/PhoneSubsystem.pm b/plugins-scripts/Classes/CiscoCCM/Component/PhoneSubsystem.pm index 7b49aa6d..c7e95b3b 100644 --- a/plugins-scripts/Classes/CiscoCCM/Component/PhoneSubsystem.pm +++ b/plugins-scripts/Classes/CiscoCCM/Component/PhoneSubsystem.pm @@ -1,22 +1,13 @@ package Classes::CiscoCCM::Component::PhoneSubsystem; our @ISA = qw(Classes::CiscoCCM); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - method => $params{method}, - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } diff --git a/plugins-scripts/Classes/CiscoIOS.pm b/plugins-scripts/Classes/CiscoIOS.pm index b2609e82..1e18a65c 100644 --- a/plugins-scripts/Classes/CiscoIOS.pm +++ b/plugins-scripts/Classes/CiscoIOS.pm @@ -16,6 +16,8 @@ sub init { $self->analyze_and_check_connection_subsystem("Classes::CiscoIOS::Component::ConnectionSubsystem"); } elsif ($self->mode =~ /device::config/) { $self->analyze_and_check_config_subsystem("Classes::CiscoIOS::Component::ConfigSubsystem"); + } else { + $self->no_such_mode(); } } diff --git a/plugins-scripts/Classes/CiscoIOS/Component/ConfigSubsystem.pm b/plugins-scripts/Classes/CiscoIOS/Component/ConfigSubsystem.pm index 8d7f4def..8d2f199f 100644 --- a/plugins-scripts/Classes/CiscoIOS/Component/ConfigSubsystem.pm +++ b/plugins-scripts/Classes/CiscoIOS/Component/ConfigSubsystem.pm @@ -1,22 +1,13 @@ package Classes::CiscoIOS::Component::ConfigSubsystem; our @ISA = qw(Classes::CiscoIOS); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - configstates => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } @@ -73,7 +64,6 @@ sub check { } } - sub dump { my $self = shift; printf "[CONFIG]\n"; diff --git a/plugins-scripts/Classes/CiscoIOS/Component/ConnectionSubsystem.pm b/plugins-scripts/Classes/CiscoIOS/Component/ConnectionSubsystem.pm index 00f87e94..39cf338f 100644 --- a/plugins-scripts/Classes/CiscoIOS/Component/ConnectionSubsystem.pm +++ b/plugins-scripts/Classes/CiscoIOS/Component/ConnectionSubsystem.pm @@ -1,22 +1,13 @@ package Classes::CiscoIOS::Component::ConnectionSubsystem; our @ISA = qw(Classes::CiscoIOS); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - connectionstates => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } @@ -45,7 +36,6 @@ sub check { } } - sub dump { my $self = shift; foreach (@{$self->{connectionstates}}) { @@ -56,7 +46,6 @@ sub dump { package Classes::CiscoIOS::Component::ConnectionSubsystem::ConnectionState; our @ISA = qw(Classes::CiscoIOS::Component::ConnectionSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/CiscoIOS/Component/CpuSubsystem.pm b/plugins-scripts/Classes/CiscoIOS/Component/CpuSubsystem.pm index 82b0a033..1950d9df 100644 --- a/plugins-scripts/Classes/CiscoIOS/Component/CpuSubsystem.pm +++ b/plugins-scripts/Classes/CiscoIOS/Component/CpuSubsystem.pm @@ -1,26 +1,18 @@ package Classes::CiscoIOS::Component::CpuSubsystem; our @ISA = qw(Classes::CiscoIOS); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - cpus => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; my $type = 0; foreach ($self->get_snmp_table_objects( 'CISCO-PROCESS-MIB', 'cpmCPUTotalTable')) { @@ -69,7 +61,6 @@ sub check { } } - sub dump { my $self = shift; foreach (@{$self->{cpus}}) { @@ -80,7 +71,6 @@ sub dump { package Classes::CiscoIOS::Component::CpuSubsystem::Cpu; our @ISA = qw(Classes::CiscoIOS::Component::CpuSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/CiscoIOS/Component/EnvironmentalSubsystem.pm b/plugins-scripts/Classes/CiscoIOS/Component/EnvironmentalSubsystem.pm index 4e3ad398..df482fd6 100644 --- a/plugins-scripts/Classes/CiscoIOS/Component/EnvironmentalSubsystem.pm +++ b/plugins-scripts/Classes/CiscoIOS/Component/EnvironmentalSubsystem.pm @@ -1,28 +1,13 @@ package Classes::CiscoIOS::Component::EnvironmentalSubsystem; our @ISA = qw(Classes::CiscoIOS); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - method => $params{method}, - condition => $params{condition}, - status => $params{status}, - fan_subsystem => undef, - temperature_subsystem => undef, - powersupply_subsystem => undef, - voltage_subsystem => undef, - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } @@ -33,13 +18,13 @@ sub init { # 1.3.6.1.4.1.9.9.13.1.1.0 ciscoEnvMonPresent (irgendein typ of envmon) # $self->{fan_subsystem} = - Classes::CiscoIOS::Component::FanSubsystem->new(%params); + Classes::CiscoIOS::Component::FanSubsystem->new(); $self->{temperature_subsystem} = - Classes::CiscoIOS::Component::TemperatureSubsystem->new(%params); + Classes::CiscoIOS::Component::TemperatureSubsystem->new(); $self->{powersupply_subsystem} = - Classes::CiscoIOS::Component::SupplySubsystem->new(%params); + Classes::CiscoIOS::Component::SupplySubsystem->new(); $self->{voltage_subsystem} = - Classes::CiscoIOS::Component::VoltageSubsystem->new(%params); + Classes::CiscoIOS::Component::VoltageSubsystem->new(); } sub check { diff --git a/plugins-scripts/Classes/CiscoIOS/Component/FanSubsystem.pm b/plugins-scripts/Classes/CiscoIOS/Component/FanSubsystem.pm index 2d66c6c1..7b5a5e5c 100644 --- a/plugins-scripts/Classes/CiscoIOS/Component/FanSubsystem.pm +++ b/plugins-scripts/Classes/CiscoIOS/Component/FanSubsystem.pm @@ -1,20 +1,13 @@ package Classes::CiscoIOS::Component::FanSubsystem; our @ISA = qw(Classes::CiscoIOS::Component::EnvironmentalSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - fans => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } @@ -51,7 +44,6 @@ sub dump { package Classes::CiscoIOS::Component::FanSubsystem::Fan; our @ISA = qw(Classes::CiscoIOS::Component::FanSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/CiscoIOS/Component/MemSubsystem.pm b/plugins-scripts/Classes/CiscoIOS/Component/MemSubsystem.pm index 78012357..4b5fbf32 100644 --- a/plugins-scripts/Classes/CiscoIOS/Component/MemSubsystem.pm +++ b/plugins-scripts/Classes/CiscoIOS/Component/MemSubsystem.pm @@ -1,31 +1,18 @@ package Classes::CiscoIOS::Component::MemSubsystem; our @ISA = qw(Classes::CiscoIOS); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - mems => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; - my $snmpwalk = $params{rawdata}; - my $ignore_redundancy = $params{ignore_redundancy}; - my $type = 0; foreach ($self->get_snmp_table_objects( 'CISCO-MEMORY-POOL-MIB', 'ciscoMemoryPoolTable')) { $_->{ciscoMemoryPoolType} ||= $type++; @@ -36,7 +23,6 @@ sub init { sub check { my $self = shift; - my $errorfound = 0; $self->add_info('checking mems'); $self->blacklist('ff', ''); if (scalar (@{$self->{mems}}) == 0) { @@ -47,7 +33,6 @@ sub check { } } - sub dump { my $self = shift; foreach (@{$self->{mems}}) { @@ -58,7 +43,6 @@ sub dump { package Classes::CiscoIOS::Component::MemSubsystem::Mem; our @ISA = qw(Classes::CiscoIOS::Component::MemSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/CiscoIOS/Component/SupplySubsystem.pm b/plugins-scripts/Classes/CiscoIOS/Component/SupplySubsystem.pm index f155614f..d4b406ea 100644 --- a/plugins-scripts/Classes/CiscoIOS/Component/SupplySubsystem.pm +++ b/plugins-scripts/Classes/CiscoIOS/Component/SupplySubsystem.pm @@ -1,20 +1,13 @@ package Classes::CiscoIOS::Component::SupplySubsystem; our @ISA = qw(Classes::CiscoIOS::Component::EnvironmentalSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - supplies => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } @@ -29,7 +22,6 @@ sub init { sub check { my $self = shift; - my $errorfound = 0; $self->add_info('checking supplies'); $self->blacklist('ps', ''); if (scalar (@{$self->{supplies}}) == 0) { @@ -40,7 +32,6 @@ sub check { } } - sub dump { my $self = shift; foreach (@{$self->{supplies}}) { @@ -51,7 +42,6 @@ sub dump { package Classes::CiscoIOS::Component::SupplySubsystem::Supply; our @ISA = qw(Classes::CiscoIOS::Component::SupplySubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/CiscoIOS/Component/TemperatureSubsystem.pm b/plugins-scripts/Classes/CiscoIOS/Component/TemperatureSubsystem.pm index 18efe99d..024ae42e 100644 --- a/plugins-scripts/Classes/CiscoIOS/Component/TemperatureSubsystem.pm +++ b/plugins-scripts/Classes/CiscoIOS/Component/TemperatureSubsystem.pm @@ -1,20 +1,13 @@ package Classes::CiscoIOS::Component::TemperatureSubsystem; our @ISA = qw(Classes::CiscoIOS::Component::EnvironmentalSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - temperatures => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } @@ -31,7 +24,6 @@ sub init { sub check { my $self = shift; - my $errorfound = 0; $self->add_info('checking temperatures'); $self->blacklist('t', ''); if (scalar (@{$self->{temperatures}}) == 0) { @@ -42,7 +34,6 @@ sub check { } } - sub dump { my $self = shift; foreach (@{$self->{temperatures}}) { @@ -53,7 +44,6 @@ sub dump { package Classes::CiscoIOS::Component::TemperatureSubsystem::Temperature; our @ISA = qw(Classes::CiscoIOS::Component::TemperatureSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; @@ -125,7 +115,6 @@ sub dump { package Classes::CiscoIOS::Component::TemperatureSubsystem::Temperature::Simple; our @ISA = qw(Classes::CiscoIOS::Component::TemperatureSubsystem::Temperature); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/CiscoIOS/Component/VoltageSubsystem.pm b/plugins-scripts/Classes/CiscoIOS/Component/VoltageSubsystem.pm index 56002020..1b09f8b9 100644 --- a/plugins-scripts/Classes/CiscoIOS/Component/VoltageSubsystem.pm +++ b/plugins-scripts/Classes/CiscoIOS/Component/VoltageSubsystem.pm @@ -1,20 +1,13 @@ package Classes::CiscoIOS::Component::VoltageSubsystem; our @ISA = qw(Classes::CiscoIOS::Component::EnvironmentalSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - voltages => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } @@ -42,7 +35,6 @@ sub check { } } - sub dump { my $self = shift; foreach (@{$self->{voltages}}) { @@ -53,7 +45,6 @@ sub dump { package Classes::CiscoIOS::Component::VoltageSubsystem::Voltage; our @ISA = qw(Classes::CiscoIOS::Component::VoltageSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/CiscoNXOS/Component/CpuSubsystem.pm b/plugins-scripts/Classes/CiscoNXOS/Component/CpuSubsystem.pm index f7216880..cfb5759d 100644 --- a/plugins-scripts/Classes/CiscoNXOS/Component/CpuSubsystem.pm +++ b/plugins-scripts/Classes/CiscoNXOS/Component/CpuSubsystem.pm @@ -1,26 +1,18 @@ package Classes::CiscoNXOS::Component::CpuSubsystem; our @ISA = qw(Classes::CiscoNXOS); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - cpus => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; my $type = 0; foreach ($self->get_snmp_table_objects( 'CISCO-PROCESS-MIB', 'cpmCPUTotalTable')) { @@ -69,7 +61,6 @@ sub check { } } - sub dump { my $self = shift; foreach (@{$self->{cpus}}) { @@ -80,7 +71,6 @@ sub dump { package Classes::CiscoNXOS::Component::CpuSubsystem::Cpu; our @ISA = qw(Classes::CiscoNXOS::Component::CpuSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/CiscoNXOS/Component/EnvironmentalSubsystem.pm b/plugins-scripts/Classes/CiscoNXOS/Component/EnvironmentalSubsystem.pm index 41227d1b..ddc90648 100644 --- a/plugins-scripts/Classes/CiscoNXOS/Component/EnvironmentalSubsystem.pm +++ b/plugins-scripts/Classes/CiscoNXOS/Component/EnvironmentalSubsystem.pm @@ -1,25 +1,13 @@ package Classes::CiscoNXOS::Component::EnvironmentalSubsystem; our @ISA = qw(Classes::CiscoNXOS); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - method => $params{method}, - condition => $params{condition}, - status => $params{status}, - sensor_subsystem => undef, - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } diff --git a/plugins-scripts/Classes/CiscoNXOS/Component/MemSubsystem.pm b/plugins-scripts/Classes/CiscoNXOS/Component/MemSubsystem.pm index ef6a6046..b63ad654 100644 --- a/plugins-scripts/Classes/CiscoNXOS/Component/MemSubsystem.pm +++ b/plugins-scripts/Classes/CiscoNXOS/Component/MemSubsystem.pm @@ -1,28 +1,18 @@ package Classes::CiscoNXOS::Component::MemSubsystem; our @ISA = qw(Classes::CiscoNXOS); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - mems => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; my $snmpwalk = $params{rawdata}; my $ignore_redundancy = $params{ignore_redundancy}; my $type = 0; diff --git a/plugins-scripts/Classes/CiscoNXOS/Component/SensorSubsystem.pm b/plugins-scripts/Classes/CiscoNXOS/Component/SensorSubsystem.pm index 622ae21e..af812ade 100644 --- a/plugins-scripts/Classes/CiscoNXOS/Component/SensorSubsystem.pm +++ b/plugins-scripts/Classes/CiscoNXOS/Component/SensorSubsystem.pm @@ -1,21 +1,13 @@ package Classes::CiscoNXOS::Component::SensorSubsystem; our @ISA = qw(Classes::CiscoNXOS::Component::EnvironmentalSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - sensors => [], - sensorthresholds => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } @@ -56,7 +48,6 @@ sub check { } } - sub dump { my $self = shift; foreach (@{$self->{sensors}}) { @@ -67,7 +58,6 @@ sub dump { package Classes::CiscoNXOS::Component::SensorSubsystem::Sensor; our @ISA = qw(Classes::CiscoNXOS::Component::SensorSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; @@ -152,7 +142,6 @@ sub dump { package Classes::CiscoNXOS::Component::SensorSubsystem::SensorThreshold; our @ISA = qw(Classes::CiscoNXOS::Component::SensorSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/CiscoWLC.pm b/plugins-scripts/Classes/CiscoWLC.pm index d13d1bd9..10cdfe38 100644 --- a/plugins-scripts/Classes/CiscoWLC.pm +++ b/plugins-scripts/Classes/CiscoWLC.pm @@ -1,72 +1,19 @@ package Classes::CiscoWLC; - -use strict; - -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - our @ISA = qw(Classes::Cisco); +use strict; sub init { my $self = shift; - $self->{components} = { - powersupply_subsystem => undef, - fan_subsystem => undef, - temperature_subsystem => undef, - cpu_subsystem => undef, - memory_subsystem => undef, - disk_subsystem => undef, - environmental_subsystem => undef, - }; - $self->{serial} = 'unknown'; - $self->{product} = 'unknown'; - $self->{romversion} = 'unknown'; - # serial is 1.3.6.1.2.1.47.1.1.1.1.11.1 - #$self->collect(); - if (! $self->check_messages()) { - ##$self->set_serial(); - if ($self->mode =~ /device::hardware::health/) { - $self->analyze_environmental_subsystem(); - #$self->auto_blacklist(); - $self->check_environmental_subsystem(); - } elsif ($self->mode =~ /device::hardware::load/) { - $self->analyze_cpu_subsystem(); - #$self->auto_blacklist(); - $self->check_cpu_subsystem(); - } elsif ($self->mode =~ /device::hardware::memory/) { - $self->analyze_mem_subsystem(); - #$self->auto_blacklist(); - $self->check_mem_subsystem(); - } elsif ($self->mode =~ /device::wlan/) { - $self->analyze_wlan_subsystem(); - $self->check_wlan_subsystem(); - } elsif ($self->mode =~ /device::shinken::interface/) { - $self->analyze_interface_subsystem(); - $self->shinken_interface_subsystem(); - } + if ($self->mode =~ /device::hardware::health/) { + $self->analyze_and_check_environmental_subsystem("Classes::CiscoWLC::Component::EnvironmentalSubsystem"); + } elsif ($self->mode =~ /device::hardware::load/) { + $self->analyze_and_check_cpu_subsystem("Classes::CiscoWLC::Component::CpuSubsystem"); + } elsif ($self->mode =~ /device::hardware::memory/) { + $self->analyze_and_check_mem_subsystem("Classes::CiscoWLC::Component::MemSubsystem"); + } elsif ($self->mode =~ /device::wlan/) { + $self->analyze_and_check_wlan_subsystem("Classes::CiscoWLC::Component::WlanSubsystem"); + } else { + $self->no_such_mode(); } } -sub analyze_environmental_subsystem { - my $self = shift; - $self->{components}->{environmental_subsystem} = - Classes::CiscoWLC::Component::EnvironmentalSubsystem->new(); -} - -sub analyze_cpu_subsystem { - my $self = shift; - $self->{components}->{cpu_subsystem} = - Classes::CiscoWLC::Component::CpuSubsystem->new(); -} - -sub analyze_mem_subsystem { - my $self = shift; - $self->{components}->{mem_subsystem} = - Classes::CiscoWLC::Component::MemSubsystem->new(); -} - -sub analyze_wlan_subsystem { - my $self = shift; - $self->{components}->{wlan_subsystem} = - Classes::CiscoWLC::Component::WlanSubsystem->new(); -} - diff --git a/plugins-scripts/Classes/CiscoWLC/Component/CpuSubsystem.pm b/plugins-scripts/Classes/CiscoWLC/Component/CpuSubsystem.pm index 32d5d4cd..e93d7feb 100644 --- a/plugins-scripts/Classes/CiscoWLC/Component/CpuSubsystem.pm +++ b/plugins-scripts/Classes/CiscoWLC/Component/CpuSubsystem.pm @@ -1,26 +1,18 @@ package Classes::CiscoWLC::Component::CpuSubsystem; our @ISA = qw(Classes::CiscoWLC); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - cpus => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; my $type = 0; $self->{cpu_utilization} = $self->get_snmp_object( 'AIRESPACE-SWITCHING-MIB', 'agentCurrentCPUUtilization'); diff --git a/plugins-scripts/Classes/CiscoWLC/Component/EnvironmentalSubsystem.pm b/plugins-scripts/Classes/CiscoWLC/Component/EnvironmentalSubsystem.pm index 768acd58..321b3628 100644 --- a/plugins-scripts/Classes/CiscoWLC/Component/EnvironmentalSubsystem.pm +++ b/plugins-scripts/Classes/CiscoWLC/Component/EnvironmentalSubsystem.pm @@ -1,46 +1,18 @@ package Classes::CiscoWLC::Component::EnvironmentalSubsystem; our @ISA = qw(Classes::CiscoWLC); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - method => $params{method}, - condition => $params{condition}, - status => $params{status}, - fan_subsystem => undef, - temperature_subsystem => undef, - powersupply_subsystem => undef, - voltage_subsystem => undef, - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; -my $remarks = " -gentRadioUpDownTrapCount => '1.3.6.1.4.1.14179.1.1.2.5', - agentApAssociateDisassociateTrapCount => '1.3.6.1.4.1.14179.1.1.2.6', - agentApLoadProfileFailTrapCount => '1.3.6.1.4.1.14179.1.1.2.7', - agentApNoiseProfileFailTrapCount => '1.3.6.1.4.1.14179.1.1.2.8', - agentTrapLogTable => '1.3.6.1.4.1.14179.1.1.2.4', - agentTrapLogEntry => '1.3.6.1.4.1.14179.1.1.2.4.1', - agentTrapLogIndex => '1.3.6.1.4.1.14179.1.1.2.4.1.1', - agentTrapLogSystemTime => '1.3.6.1.4.1.14179.1.1.2.4.1.2', - agentTrapLogTrap => '1.3.6.1.4.1.14179.1.1.2.4.1.22', - -"; $self->{ps1_present} = $self->get_snmp_object( 'AIRESPACE-SWITCHING-MIB', 'agentSwitchInfoPowerSupply1Present', 0); diff --git a/plugins-scripts/Classes/CiscoWLC/Component/FanSubsystem.pm b/plugins-scripts/Classes/CiscoWLC/Component/FanSubsystem.pm index 2d66c6c1..d66c503c 100644 --- a/plugins-scripts/Classes/CiscoWLC/Component/FanSubsystem.pm +++ b/plugins-scripts/Classes/CiscoWLC/Component/FanSubsystem.pm @@ -1,20 +1,13 @@ package Classes::CiscoIOS::Component::FanSubsystem; our @ISA = qw(Classes::CiscoIOS::Component::EnvironmentalSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - fans => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } @@ -40,7 +33,6 @@ sub check { } } - sub dump { my $self = shift; foreach (@{$self->{fans}}) { @@ -51,7 +43,6 @@ sub dump { package Classes::CiscoIOS::Component::FanSubsystem::Fan; our @ISA = qw(Classes::CiscoIOS::Component::FanSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/CiscoWLC/Component/MemSubsystem.pm b/plugins-scripts/Classes/CiscoWLC/Component/MemSubsystem.pm index 8ec9904e..95010ffb 100644 --- a/plugins-scripts/Classes/CiscoWLC/Component/MemSubsystem.pm +++ b/plugins-scripts/Classes/CiscoWLC/Component/MemSubsystem.pm @@ -1,26 +1,18 @@ package Classes::CiscoWLC::Component::MemSubsystem; our @ISA = qw(Classes::CiscoWLC); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; - my $type = 0; $self->{total_memory} = $self->get_snmp_object( 'AIRESPACE-SWITCHING-MIB', 'agentTotalMemory'); $self->{free_memory} = $self->get_snmp_object( diff --git a/plugins-scripts/Classes/CiscoWLC/Component/SupplySubsystem.pm b/plugins-scripts/Classes/CiscoWLC/Component/SupplySubsystem.pm index f155614f..5335d3ea 100644 --- a/plugins-scripts/Classes/CiscoWLC/Component/SupplySubsystem.pm +++ b/plugins-scripts/Classes/CiscoWLC/Component/SupplySubsystem.pm @@ -1,20 +1,13 @@ package Classes::CiscoIOS::Component::SupplySubsystem; our @ISA = qw(Classes::CiscoIOS::Component::EnvironmentalSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - supplies => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } @@ -40,7 +33,6 @@ sub check { } } - sub dump { my $self = shift; foreach (@{$self->{supplies}}) { @@ -51,7 +43,6 @@ sub dump { package Classes::CiscoIOS::Component::SupplySubsystem::Supply; our @ISA = qw(Classes::CiscoIOS::Component::SupplySubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/CiscoWLC/Component/TemperatureSubsystem.pm b/plugins-scripts/Classes/CiscoWLC/Component/TemperatureSubsystem.pm index 18efe99d..97bb2597 100644 --- a/plugins-scripts/Classes/CiscoWLC/Component/TemperatureSubsystem.pm +++ b/plugins-scripts/Classes/CiscoWLC/Component/TemperatureSubsystem.pm @@ -1,20 +1,13 @@ package Classes::CiscoIOS::Component::TemperatureSubsystem; our @ISA = qw(Classes::CiscoIOS::Component::EnvironmentalSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - temperatures => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } @@ -42,7 +35,6 @@ sub check { } } - sub dump { my $self = shift; foreach (@{$self->{temperatures}}) { @@ -53,7 +45,6 @@ sub dump { package Classes::CiscoIOS::Component::TemperatureSubsystem::Temperature; our @ISA = qw(Classes::CiscoIOS::Component::TemperatureSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; @@ -123,9 +114,9 @@ sub dump { printf "\n"; } + package Classes::CiscoIOS::Component::TemperatureSubsystem::Temperature::Simple; our @ISA = qw(Classes::CiscoIOS::Component::TemperatureSubsystem::Temperature); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/CiscoWLC/Component/VoltageSubsystem.pm b/plugins-scripts/Classes/CiscoWLC/Component/VoltageSubsystem.pm index 56002020..1b09f8b9 100644 --- a/plugins-scripts/Classes/CiscoWLC/Component/VoltageSubsystem.pm +++ b/plugins-scripts/Classes/CiscoWLC/Component/VoltageSubsystem.pm @@ -1,20 +1,13 @@ package Classes::CiscoIOS::Component::VoltageSubsystem; our @ISA = qw(Classes::CiscoIOS::Component::EnvironmentalSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - voltages => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } @@ -42,7 +35,6 @@ sub check { } } - sub dump { my $self = shift; foreach (@{$self->{voltages}}) { @@ -53,7 +45,6 @@ sub dump { package Classes::CiscoIOS::Component::VoltageSubsystem::Voltage; our @ISA = qw(Classes::CiscoIOS::Component::VoltageSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/CiscoWLC/Component/WlanSubsystem.pm b/plugins-scripts/Classes/CiscoWLC/Component/WlanSubsystem.pm index 2f5dd700..4aa60ac6 100644 --- a/plugins-scripts/Classes/CiscoWLC/Component/WlanSubsystem.pm +++ b/plugins-scripts/Classes/CiscoWLC/Component/WlanSubsystem.pm @@ -1,33 +1,18 @@ package Classes::CiscoWLC::Component::WlanSubsystem; our @ISA = qw(Classes::CiscoWLC); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - aps => [], - ifs => [], - ifloads => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; - my $snmpwalk = $params{rawdata}; - my $ignore_redundancy = $params{ignore_redundancy}; - my $type = 0; $self->{name} = $self->get_snmp_object( 'MIB-II', 'sysName', 0); foreach ($self->get_snmp_table_objects( @@ -143,9 +128,9 @@ sub assign_loads_to_ifs { } } + package Classes::CiscoWLC::Component::WlanSubsystem::IF; our @ISA = qw(Classes::CiscoWLC::Component::WlanSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; @@ -164,9 +149,9 @@ sub new { return $self; } + package Classes::CiscoWLC::Component::WlanSubsystem::IFLoad; our @ISA = qw(Classes::CiscoWLC::Component::WlanSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; @@ -185,9 +170,9 @@ sub new { return $self; } + package Classes::CiscoWLC::Component::WlanSubsystem::AP; our @ISA = qw(Classes::CiscoWLC::Component::WlanSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/Device.pm b/plugins-scripts/Classes/Device.pm index 59b5fed0..20f1f278 100644 --- a/plugins-scripts/Classes/Device.pm +++ b/plugins-scripts/Classes/Device.pm @@ -167,32 +167,14 @@ use strict; sub init { my $self = shift; if ($self->mode =~ /device::interfaces::aggregation::availability/) { - $self->analyze_and_check_aggregation_subsystem(); + $self->analyze_and_check_aggregation_subsystem("NWC::IFMIB::Component::LinkAggregation"); } elsif ($self->mode =~ /device::interfaces/) { - $self->analyze_and_check_interface_subsystem(); + $self->analyze_and_check_interface_subsystem("NWC::IFMIB::Component::InterfaceSubsystem"); } elsif ($self->mode =~ /device::bgp/) { - $self->analyze_and_check_bgp_subsystem(); + $self->analyze_and_check_bgp_subsystem("NWC::BGP::Component::PeerSubsystem"); } else { bless $self, 'GLPlugin::SNMP'; $self->no_such_mode(); } } -sub analyze_interface_subsystem { - my $self = shift; - $self->{components}->{interface_subsystem} = - NWC::IFMIB::Component::InterfaceSubsystem->new(); -} - -sub analyze_bgp_subsystem { - my $self = shift; - $self->{components}->{bgp_subsystem} = - NWC::BGP::Component::PeerSubsystem->new(); -} - -sub analyze_aggregation_subsystem { - my $self = shift; - $self->{components}->{aggregation_subsystem} = - NWC::IFMIB::Component::LinkAggregation->new(); -} - diff --git a/plugins-scripts/Classes/F5.pm b/plugins-scripts/Classes/F5.pm index eee9e2ab..fbbbdbb4 100644 --- a/plugins-scripts/Classes/F5.pm +++ b/plugins-scripts/Classes/F5.pm @@ -1,10 +1,6 @@ package Classes::F5; - -use strict; - -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - our @ISA = qw(Classes::Device); +use strict; use constant trees => ( '1.3.6.1.4.1.3375.1.2.1.1.1', # F5-3DNS-MIB @@ -17,12 +13,12 @@ use constant trees => ( sub init { my $self = shift; - my %params = @_; - $self->SUPER::init(%params); if ($self->{productname} =~ /Linux.*((el6.f5.x86_64)|(el5.1.0.f5app)) .*/i) { bless $self, 'Classes::F5::F5BIGIP'; $self->debug('using Classes::F5::F5BIGIP'); } - $self->init(%params); + if (ref($self) ne "Classes::F5") { + $self->init(); + } } diff --git a/plugins-scripts/Classes/F5/F5BIGIP.pm b/plugins-scripts/Classes/F5/F5BIGIP.pm index 7e3f8112..e944b8fa 100644 --- a/plugins-scripts/Classes/F5/F5BIGIP.pm +++ b/plugins-scripts/Classes/F5/F5BIGIP.pm @@ -1,76 +1,31 @@ package Classes::F5::F5BIGIP; - -use strict; - -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - our @ISA = qw(Classes::F5); +use strict; sub init { my $self = shift; - my %params = @_; - $self->{components} = { - powersupply_subsystem => undef, - fan_subsystem => undef, - temperature_subsystem => undef, - cpu_subsystem => undef, - memory_subsystem => undef, - disk_subsystem => undef, - environmental_subsystem => undef, - ltm_subsystem => undef, - }; # gets 11.* and 9.* $self->{productversion} = $self->get_snmp_object('F5-BIGIP-SYSTEM-MIB', 'sysProductVersion'); if (! defined $self->{productversion} || $self->{productversion} !~ /^((9)|(10)|(11))/) { $self->{productversion} = "4"; } - $params{productversion} = $self->{productversion}; - if (! $self->check_messages()) { - if ($self->mode =~ /device::hardware::health/) { - $self->analyze_environmental_subsystem(); - #$self->auto_blacklist(); - $self->check_environmental_subsystem(); - } elsif ($self->mode =~ /device::hardware::load/) { - $self->analyze_cpu_subsystem(); - #$self->auto_blacklist(); - $self->check_cpu_subsystem(); - } elsif ($self->mode =~ /device::hardware::memory/) { - $self->analyze_mem_subsystem(); - #$self->auto_blacklist(); - $self->check_mem_subsystem(); - } elsif ($self->mode =~ /device::lb/) { - $self->analyze_ltm_subsystem(%params); - $self->check_ltm_subsystem(); - } elsif ($self->mode =~ /device::shinken::interface/) { - $self->analyze_interface_subsystem(); - $self->shinken_interface_subsystem(); - } + if ($self->mode =~ /device::hardware::health/) { + $self->analyze_and_check_environmental_subsystem(" Classes::F5::F5BIGIP::Component::EnvironmentalSubsystem"); + } elsif ($self->mode =~ /device::hardware::load/) { + $self->analyze_and_check_cpu_subsystem("Classes::F5::F5BIGIP::Component::CpuSubsystem"); + } elsif ($self->mode =~ /device::hardware::memory/) { + $self->analyze_and_check_mem_subsystem("Classes::F5::F5BIGIP::Component::MemSubsystem"); + } elsif ($self->mode =~ /device::lb/) { + $self->analyze_and_check_ltm_subsystem(); + } else { + $self->no_such_mode(); } } -sub analyze_environmental_subsystem { - my $self = shift; - $self->{components}->{environmental_subsystem} = - Classes::F5::F5BIGIP::Component::EnvironmentalSubsystem->new(); -} - -sub analyze_cpu_subsystem { - my $self = shift; - $self->{components}->{cpu_subsystem} = - Classes::F5::F5BIGIP::Component::CpuSubsystem->new(); -} - -sub analyze_mem_subsystem { - my $self = shift; - $self->{components}->{mem_subsystem} = - Classes::F5::F5BIGIP::Component::MemSubsystem->new(); -} - sub analyze_ltm_subsystem { my $self = shift; - my %params = @_; $self->{components}->{ltm_subsystem} = - Classes::F5::F5BIGIP::Component::LTMSubsystem->new(%params); + Classes::F5::F5BIGIP::Component::LTMSubsystem->new('productversion' => $self->{productversion}); } diff --git a/plugins-scripts/Classes/F5/F5BIGIP/Component/CpuSubsystem.pm b/plugins-scripts/Classes/F5/F5BIGIP/Component/CpuSubsystem.pm index 23c89e2e..84f57616 100644 --- a/plugins-scripts/Classes/F5/F5BIGIP/Component/CpuSubsystem.pm +++ b/plugins-scripts/Classes/F5/F5BIGIP/Component/CpuSubsystem.pm @@ -1,23 +1,16 @@ package Classes::F5::F5BIGIP::Component::CpuSubsystem; our @ISA = qw(Classes::F5::F5BIGIP::Component::EnvironmentalSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - cpus => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; if ($self->mode =~ /load/) { - $self->overall_init(%params); + $self->overall_init(); } else { - $self->init(%params); + $self->init(); } return $self; } @@ -48,8 +41,6 @@ sub init { sub check { my $self = shift; - my %params = @_; - my $errorfound = 0; $self->add_info('checking cpus'); $self->blacklist('cc', ''); if ($self->mode =~ /load/) { @@ -75,7 +66,6 @@ sub check { } } - sub dump { my $self = shift; foreach (@{$self->{cpus}}) { @@ -86,7 +76,6 @@ sub dump { package Classes::F5::F5BIGIP::Component::CpuSubsystem::Cpu; our @ISA = qw(Classes::F5::F5BIGIP::Component::CpuSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/F5/F5BIGIP/Component/EnvironmentalSubsystem.pm b/plugins-scripts/Classes/F5/F5BIGIP/Component/EnvironmentalSubsystem.pm index c874a60a..510eb8f1 100644 --- a/plugins-scripts/Classes/F5/F5BIGIP/Component/EnvironmentalSubsystem.pm +++ b/plugins-scripts/Classes/F5/F5BIGIP/Component/EnvironmentalSubsystem.pm @@ -1,47 +1,30 @@ package Classes::F5::F5BIGIP::Component::EnvironmentalSubsystem; our @ISA = qw(Classes::F5::F5BIGIP); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - method => $params{method}, - condition => $params{condition}, - status => $params{status}, - cpu_subsystem => undef, - fan_subsystem => undef, - temperature_subsystem => undef, - powersupply_subsystem => undef, - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; $self->{cpu_subsystem} = - Classes::F5::F5BIGIP::Component::CpuSubsystem->new(%params); + Classes::F5::F5BIGIP::Component::CpuSubsystem->new(); $self->{fan_subsystem} = - Classes::F5::F5BIGIP::Component::FanSubsystem->new(%params); + Classes::F5::F5BIGIP::Component::FanSubsystem->new(); $self->{temperature_subsystem} = - Classes::F5::F5BIGIP::Component::TemperatureSubsystem->new(%params); + Classes::F5::F5BIGIP::Component::TemperatureSubsystem->new(); $self->{powersupply_subsystem} = - Classes::F5::F5BIGIP::Component::PowersupplySubsystem->new(%params); + Classes::F5::F5BIGIP::Component::PowersupplySubsystem->new(); } sub check { my $self = shift; - my $errorfound = 0; $self->{cpu_subsystem}->check(); $self->{fan_subsystem}->check(); $self->{temperature_subsystem}->check(); diff --git a/plugins-scripts/Classes/F5/F5BIGIP/Component/FanSubsystem.pm b/plugins-scripts/Classes/F5/F5BIGIP/Component/FanSubsystem.pm index 3a734333..92ce7b69 100644 --- a/plugins-scripts/Classes/F5/F5BIGIP/Component/FanSubsystem.pm +++ b/plugins-scripts/Classes/F5/F5BIGIP/Component/FanSubsystem.pm @@ -1,20 +1,13 @@ package Classes::F5::F5BIGIP::Component::FanSubsystem; our @ISA = qw(Classes::F5::F5BIGIP::Component::EnvironmentalSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - fans => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } @@ -29,7 +22,6 @@ sub init { sub check { my $self = shift; - my $errorfound = 0; $self->add_info('checking fans'); $self->blacklist('ff', ''); if (scalar (@{$self->{fans}}) == 0) { @@ -40,7 +32,6 @@ sub check { } } - sub dump { my $self = shift; foreach (@{$self->{fans}}) { @@ -51,7 +42,6 @@ sub dump { package Classes::F5::F5BIGIP::Component::FanSubsystem::Fan; our @ISA = qw(Classes::F5::F5BIGIP::Component::FanSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/F5/F5BIGIP/Component/LTM.pm b/plugins-scripts/Classes/F5/F5BIGIP/Component/LTM.pm index a42b1bb2..7c1bd5e6 100644 --- a/plugins-scripts/Classes/F5/F5BIGIP/Component/LTM.pm +++ b/plugins-scripts/Classes/F5/F5BIGIP/Component/LTM.pm @@ -1,20 +1,12 @@ package Classes::F5::F5BIGIP::Component::LTMSubsystem; our @ISA = qw(Classes::F5::F5BIGIP); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; my %params = @_; - my $self = { - pools => [], - poolmembers => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; - #bless $self, $class; + my $self = {}; # tables can be huge if ($Classes::Device::session) { $Classes::Device::session->max_msg_size(10 * $Classes::Device::session->max_msg_size()); @@ -27,13 +19,12 @@ sub new { bless $self, "Classes::F5::F5BIGIP::Component::LTMSubsystem9"; $self->debug("use Classes::F5::F5BIGIP::Component::LTMSubsystem9"); } - $self->init(%params); + $self->init(); return $self; } sub check { my $self = shift; - my $errorfound = 0; $self->add_info('checking ltm pools'); $self->blacklist('poo', ''); if (scalar(@{$self->{pools}}) == 0) { @@ -59,9 +50,9 @@ sub dump { } } + package Classes::F5::F5BIGIP::Component::LTMSubsystem9; our @ISA = qw(Classes::F5::F5BIGIP::Component::LTMSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; @@ -179,7 +170,6 @@ sub assign_members_to_pools { package Classes::F5::F5BIGIP::Component::LTMSubsystem9::LTMPool; our @ISA = qw(Classes::F5::F5BIGIP::Component::LTMSubsystem9); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; @@ -303,7 +293,6 @@ sub dump { package Classes::F5::F5BIGIP::Component::LTMSubsystem9::LTMPoolMember; our @ISA = qw(Classes::F5::F5BIGIP::Component::LTMSubsystem9); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; @@ -360,7 +349,6 @@ sub dump { package Classes::F5::F5BIGIP::Component::LTMSubsystem4; our @ISA = qw(Classes::F5::F5BIGIP::Component::LTMSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; @@ -420,7 +408,6 @@ sub assign_members_to_pools { package Classes::F5::F5BIGIP::Component::LTMSubsystem4::LTMPool; our @ISA = qw(Classes::F5::F5BIGIP::Component::LTMSubsystem4); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; @@ -492,7 +479,6 @@ sub dump { package Classes::F5::F5BIGIP::Component::LTMSubsystem4::LTMPoolMember; our @ISA = qw(Classes::F5::F5BIGIP::Component::LTMSubsystem4); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/F5/F5BIGIP/Component/MemSubsystem.pm b/plugins-scripts/Classes/F5/F5BIGIP/Component/MemSubsystem.pm index 90e8d5bf..819f07ae 100644 --- a/plugins-scripts/Classes/F5/F5BIGIP/Component/MemSubsystem.pm +++ b/plugins-scripts/Classes/F5/F5BIGIP/Component/MemSubsystem.pm @@ -1,20 +1,13 @@ package Classes::F5::F5BIGIP::Component::MemSubsystem; our @ISA = qw(Classes::F5::F5BIGIP::Component::EnvironmentalSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - mems => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->overall_init(%params); + $self->overall_init(); return $self; } @@ -34,8 +27,6 @@ sub overall_init { sub check { my $self = shift; - my %params = @_; - my $errorfound = 0; $self->add_info('checking memory'); $self->blacklist('mm', ''); my $info = sprintf 'tmm memory usage is %.2f%%', diff --git a/plugins-scripts/Classes/F5/F5BIGIP/Component/PowersupplySubsystem.pm b/plugins-scripts/Classes/F5/F5BIGIP/Component/PowersupplySubsystem.pm index d61b839c..4f0c815f 100644 --- a/plugins-scripts/Classes/F5/F5BIGIP/Component/PowersupplySubsystem.pm +++ b/plugins-scripts/Classes/F5/F5BIGIP/Component/PowersupplySubsystem.pm @@ -1,20 +1,13 @@ package Classes::F5::F5BIGIP::Component::PowersupplySubsystem; our @ISA = qw(Classes::F5::F5BIGIP::Component::EnvironmentalSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - powersupplies => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } @@ -40,7 +33,6 @@ sub check { } } - sub dump { my $self = shift; foreach (@{$self->{powersupplies}}) { @@ -51,7 +43,6 @@ sub dump { package Classes::F5::F5BIGIP::Component::PowersupplySubsystem::Powersupply; our @ISA = qw(Classes::F5::F5BIGIP::Component::PowersupplySubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/F5/F5BIGIP/Component/TemperatureSubsystem.pm b/plugins-scripts/Classes/F5/F5BIGIP/Component/TemperatureSubsystem.pm index 0efd3f60..73a7c62b 100644 --- a/plugins-scripts/Classes/F5/F5BIGIP/Component/TemperatureSubsystem.pm +++ b/plugins-scripts/Classes/F5/F5BIGIP/Component/TemperatureSubsystem.pm @@ -1,20 +1,13 @@ package Classes::F5::F5BIGIP::Component::TemperatureSubsystem; our @ISA = qw(Classes::F5::F5BIGIP::Component::EnvironmentalSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - temperatures => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } @@ -40,7 +33,6 @@ sub check { } } - sub dump { my $self = shift; foreach (@{$self->{temperatures}}) { @@ -51,7 +43,6 @@ sub dump { package Classes::F5::F5BIGIP::Component::TemperatureSubsystem::Temperature; our @ISA = qw(Classes::F5::F5BIGIP::Component::TemperatureSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/FCEOS.pm b/plugins-scripts/Classes/FCEOS.pm index baa70180..258e18de 100644 --- a/plugins-scripts/Classes/FCEOS.pm +++ b/plugins-scripts/Classes/FCEOS.pm @@ -1,8 +1,4 @@ package Classes::FCEOS; - -use strict; - -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - our @ISA = qw(Classes::Device); +use strict; diff --git a/plugins-scripts/Classes/FCEOS/Components/EnvironmentalSubsystem.pm b/plugins-scripts/Classes/FCEOS/Components/EnvironmentalSubsystem.pm index d3bfa0b4..c2a7209e 100644 --- a/plugins-scripts/Classes/FCEOS/Components/EnvironmentalSubsystem.pm +++ b/plugins-scripts/Classes/FCEOS/Components/EnvironmentalSubsystem.pm @@ -1,46 +1,31 @@ package Classes::FCEOS::Component::EnvironmentalSubsystem; our @ISA = qw(Classes::FCEOS); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - method => $params{method}, - condition => $params{condition}, - status => $params{status}, - fru_subsystem => undef, - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; $self->overall_init(%params); - $self->init(%params); + $self->init(); return $self; } sub overall_init { my $self = shift; - my %params = @_; $self->{oper_status} = $self->get_snmp_object('FCEOS-MIB', 'fcEosSysOperStatus'); } sub init { my $self = shift; - my %params = @_; $self->{fru_subsystem} = Classes::FCEOS::Component::FruSubsystem->new(%params); } sub check { my $self = shift; - my $errorfound = 0; $self->{fru_subsystem}->check(); if (! $self->check_messages()) { $self->add_message(OK, "environmental hardware working fine"); diff --git a/plugins-scripts/Classes/FCEOS/Components/FruSubsystem.pm b/plugins-scripts/Classes/FCEOS/Components/FruSubsystem.pm index 0480c27d..c73c79d7 100644 --- a/plugins-scripts/Classes/FCEOS/Components/FruSubsystem.pm +++ b/plugins-scripts/Classes/FCEOS/Components/FruSubsystem.pm @@ -1,27 +1,18 @@ package Classes::FCEOS::Component::FruSubsystem; our @ISA = qw(Classes::FCEOS::Component::EnvironmentalSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - frus => [], - thresholds => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my $sensors = {}; foreach ($self->get_snmp_table_objects( 'FCEOS-MIB', 'fcEosFruTable')) { push(@{$self->{frus}}, @@ -42,7 +33,6 @@ sub check { } } - sub dump { my $self = shift; foreach (@{$self->{frus}}) { @@ -53,7 +43,6 @@ sub dump { package Classes::FCEOS::Component::FruSubsystem::Fcu; our @ISA = qw(Classes::FCEOS::Component::FruSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/FCMGMT.pm b/plugins-scripts/Classes/FCMGMT.pm index a41b02fd..9687a32e 100644 --- a/plugins-scripts/Classes/FCMGMT.pm +++ b/plugins-scripts/Classes/FCMGMT.pm @@ -1,8 +1,4 @@ package Classes::FCMGMT; - -use strict; - -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - our @ISA = qw(Classes::Device); +use strict; diff --git a/plugins-scripts/Classes/FCMGMT/Component/EnvironmentalSubsystem.pm b/plugins-scripts/Classes/FCMGMT/Component/EnvironmentalSubsystem.pm index 832f5bf6..f6c4594d 100644 --- a/plugins-scripts/Classes/FCMGMT/Component/EnvironmentalSubsystem.pm +++ b/plugins-scripts/Classes/FCMGMT/Component/EnvironmentalSubsystem.pm @@ -1,38 +1,24 @@ package Classes::FCMGMT::Component::EnvironmentalSubsystem; our @ISA = qw(Classes::FCMGMT); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - method => $params{method}, - condition => $params{condition}, - status => $params{status}, - sensor_subsystem => undef, - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; $self->{sensor_subsystem} = - Classes::FCMGMT::Component::SensorSubsystem->new(%params); + Classes::FCMGMT::Component::SensorSubsystem->new(); } sub check { my $self = shift; - my $errorfound = 0; $self->{sensor_subsystem}->check(); if (! $self->check_messages()) { $self->add_message(OK, "environmental hardware working fine"); diff --git a/plugins-scripts/Classes/FCMGMT/Component/SensorSubsystem.pm b/plugins-scripts/Classes/FCMGMT/Component/SensorSubsystem.pm index e3fabfa2..0b9b50a6 100644 --- a/plugins-scripts/Classes/FCMGMT/Component/SensorSubsystem.pm +++ b/plugins-scripts/Classes/FCMGMT/Component/SensorSubsystem.pm @@ -1,27 +1,18 @@ package Classes::FCMGMT::Component::SensorSubsystem; our @ISA = qw(Classes::FCMGMT::Component::EnvironmentalSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - sensors => [], - sensorthresholds => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my $sensors = {}; foreach ($self->get_snmp_table_objects( 'FCMGMT-MIB', 'fcConnUnitSensorTable')) { $_->{fcConnUnitSensorIndex} ||= $_->{indices}->[-1]; @@ -32,7 +23,6 @@ sub init { sub check { my $self = shift; - my $errorfound = 0; $self->add_info('checking sensors'); $self->blacklist('ses', ''); if (scalar (@{$self->{sensors}}) == 0) { @@ -43,7 +33,6 @@ sub check { } } - sub dump { my $self = shift; foreach (@{$self->{sensors}}) { @@ -54,7 +43,6 @@ sub dump { package Classes::FCMGMT::Component::SensorSubsystem::Sensor; our @ISA = qw(Classes::FCMGMT::Component::SensorSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/FabOS.pm b/plugins-scripts/Classes/FabOS.pm index 36d1905a..e87cd90e 100644 --- a/plugins-scripts/Classes/FabOS.pm +++ b/plugins-scripts/Classes/FabOS.pm @@ -1,56 +1,17 @@ package Classes::FabOS; - -use strict; - -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - our @ISA = qw(Classes::Brocade); +use strict; sub init { my $self = shift; - my %params = @_; - $self->{components} = { - powersupply_subsystem => undef, - fan_subsystem => undef, - temperature_subsystem => undef, - cpu_subsystem => undef, - }; - $self->{serial} = 'unknown'; - $self->{product} = 'unknown'; - $self->{romversion} = 'unknown'; - # serial is 1.3.6.1.2.1.47.1.1.1.1.11.1 - #$self->collect(); - if (! $self->check_messages()) { - ##$self->set_serial(); - if ($self->mode =~ /device::hardware::health/) { - $self->analyze_environmental_subsystem(); - $self->check_environmental_subsystem(); - } elsif ($self->mode =~ /device::hardware::load/) { - $self->analyze_cpu_subsystem(); - $self->check_cpu_subsystem(); - } elsif ($self->mode =~ /device::hardware::memory/) { - $self->analyze_mem_subsystem(); - $self->check_mem_subsystem(); - } + if ($self->mode =~ /device::hardware::health/) { + $self->analyze_and_check_environmental_subsystem("Classes::FabOS::Component::EnvironmentalSubsystem"); + } elsif ($self->mode =~ /device::hardware::load/) { + $self->analyze_and_check_cpu_subsystem("Classes::FabOS::Component::CpuSubsystem"); + } elsif ($self->mode =~ /device::hardware::memory/) { + $self->analyze_and_check_mem_subsystem("Classes::FabOS::Component::MemSubsystem"); + } else { + $self->no_such_mode(); } } -sub analyze_environmental_subsystem { - my $self = shift; - $self->{components}->{environmental_subsystem} = - Classes::FabOS::Component::EnvironmentalSubsystem->new(); -} - -sub analyze_cpu_subsystem { - my $self = shift; - $self->{components}->{cpu_subsystem} = - Classes::FabOS::Component::CpuSubsystem->new(); -#printf "%s\n", Data::Dumper::Dumper($self->{components}); -} - -sub analyze_mem_subsystem { - my $self = shift; - $self->{components}->{mem_subsystem} = - Classes::FabOS::Component::MemSubsystem->new(); -} - diff --git a/plugins-scripts/Classes/FabOS/Component/CpuSubsystem.pm b/plugins-scripts/Classes/FabOS/Component/CpuSubsystem.pm index e7e4ac4a..576e24a0 100644 --- a/plugins-scripts/Classes/FabOS/Component/CpuSubsystem.pm +++ b/plugins-scripts/Classes/FabOS/Component/CpuSubsystem.pm @@ -1,26 +1,18 @@ package Classes::FabOS::Component::CpuSubsystem; our @ISA = qw(Classes::FabOS); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - cpus => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; my $type = 0; foreach (qw(swCpuUsage swCpuNoOfRetries swCpuUsageLimit swCpuPollingInterval swCpuAction)) { diff --git a/plugins-scripts/Classes/FabOS/Component/EnvironmentalSubsystem.pm b/plugins-scripts/Classes/FabOS/Component/EnvironmentalSubsystem.pm index 798b7202..fac909b3 100644 --- a/plugins-scripts/Classes/FabOS/Component/EnvironmentalSubsystem.pm +++ b/plugins-scripts/Classes/FabOS/Component/EnvironmentalSubsystem.pm @@ -1,38 +1,24 @@ package Classes::FabOS::Component::EnvironmentalSubsystem; our @ISA = qw(Classes::FabOS); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - method => $params{method}, - condition => $params{condition}, - status => $params{status}, - sensor_subsystem => undef, - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; $self->{sensor_subsystem} = Classes::FabOS::Component::SensorSubsystem->new(%params); } sub check { my $self = shift; - my $errorfound = 0; $self->{sensor_subsystem}->check(); if (! $self->check_messages()) { $self->add_message(OK, "environmental hardware working fine"); diff --git a/plugins-scripts/Classes/FabOS/Component/MemSubsystem.pm b/plugins-scripts/Classes/FabOS/Component/MemSubsystem.pm index 8f8515e2..b67ea016 100644 --- a/plugins-scripts/Classes/FabOS/Component/MemSubsystem.pm +++ b/plugins-scripts/Classes/FabOS/Component/MemSubsystem.pm @@ -1,31 +1,18 @@ package Classes::FabOS::Component::MemSubsystem; our @ISA = qw(Classes::FabOS); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - mems => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; - my $snmpwalk = $params{rawdata}; - my $ignore_redundancy = $params{ignore_redundancy}; - my $type = 0; foreach (qw(swMemUsage swMemUsageLimit1 swMemUsageLimit3 swMemPollingInterval swMemNoOfRetries swMemAction)) { $self->{$_} = $self->valid_response('SW-MIB', $_, 0); diff --git a/plugins-scripts/Classes/FabOS/Component/SensorSubsystem.pm b/plugins-scripts/Classes/FabOS/Component/SensorSubsystem.pm index e6369b1b..baaa2ee1 100644 --- a/plugins-scripts/Classes/FabOS/Component/SensorSubsystem.pm +++ b/plugins-scripts/Classes/FabOS/Component/SensorSubsystem.pm @@ -1,27 +1,18 @@ package Classes::FabOS::Component::SensorSubsystem; our @ISA = qw(Classes::FabOS::Component::EnvironmentalSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - sensors => [], - sensorthresholds => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my $sensors = {}; foreach ($self->get_snmp_table_objects( 'SW-MIB', 'swSensorTable')) { push(@{$self->{sensors}}, @@ -35,7 +26,6 @@ sub init { sub check { my $self = shift; - my $errorfound = 0; $self->add_info('checking sensors'); $self->blacklist('ses', ''); if (scalar (@{$self->{sensors}}) == 0) { @@ -46,7 +36,6 @@ sub check { } } - sub dump { my $self = shift; foreach (@{$self->{sensors}}) { @@ -57,7 +46,6 @@ sub dump { package Classes::FabOS::Component::SensorSubsystem::Sensor; our @ISA = qw(Classes::FabOS::Component::SensorSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; @@ -115,9 +103,9 @@ sub dump { printf "\n"; } + package Classes::FabOS::Component::SensorSubsystem::SensorThreshold; our @ISA = qw(Classes::FabOS::Component::SensorSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/Fortigate.pm b/plugins-scripts/Classes/Fortigate.pm index f50c48ac..878e4066 100644 --- a/plugins-scripts/Classes/Fortigate.pm +++ b/plugins-scripts/Classes/Fortigate.pm @@ -1,56 +1,17 @@ package Classes::Fortigate; - -use strict; - -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - our @ISA = qw(Classes::Brocade); +use strict; sub init { my $self = shift; - my %params = @_; - $self->{components} = { - powersupply_subsystem => undef, - fan_subsystem => undef, - temperature_subsystem => undef, - cpu_subsystem => undef, - }; - $self->{serial} = 'unknown'; - $self->{product} = 'unknown'; - $self->{romversion} = 'unknown'; - # serial is 1.3.6.1.2.1.47.1.1.1.1.11.1 - #$self->collect(); - if (! $self->check_messages()) { - ##$self->set_serial(); - if ($self->mode =~ /device::hardware::health/) { - $self->analyze_environmental_subsystem(); - $self->check_environmental_subsystem(); - } elsif ($self->mode =~ /device::hardware::load/) { - $self->analyze_cpu_subsystem(); - $self->check_cpu_subsystem(); - } elsif ($self->mode =~ /device::hardware::memory/) { - $self->analyze_mem_subsystem(); - $self->check_mem_subsystem(); - } + if ($self->mode =~ /device::hardware::health/) { + $self->analyze_and_check_environmental_subsystem("Classes::Fortigate::Component::EnvironmentalSubsystem"); + } elsif ($self->mode =~ /device::hardware::load/) { + $self->analyze_and_check_cpu_subsystem("Classes::Fortigate::Component::CpuSubsystem"); + } elsif ($self->mode =~ /device::hardware::memory/) { + $self->analyze_and_check_mem_subsystem("Classes::Fortigate::Component::MemSubsystem"); + } else { + $self->no_such_mode(); } } -sub analyze_environmental_subsystem { - my $self = shift; - $self->{components}->{environmental_subsystem} = - Classes::Fortigate::Component::EnvironmentalSubsystem->new(); -} - -sub analyze_cpu_subsystem { - my $self = shift; - $self->{components}->{cpu_subsystem} = - Classes::Fortigate::Component::CpuSubsystem->new(); -#printf "%s\n", Data::Dumper::Dumper($self->{components}); -} - -sub analyze_mem_subsystem { - my $self = shift; - $self->{components}->{mem_subsystem} = - Classes::Fortigate::Component::MemSubsystem->new(); -} - diff --git a/plugins-scripts/Classes/Fortigate/Component/CpuSubsystem.pm b/plugins-scripts/Classes/Fortigate/Component/CpuSubsystem.pm index 01d03ce4..b03d1c95 100644 --- a/plugins-scripts/Classes/Fortigate/Component/CpuSubsystem.pm +++ b/plugins-scripts/Classes/Fortigate/Component/CpuSubsystem.pm @@ -1,20 +1,13 @@ package Classes::Fortigate::Component::CpuSubsystem; our @ISA = qw(Classes::Fortigate); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - cpus => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } diff --git a/plugins-scripts/Classes/Fortigate/Component/DiskSubsystem.pm b/plugins-scripts/Classes/Fortigate/Component/DiskSubsystem.pm index bbb9542c..8e785b38 100644 --- a/plugins-scripts/Classes/Fortigate/Component/DiskSubsystem.pm +++ b/plugins-scripts/Classes/Fortigate/Component/DiskSubsystem.pm @@ -1,21 +1,13 @@ package Classes::Fortigate::Component::DiskSubsystem; our @ISA = qw(Classes::Fortigate::Component::EnvironmentalSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - disks => [], - diskthresholds => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } @@ -31,7 +23,6 @@ sub init { sub check { my $self = shift; - my $errorfound = 0; $self->add_info('checking disks'); $self->blacklist('di', ''); if (! defined $self->{usage}) { diff --git a/plugins-scripts/Classes/Fortigate/Component/EnvironmentalSubsystem.pm b/plugins-scripts/Classes/Fortigate/Component/EnvironmentalSubsystem.pm index ca89f62a..2c126f8e 100644 --- a/plugins-scripts/Classes/Fortigate/Component/EnvironmentalSubsystem.pm +++ b/plugins-scripts/Classes/Fortigate/Component/EnvironmentalSubsystem.pm @@ -1,40 +1,26 @@ package Classes::Fortigate::Component::EnvironmentalSubsystem; our @ISA = qw(Classes::Fortigate); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - method => $params{method}, - condition => $params{condition}, - status => $params{status}, - sensor_subsystem => undef, - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; $self->{sensor_subsystem} = - Classes::Fortigate::Component::SensorSubsystem->new(%params); + Classes::Fortigate::Component::SensorSubsystem->new(); $self->{disk_subsystem} = - Classes::Fortigate::Component::DiskSubsystem->new(%params); + Classes::Fortigate::Component::DiskSubsystem->new(); } sub check { my $self = shift; - my $errorfound = 0; $self->{sensor_subsystem}->check(); $self->{disk_subsystem}->check(); if (! $self->check_messages()) { diff --git a/plugins-scripts/Classes/Fortigate/Component/MemSubsystem.pm b/plugins-scripts/Classes/Fortigate/Component/MemSubsystem.pm index a2dc5d70..4c8431da 100644 --- a/plugins-scripts/Classes/Fortigate/Component/MemSubsystem.pm +++ b/plugins-scripts/Classes/Fortigate/Component/MemSubsystem.pm @@ -1,28 +1,18 @@ package Classes::Fortigate::Component::MemSubsystem; our @ISA = qw(Classes::Fortigate); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - mems => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; foreach (qw(fgSysMemUsage)) { $self->{$_} = $self->get_snmp_object('FORTINET-FORTIGATE-MIB', $_, 0); } @@ -30,7 +20,6 @@ sub init { sub check { my $self = shift; - my $errorfound = 0; $self->add_info('checking memory'); $self->blacklist('m', ''); if (defined $self->{fgSysMemUsage}) { diff --git a/plugins-scripts/Classes/Fortigate/Component/SensorSubsystem.pm b/plugins-scripts/Classes/Fortigate/Component/SensorSubsystem.pm index 902c3284..da4b75df 100644 --- a/plugins-scripts/Classes/Fortigate/Component/SensorSubsystem.pm +++ b/plugins-scripts/Classes/Fortigate/Component/SensorSubsystem.pm @@ -1,27 +1,18 @@ package Classes::Fortigate::Component::SensorSubsystem; our @ISA = qw(Classes::Fortigate::Component::EnvironmentalSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - sensors => [], - sensorthresholds => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my $sensors = {}; foreach ($self->get_snmp_table_objects( 'FORTINET-FORTIGATE-MIB', 'fgHwSensorTable')) { push(@{$self->{sensors}}, @@ -42,7 +33,6 @@ sub check { } } - sub dump { my $self = shift; foreach (@{$self->{sensors}}) { @@ -53,7 +43,6 @@ sub dump { package Classes::Fortigate::Component::SensorSubsystem::Sensor; our @ISA = qw(Classes::Fortigate::Component::SensorSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/Foundry.pm b/plugins-scripts/Classes/Foundry.pm index f6f812a8..124d5f99 100644 --- a/plugins-scripts/Classes/Foundry.pm +++ b/plugins-scripts/Classes/Foundry.pm @@ -1,60 +1,19 @@ package Classes::Foundry; - -use strict; - -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - our @ISA = qw(Classes::Device); +use strict; sub init { my $self = shift; - my %params = @_; - $self->SUPER::init(%params); - $self->{components} = { - powersupply_subsystem => undef, - fan_subsystem => undef, - temperature_subsystem => undef, - cpu_subsystem => undef, - slb_subsystem => undef, - }; - if (! $self->check_messages()) { - if ($self->mode =~ /device::hardware::health/) { - $self->analyze_environmental_subsystem(); - $self->check_environmental_subsystem(); - } elsif ($self->mode =~ /device::hardware::load/) { - $self->analyze_cpu_subsystem(); - $self->check_cpu_subsystem(); - } elsif ($self->mode =~ /device::hardware::memory/) { - $self->analyze_mem_subsystem(); - $self->check_mem_subsystem(); - } elsif ($self->mode =~ /device::lb/) { - $self->analyze_slb_subsystem(); - $self->check_slb_subsystem(); - } + if ($self->mode =~ /device::hardware::health/) { + $self->analyze_and_check_environmental_subsystem("Classes::Foundry::Component::EnvironmentalSubsystem"); + } elsif ($self->mode =~ /device::hardware::load/) { + $self->analyze_and_check_cpu_subsystem("Classes::Foundry::Component::CpuSubsystem"); + } elsif ($self->mode =~ /device::hardware::memory/) { + $self->analyze_and_check_mem_subsystem("Classes::Foundry::Component::MemSubsystem"); + } elsif ($self->mode =~ /device::lb/) { + $self->analyze_and_check_slb_subsystem("Classes::Foundry::Component::SLBSubsystem"); + } else { + $self->no_such_mode(); } } -sub analyze_environmental_subsystem { - my $self = shift; - $self->{components}->{environmental_subsystem} = - Classes::Foundry::Component::EnvironmentalSubsystem->new(); -} - -sub analyze_cpu_subsystem { - my $self = shift; - $self->{components}->{cpu_subsystem} = - Classes::Foundry::Component::CpuSubsystem->new(); -} - -sub analyze_mem_subsystem { - my $self = shift; - $self->{components}->{mem_subsystem} = - Classes::Foundry::Component::MemSubsystem->new(); -} - -sub analyze_slb_subsystem { - my $self = shift; - $self->{components}->{slb_subsystem} = - Classes::Foundry::Component::SLBSubsystem->new(); -} - diff --git a/plugins-scripts/Classes/Foundry/Component/CpuSubsystem.pm b/plugins-scripts/Classes/Foundry/Component/CpuSubsystem.pm index 476b0cba..b468ddd2 100644 --- a/plugins-scripts/Classes/Foundry/Component/CpuSubsystem.pm +++ b/plugins-scripts/Classes/Foundry/Component/CpuSubsystem.pm @@ -1,26 +1,18 @@ package Classes::Foundry::Component::CpuSubsystem; our @ISA = qw(Classes::Foundry); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - loads => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; foreach ($self->get_snmp_table_objects( 'FOUNDRY-SN-AGENT-MIB', 'snAgentCpuUtilTable')) { push(@{$self->{cpus}}, @@ -114,7 +106,6 @@ sub unix_dump { package Classes::Foundry::Component::CpuSubsystem::Cpu; our @ISA = qw(Classes::Foundry::Component::CpuSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; @@ -175,7 +166,6 @@ sub dump { package Classes::Foundry::Component::CpuSubsystem::Load; our @ISA = qw(Classes::Foundry::Component::CpuSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/Foundry/Component/EnvironmentalSubsystem.pm b/plugins-scripts/Classes/Foundry/Component/EnvironmentalSubsystem.pm index 181095b5..cf487de3 100644 --- a/plugins-scripts/Classes/Foundry/Component/EnvironmentalSubsystem.pm +++ b/plugins-scripts/Classes/Foundry/Component/EnvironmentalSubsystem.pm @@ -1,44 +1,28 @@ package Classes::Foundry::Component::EnvironmentalSubsystem; our @ISA = qw(Classes::Foundry); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - method => $params{method}, - condition => $params{condition}, - status => $params{status}, - powersupply_subsystem => undef, - fan_subsystem => undef, - temperature_subsystem => undef, - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; $self->{powersupply_subsystem} = - Classes::Foundry::Component::PowersupplySubsystem->new(%params); + Classes::Foundry::Component::PowersupplySubsystem->new(); $self->{fan_subsystem} = - Classes::Foundry::Component::FanSubsystem->new(%params); + Classes::Foundry::Component::FanSubsystem->new(); $self->{temperature_subsystem} = - Classes::Foundry::Component::TemperatureSubsystem->new(%params); + Classes::Foundry::Component::TemperatureSubsystem->new(); } sub check { my $self = shift; - my $errorfound = 0; $self->{powersupply_subsystem}->check(); $self->{fan_subsystem}->check(); $self->{temperature_subsystem}->check(); diff --git a/plugins-scripts/Classes/Foundry/Component/FanSubsystem.pm b/plugins-scripts/Classes/Foundry/Component/FanSubsystem.pm index 0c3ffbfa..f16cc67c 100644 --- a/plugins-scripts/Classes/Foundry/Component/FanSubsystem.pm +++ b/plugins-scripts/Classes/Foundry/Component/FanSubsystem.pm @@ -1,20 +1,13 @@ package Classes::Foundry::Component::FanSubsystem; our @ISA = qw(Classes::Foundry::Component::EnvironmentalSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - fans => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } @@ -40,7 +33,6 @@ sub check { } } - sub dump { my $self = shift; foreach (@{$self->{fans}}) { @@ -51,7 +43,6 @@ sub dump { package Classes::Foundry::Component::FanSubsystem::Fan; our @ISA = qw(Classes::Foundry::Component::FanSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/Foundry/Component/MemSubsystem.pm b/plugins-scripts/Classes/Foundry/Component/MemSubsystem.pm index 163a81b4..192b0e4f 100644 --- a/plugins-scripts/Classes/Foundry/Component/MemSubsystem.pm +++ b/plugins-scripts/Classes/Foundry/Component/MemSubsystem.pm @@ -1,29 +1,18 @@ package Classes::Foundry::Component::MemSubsystem; our @ISA = qw(Classes::Foundry); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - mems => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; - my $snmpwalk = $params{rawdata}; foreach (qw(snAgGblDynMemUtil snAgGblDynMemTotal snAgGblDynMemFree)) { $self->{$_} = $self->get_snmp_object('FOUNDRY-SN-AGENT-MIB', $_); } @@ -31,7 +20,6 @@ sub init { sub check { my $self = shift; - my $errorfound = 0; $self->add_info('checking memory'); $self->blacklist('m', ''); if (defined $self->{snAgGblDynMemUtil}) { diff --git a/plugins-scripts/Classes/Foundry/Component/PowersupplySubsystem.pm b/plugins-scripts/Classes/Foundry/Component/PowersupplySubsystem.pm index dc4b773d..cb956015 100644 --- a/plugins-scripts/Classes/Foundry/Component/PowersupplySubsystem.pm +++ b/plugins-scripts/Classes/Foundry/Component/PowersupplySubsystem.pm @@ -1,20 +1,13 @@ package Classes::Foundry::Component::PowersupplySubsystem; our @ISA = qw(Classes::Foundry::Component::EnvironmentalSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - supplies => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } @@ -40,7 +33,6 @@ sub check { } } - sub dump { my $self = shift; foreach (@{$self->{supplies}}) { @@ -51,7 +43,6 @@ sub dump { package Classes::Foundry::Component::PowersupplySubsystem::Powersupply; our @ISA = qw(Classes::Foundry::Component::PowersupplySubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/Foundry/Component/SLBSubsystem.pm b/plugins-scripts/Classes/Foundry/Component/SLBSubsystem.pm index 7acad805..7f38a265 100644 --- a/plugins-scripts/Classes/Foundry/Component/SLBSubsystem.pm +++ b/plugins-scripts/Classes/Foundry/Component/SLBSubsystem.pm @@ -1,29 +1,13 @@ package Classes::Foundry::Component::SLBSubsystem; our @ISA = qw(Classes::Foundry); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - virtualservers => [], - realservers => [], - bindings => [], - vsdict => {}, - vspdict => {}, - vspsdict => {}, - rsdict => {}, - rsstdict => {}, - rspstdict => {}, - bindingdict => {}, - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } @@ -39,7 +23,6 @@ sub update_caches { sub init { my $self = shift; - my %params = @_; # opt->name can be servername:serverport my $original_name = $self->opts->name; if ($self->mode =~ /device::lb::session::usage/) { @@ -179,7 +162,6 @@ sub init { sub check { my $self = shift; - my $errorfound = 0; $self->add_info('checking slb virtual servers'); $self->blacklist('vip', ''); if ($self->mode =~ /device::lb::session::usage/) { @@ -239,7 +221,6 @@ sub add_port { package Classes::Foundry::Component::SLBSubsystem::VirtualServer; our @ISA = qw(Classes::Foundry::Component::SLBSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; @@ -299,7 +280,6 @@ sub dump { package Classes::Foundry::Component::SLBSubsystem::VirtualServerPort; our @ISA = qw(Classes::Foundry::Component::SLBSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; @@ -429,7 +409,6 @@ sub dump { package Classes::Foundry::Component::SLBSubsystem::RealServer; our @ISA = qw(Classes::Foundry::Component::SLBSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; @@ -477,7 +456,6 @@ sub dump { package Classes::Foundry::Component::SLBSubsystem::RealServerPort; our @ISA = qw(Classes::Foundry::Component::SLBSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; @@ -525,7 +503,6 @@ sub dump { package Classes::Foundry::Component::SLBSubsystem::Binding; our @ISA = qw(Classes::Foundry::Component::SLBSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/Foundry/Component/TemperatureSubsystem.pm b/plugins-scripts/Classes/Foundry/Component/TemperatureSubsystem.pm index 1b11eef2..72366e36 100644 --- a/plugins-scripts/Classes/Foundry/Component/TemperatureSubsystem.pm +++ b/plugins-scripts/Classes/Foundry/Component/TemperatureSubsystem.pm @@ -1,26 +1,18 @@ package Classes::Foundry::Component::TemperatureSubsystem; our @ISA = qw(Classes::Foundry); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - temperatures => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; my $temp = 0; foreach ($self->get_snmp_table_objects( 'FOUNDRY-SN-AGENT-MIB', 'snAgentTempTable')) { @@ -52,7 +44,6 @@ sub dump { package Classes::Foundry::Component::TemperatureSubsystem::Temperature; our @ISA = qw(Classes::Foundry::Component::TemperatureSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/Generic.pm b/plugins-scripts/Classes/Generic.pm deleted file mode 100644 index 3d9d3468..00000000 --- a/plugins-scripts/Classes/Generic.pm +++ /dev/null @@ -1,40 +0,0 @@ -package Classes::Generic; - -use strict; - -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - -our @ISA = qw(Classes::Device); - - -sub init { - my $self = shift; - if ($self->mode =~ /device::interfaces::aggregation::availability/) { - my $aggregation = NWC::IFMIB::Component::LinkAggregation->new(); - #$self->analyze_interface_subsystem(); - $aggregation->check(); - } elsif ($self->mode =~ /device::interfaces/) { - $self->analyze_interface_subsystem(); - $self->check_interface_subsystem(); - } elsif ($self->mode =~ /device::bgp/) { - $self->analyze_bgp_subsystem(); - $self->check_bgp_subsystem(); - } else { - $self->init(); - #$self->no_such_mode(); - } -} - - -sub analyze_interface_subsystem { - my $self = shift; - $self->{components}->{interface_subsystem} = - Classes::IFMIB::Component::InterfaceSubsystem->new(); -} - -sub analyze_bgp_subsystem { - my $self = shift; - $self->{components}->{bgp_subsystem} = - Classes::BGP::Component::PeerSubsystem->new(); -} - diff --git a/plugins-scripts/Classes/HOSTRESOURCESMIB.pm b/plugins-scripts/Classes/HOSTRESOURCESMIB.pm index 56fd1c62..7a5febc1 100644 --- a/plugins-scripts/Classes/HOSTRESOURCESMIB.pm +++ b/plugins-scripts/Classes/HOSTRESOURCESMIB.pm @@ -1,8 +1,4 @@ package Classes::HOSTRESOURCESMIB; - -use strict; - -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - our @ISA = qw(Classes::Device); +use strict; diff --git a/plugins-scripts/Classes/HOSTRESOURCESMIB/Component/CpuSubsystem.pm b/plugins-scripts/Classes/HOSTRESOURCESMIB/Component/CpuSubsystem.pm index c3d70dc9..ef37dcab 100644 --- a/plugins-scripts/Classes/HOSTRESOURCESMIB/Component/CpuSubsystem.pm +++ b/plugins-scripts/Classes/HOSTRESOURCESMIB/Component/CpuSubsystem.pm @@ -1,26 +1,18 @@ package Classes::HOSTRESOURCESMIB::Component::CpuSubsystem; our @ISA = qw(Classes::HOSTRESOURCESMIB); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - cpus => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my $cpus = {}; my $idx = 0; foreach ($self->get_snmp_table_objects( 'HOST-RESOURCES-MIB', 'hrProcessorTable')) { @@ -32,7 +24,6 @@ sub init { sub check { my $self = shift; - my $errorfound = 0; $self->add_info('checking cpus'); $self->blacklist('cpus', ''); foreach (@{$self->{cpus}}) { @@ -50,7 +41,6 @@ sub dump { package Classes::HOSTRESOURCESMIB::Component::CpuSubsystem::Cpu; our @ISA = qw(Classes::HOSTRESOURCESMIB::Component::CpuSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/HOSTRESOURCESMIB/Component/DiskSubsystem.pm b/plugins-scripts/Classes/HOSTRESOURCESMIB/Component/DiskSubsystem.pm index 3e0075c1..3003f18a 100644 --- a/plugins-scripts/Classes/HOSTRESOURCESMIB/Component/DiskSubsystem.pm +++ b/plugins-scripts/Classes/HOSTRESOURCESMIB/Component/DiskSubsystem.pm @@ -1,29 +1,18 @@ package Classes::HOSTRESOURCESMIB::Component::DiskSubsystem; our @ISA = qw(Classes::HOSTRESOURCESMIB::Component::EnvironmentalSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - storages => [], - volumes => [], - disks => [], - diskthresholds => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my $disks = {}; foreach ($self->get_snmp_table_objects( 'HOST-RESOURCES-MIB', 'hrStorageTable')) { next if $_->{hrStorageType} ne 'hrStorageFixedDisk'; @@ -34,7 +23,6 @@ sub init { sub check { my $self = shift; - my $errorfound = 0; $self->add_info('checking disks'); $self->blacklist('ses', ''); foreach (@{$self->{storages}}) { @@ -52,7 +40,6 @@ sub dump { package Classes::HOSTRESOURCESMIB::Component::DiskSubsystem::Storage; our @ISA = qw(Classes::HOSTRESOURCESMIB::Component::DiskSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/HOSTRESOURCESMIB/Component/EnvironmentalSubsystem.pm b/plugins-scripts/Classes/HOSTRESOURCESMIB/Component/EnvironmentalSubsystem.pm index 24bcf80a..70f9ca42 100644 --- a/plugins-scripts/Classes/HOSTRESOURCESMIB/Component/EnvironmentalSubsystem.pm +++ b/plugins-scripts/Classes/HOSTRESOURCESMIB/Component/EnvironmentalSubsystem.pm @@ -1,39 +1,24 @@ package Classes::HOSTRESOURCESMIB::Component::EnvironmentalSubsystem; our @ISA = qw(Classes::HOSTRESOURCESMIB); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - method => $params{method}, - condition => $params{condition}, - status => $params{status}, - sensor_subsystem => undef, - disk_subsystem => undef, - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; $self->{disk_subsystem} = - Classes::HOSTRESOURCESMIB::Component::DiskSubsystem->new(%params); + Classes::HOSTRESOURCESMIB::Component::DiskSubsystem->new(); } sub check { my $self = shift; - my $errorfound = 0; $self->{disk_subsystem}->check(); if (! $self->check_messages()) { $self->add_message(OK, "environmental hardware working fine"); diff --git a/plugins-scripts/Classes/HOSTRESOURCESMIB/Component/MemSubsystem.pm b/plugins-scripts/Classes/HOSTRESOURCESMIB/Component/MemSubsystem.pm index 53c0d770..d96f274a 100644 --- a/plugins-scripts/Classes/HOSTRESOURCESMIB/Component/MemSubsystem.pm +++ b/plugins-scripts/Classes/HOSTRESOURCESMIB/Component/MemSubsystem.pm @@ -1,29 +1,18 @@ package Classes::HOSTRESOURCESMIB::Component::MemSubsystem; our @ISA = qw(Classes::HOSTRESOURCESMIB); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - storages => [], - volumes => [], - disks => [], - diskthresholds => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my $disks = {}; foreach ($self->get_snmp_table_objects( 'HOST-RESOURCES-MIB', 'hrStorageTable')) { next if $_->{hrStorageType} ne 'hrStorageRam'; diff --git a/plugins-scripts/Classes/HP.pm b/plugins-scripts/Classes/HP.pm index 06326495..27ac1f64 100644 --- a/plugins-scripts/Classes/HP.pm +++ b/plugins-scripts/Classes/HP.pm @@ -1,10 +1,6 @@ package Classes::HP; - -use strict; - -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - our @ISA = qw(Classes::Device); +use strict; use constant trees => ( '1.3.6.1.4.1.11.2.14.11.1.2', # HP-ICF-CHASSIS @@ -17,12 +13,12 @@ use constant trees => ( sub init { my $self = shift; - my %params = @_; - $self->SUPER::init(%params); if ($self->{productname} =~ /Procurve/i) { bless $self, 'Classes::HP::Procurve'; $self->debug('using Classes::HP::Procurve'); } - $self->init(); + if (ref($self) ne "Classes::HP") { + $self->init(); + } } diff --git a/plugins-scripts/Classes/HP/Procurve.pm b/plugins-scripts/Classes/HP/Procurve.pm index bdf8d670..bb9e0814 100644 --- a/plugins-scripts/Classes/HP/Procurve.pm +++ b/plugins-scripts/Classes/HP/Procurve.pm @@ -1,59 +1,17 @@ package Classes::HP::Procurve; - -use strict; - -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - our @ISA = qw(Classes::HP); +use strict; sub init { my $self = shift; - $self->{components} = { - cpu_subsystem => undef, - memory_subsystem => undef, - environmental_subsystem => undef, - }; - $self->{serial} = 'unknown'; - $self->{product} = 'unknown'; - $self->{romversion} = 'unknown'; - # serial is 1.3.6.1.2.1.47.1.1.1.1.11.1 - #$self->collect(); - if (! $self->check_messages()) { - ##$self->set_serial(); - if ($self->mode =~ /device::hardware::health/) { - $self->analyze_environmental_subsystem(); - #$self->auto_blacklist(); - $self->check_environmental_subsystem(); - } elsif ($self->mode =~ /device::hardware::load/) { - $self->analyze_cpu_subsystem(); - #$self->auto_blacklist(); - $self->check_cpu_subsystem(); - } elsif ($self->mode =~ /device::hardware::memory/) { - $self->analyze_mem_subsystem(); - #$self->auto_blacklist(); - $self->check_mem_subsystem(); - } elsif ($self->mode =~ /device::shinken::interface/) { - $self->analyze_interface_subsystem(); - $self->shinken_interface_subsystem(); - } + if ($self->mode =~ /device::hardware::health/) { + $self->analyze_and_check_environmental_subsystem("Classes::HP::Procurve::Component::EnvironmentalSubsystem"); + } elsif ($self->mode =~ /device::hardware::load/) { + $self->analyze_and_check_cpu_subsystem("Classes::HP::Procurve::Component::CpuSubsystem"); + } elsif ($self->mode =~ /device::hardware::memory/) { + $self->analyze_and_check_mem_subsystem("Classes::HP::Procurve::Component::MemSubsystem"); + } else { + $self->no_such_mode(); } } -sub analyze_environmental_subsystem { - my $self = shift; - $self->{components}->{environmental_subsystem} = - Classes::HP::Procurve::Component::EnvironmentalSubsystem->new(); -} - -sub analyze_cpu_subsystem { - my $self = shift; - $self->{components}->{cpu_subsystem} = - Classes::HP::Procurve::Component::CpuSubsystem->new(); -} - -sub analyze_mem_subsystem { - my $self = shift; - $self->{components}->{mem_subsystem} = - Classes::HP::Procurve::Component::MemSubsystem->new(); -} - diff --git a/plugins-scripts/Classes/HP/Procurve/Component/CpuSubsystem.pm b/plugins-scripts/Classes/HP/Procurve/Component/CpuSubsystem.pm index 3d0070c8..039b74c7 100644 --- a/plugins-scripts/Classes/HP/Procurve/Component/CpuSubsystem.pm +++ b/plugins-scripts/Classes/HP/Procurve/Component/CpuSubsystem.pm @@ -1,20 +1,13 @@ package Classes::HP::Procurve::Component::CpuSubsystem; our @ISA = qw(Classes::HP::Procurve); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - cpus => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } diff --git a/plugins-scripts/Classes/HP/Procurve/Component/EnvironmentalSubsystem.pm b/plugins-scripts/Classes/HP/Procurve/Component/EnvironmentalSubsystem.pm index 4fe04590..3489cfa0 100644 --- a/plugins-scripts/Classes/HP/Procurve/Component/EnvironmentalSubsystem.pm +++ b/plugins-scripts/Classes/HP/Procurve/Component/EnvironmentalSubsystem.pm @@ -1,38 +1,24 @@ package Classes::HP::Procurve::Component::EnvironmentalSubsystem; our @ISA = qw(Classes::HP::Procurve); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - method => $params{method}, - condition => $params{condition}, - status => $params{status}, - sensor_subsystem => undef, - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; $self->{sensor_subsystem} = - Classes::HP::Procurve::Component::SensorSubsystem->new(%params); + Classes::HP::Procurve::Component::SensorSubsystem->new(); } sub check { my $self = shift; - my $errorfound = 0; $self->{sensor_subsystem}->check(); if (! $self->check_messages()) { $self->add_message(OK, "environmental hardware working fine"); diff --git a/plugins-scripts/Classes/HP/Procurve/Component/MemSubsystem.pm b/plugins-scripts/Classes/HP/Procurve/Component/MemSubsystem.pm index b2ce6f20..1e870979 100644 --- a/plugins-scripts/Classes/HP/Procurve/Component/MemSubsystem.pm +++ b/plugins-scripts/Classes/HP/Procurve/Component/MemSubsystem.pm @@ -1,27 +1,18 @@ package Classes::HP::Procurve::Component::MemSubsystem; our @ISA = qw(Classes::HP::Procurve::Component::EnvironmentalSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - sensors => [], - sensorthresholds => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my $sensors = {}; foreach ($self->get_snmp_table_objects( 'NETSWITCH-MIB', 'hpLocalMemTable')) { push(@{$self->{mem}}, @@ -31,7 +22,6 @@ sub init { sub check { my $self = shift; - my $errorfound = 0; $self->add_info('checking memory'); $self->blacklist('m', ''); if (scalar (@{$self->{mem}}) == 0) { @@ -53,7 +43,6 @@ sub dump { package Classes::HP::Procurve::Component::MemSubsystem::Memory; our @ISA = qw(Classes::HP::Procurve::Component::MemSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/HP/Procurve/Component/SensorSubsystem.pm b/plugins-scripts/Classes/HP/Procurve/Component/SensorSubsystem.pm index bccf82b0..5cb15096 100644 --- a/plugins-scripts/Classes/HP/Procurve/Component/SensorSubsystem.pm +++ b/plugins-scripts/Classes/HP/Procurve/Component/SensorSubsystem.pm @@ -1,27 +1,18 @@ package Classes::HP::Procurve::Component::SensorSubsystem; our @ISA = qw(Classes::HP::Procurve::Component::EnvironmentalSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - sensors => [], - sensorthresholds => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my $sensors = {}; foreach ($self->get_snmp_table_objects( 'HP-ICF-CHASSIS-MIB', 'hpicfSensorTable')) { push(@{$self->{sensors}}, @@ -31,7 +22,6 @@ sub init { sub check { my $self = shift; - my $errorfound = 0; $self->add_info('checking sensors'); $self->blacklist('ses', ''); if (scalar (@{$self->{sensors}}) == 0) { @@ -42,7 +32,6 @@ sub check { } } - sub dump { my $self = shift; foreach (@{$self->{sensors}}) { @@ -53,7 +42,6 @@ sub dump { package Classes::HP::Procurve::Component::SensorSubsystem::Sensor; our @ISA = qw(Classes::HP::Procurve::Component::SensorSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/HSRP.pm b/plugins-scripts/Classes/HSRP.pm index 2fa749a0..6520036c 100644 --- a/plugins-scripts/Classes/HSRP.pm +++ b/plugins-scripts/Classes/HSRP.pm @@ -1,8 +1,4 @@ package Classes::HSRP; - -use strict; - -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - our @ISA = qw(Classes::Device); +use strict; diff --git a/plugins-scripts/Classes/HSRP/Component/HSRPSubsystem.pm b/plugins-scripts/Classes/HSRP/Component/HSRPSubsystem.pm index 45bfbbe7..4a2f325b 100644 --- a/plugins-scripts/Classes/HSRP/Component/HSRPSubsystem.pm +++ b/plugins-scripts/Classes/HSRP/Component/HSRPSubsystem.pm @@ -1,26 +1,18 @@ package Classes::HSRP::Component::HSRPSubsystem; our @ISA = qw(Classes::HSRP); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - groups => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; if ($self->mode =~ /device::hsrp/) { foreach ($self->get_snmp_table_objects( 'CISCO-HSRP-MIB', 'cHsrpGrpTable')) { @@ -34,7 +26,6 @@ sub init { sub check { my $self = shift; - my $errorfound = 0; $self->add_info('checking hsrp groups'); $self->blacklist('hhsrp', ''); if ($self->mode =~ /device::hsrp::list/) { @@ -62,7 +53,6 @@ sub dump { package Classes::HSRP::Component::HSRPSubsystem::Group; our @ISA = qw(Classes::HSRP::Component::HSRPSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/IFMIB.pm b/plugins-scripts/Classes/IFMIB.pm index 159b64f2..9fa0638a 100644 --- a/plugins-scripts/Classes/IFMIB.pm +++ b/plugins-scripts/Classes/IFMIB.pm @@ -1,8 +1,4 @@ package Classes::IFMIB; - -use strict; - -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - our @ISA = qw(Classes::Device); +use strict; diff --git a/plugins-scripts/Classes/IFMIB/Component/InterfaceSubsystem.pm b/plugins-scripts/Classes/IFMIB/Component/InterfaceSubsystem.pm index 287df85b..9cbb4cde 100644 --- a/plugins-scripts/Classes/IFMIB/Component/InterfaceSubsystem.pm +++ b/plugins-scripts/Classes/IFMIB/Component/InterfaceSubsystem.pm @@ -1,26 +1,18 @@ package Classes::IFMIB::Component::InterfaceSubsystem; our @ISA = qw(Classes::IFMIB); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - interfaces => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; if ($self->mode =~ /device::interfaces::list/) { $self->update_interface_cache(1); foreach my $ifIndex (keys %{$self->{interface_cache}}) { @@ -55,7 +47,6 @@ sub init { sub check { my $self = shift; - my $errorfound = 0; $self->add_info('checking interfaces'); $self->blacklist('ff', ''); if (scalar(@{$self->{interfaces}}) == 0) { @@ -262,7 +253,6 @@ sub dump { package Classes::IFMIB::Component::InterfaceSubsystem::Interface; our @ISA = qw(Classes::IFMIB::Component::InterfaceSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/IFMIB/Component/LinkAggregation.pm b/plugins-scripts/Classes/IFMIB/Component/LinkAggregation.pm index cf54e3da..d404f52a 100644 --- a/plugins-scripts/Classes/IFMIB/Component/LinkAggregation.pm +++ b/plugins-scripts/Classes/IFMIB/Component/LinkAggregation.pm @@ -1,26 +1,18 @@ package Classes::IFMIB::Component::LinkAggregation; our @ISA = qw(Classes::IFMIB); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - link_aggregations => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; if ($self->opts->name) { my @ifs = split(",", $self->opts->name); $self->{name} = shift @ifs; @@ -48,7 +40,6 @@ sub init { sub check { my $self = shift; - my $errorfound = 0; $self->add_info('checking link aggregation'); if (scalar(@{$self->{components}->{interface_subsystem}->{interfaces}}) == 0) { $self->add_message(UNKNOWN, 'no interfaces'); diff --git a/plugins-scripts/Classes/Juniper.pm b/plugins-scripts/Classes/Juniper.pm index 4f2c60cd..860d4e0a 100644 --- a/plugins-scripts/Classes/Juniper.pm +++ b/plugins-scripts/Classes/Juniper.pm @@ -1,10 +1,6 @@ package Classes::Juniper; - -use strict; - -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - our @ISA = qw(Classes::Device); +use strict; use constant trees => ( '1.3.6.1.4.1.4874.', @@ -13,11 +9,7 @@ use constant trees => ( sub init { my $self = shift; - my %params = @_; - $self->SUPER::init(%params); - if (ref($self) =~ /^Classes::Juniper/) { - # - } elsif ($self->{productname} =~ /NetScreen/i) { + if ($self->{productname} =~ /NetScreen/i) { bless $self, 'Classes::Juniper::NetScreen'; $self->debug('using Classes::Juniper::NetScreen'); } elsif ($self->{productname} =~ /Juniper.*MAG\-\d+/i) { @@ -25,10 +17,8 @@ sub init { bless $self, 'Classes::Juniper::IVE'; $self->debug('using Classes::Juniper::IVE'); } - $self->init(%params); + if (ref($self) ne "Classes::Juniper") { + $self->init(); + } } -# Classes::Device->init -# array aus signaturfunktion, signatur, klasse -# selber init - diff --git a/plugins-scripts/Classes/Juniper/IVE.pm b/plugins-scripts/Classes/Juniper/IVE.pm index c144dad5..89bdc67c 100644 --- a/plugins-scripts/Classes/Juniper/IVE.pm +++ b/plugins-scripts/Classes/Juniper/IVE.pm @@ -1,10 +1,6 @@ package Classes::Juniper::IVE; - -use strict; - -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - our @ISA = qw(Classes::Juniper); +use strict; use constant trees => ( '1.3.6.1.2.1', # mib-2 @@ -13,61 +9,16 @@ use constant trees => ( sub init { my $self = shift; - $self->{components} = { - powersupply_subsystem => undef, - fan_subsystem => undef, - temperature_subsystem => undef, - cpu_subsystem => undef, - memory_subsystem => undef, - disk_subsystem => undef, - environmental_subsystem => undef, - user_subsystem => undef, - }; - $self->{serial} = 'unknown'; - $self->{product} = 'unknown'; - $self->{romversion} = 'unknown'; - if (! $self->check_messages()) { - ##$self->set_serial(); - if ($self->mode =~ /device::hardware::health/) { - $self->analyze_environmental_subsystem(); - $self->check_environmental_subsystem(); - } elsif ($self->mode =~ /device::hardware::load/) { - $self->analyze_cpu_subsystem(); - $self->check_cpu_subsystem(); - } elsif ($self->mode =~ /device::hardware::memory/) { - $self->analyze_mem_subsystem(); - $self->check_mem_subsystem(); - } elsif ($self->mode =~ /device::users/) { - $self->analyze_user_subsystem(); - $self->check_user_subsystem(); - } elsif ($self->mode =~ /device::interfaces/) { - $self->analyze_interface_subsystem(); - $self->check_interface_subsystem(); - } + if ($self->mode =~ /device::hardware::health/) { + $self->analyze_and_check_environmental_subsystem("Classes::Juniper::IVE::Component::EnvironmentalSubsystem"); + } elsif ($self->mode =~ /device::hardware::load/) { + $self->analyze_and_check_cpu_subsystem("Classes::Juniper::IVE::Component::CpuSubsystem"); + } elsif ($self->mode =~ /device::hardware::memory/) { + $self->analyze_and_check_mem_subsystem("Classes::Juniper::IVE::Component::MemSubsystem"); + } elsif ($self->mode =~ /device::users/) { + $self->analyze_and_check_user_subsystem("Classes::Juniper::IVE::Component::UserSubsystem"); + } else { + $self->no_such_mode(); } } -sub analyze_mem_subsystem { - my $self = shift; - $self->{components}->{mem_subsystem} = - Classes::Juniper::IVE::Component::MemSubsystem->new(); -} - -sub analyze_cpu_subsystem { - my $self = shift; - $self->{components}->{cpu_subsystem} = - Classes::Juniper::IVE::Component::CpuSubsystem->new(); -} - -sub analyze_environmental_subsystem { - my $self = shift; - $self->{components}->{environmental_subsystem} = - Classes::Juniper::IVE::Component::EnvironmentalSubsystem->new(); -} - -sub analyze_user_subsystem { - my $self = shift; - $self->{components}->{user_subsystem} = - Classes::Juniper::IVE::Component::UserSubsystem->new(); -} - diff --git a/plugins-scripts/Classes/Juniper/IVE/Component/CpuSubsystem.pm b/plugins-scripts/Classes/Juniper/IVE/Component/CpuSubsystem.pm index 508b8b3c..ad915041 100644 --- a/plugins-scripts/Classes/Juniper/IVE/Component/CpuSubsystem.pm +++ b/plugins-scripts/Classes/Juniper/IVE/Component/CpuSubsystem.pm @@ -1,27 +1,18 @@ package Classes::Juniper::IVE::Component::CpuSubsystem; our @ISA = qw(Classes::Juniper::IVE); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - loads => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; - my $type = 0; $self->{iveCpuUtil} = $self->get_snmp_object('JUNIPER-IVE-MIB', 'iveCpuUtil'); } @@ -85,7 +76,6 @@ sub unix_dump { package Classes::Juniper::IVE::Component::CpuSubsystem::Load; our @ISA = qw(Classes::Juniper::IVE::Component::CpuSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/Juniper/IVE/Component/DiskSubsystem.pm b/plugins-scripts/Classes/Juniper/IVE/Component/DiskSubsystem.pm index dfd03a4f..a6e960bc 100644 --- a/plugins-scripts/Classes/Juniper/IVE/Component/DiskSubsystem.pm +++ b/plugins-scripts/Classes/Juniper/IVE/Component/DiskSubsystem.pm @@ -1,34 +1,24 @@ package Classes::Juniper::IVE::Component::DiskSubsystem; our @ISA = qw(Classes::Juniper::IVE::Component::EnvironmentalSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - disks => [], - diskthresholds => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my $disks = {}; $self->{diskFullPercent} = $self->get_snmp_object('JUNIPER-IVE-MIB', 'diskFullPercent'); } sub check { my $self = shift; - my $errorfound = 0; $self->add_info('checking disks'); $self->blacklist('di', ''); $self->add_info(sprintf 'disk is %.2f%% full', diff --git a/plugins-scripts/Classes/Juniper/IVE/Component/EnvironmentalSubsystem.pm b/plugins-scripts/Classes/Juniper/IVE/Component/EnvironmentalSubsystem.pm index 69354ddd..ee7a9f89 100644 --- a/plugins-scripts/Classes/Juniper/IVE/Component/EnvironmentalSubsystem.pm +++ b/plugins-scripts/Classes/Juniper/IVE/Component/EnvironmentalSubsystem.pm @@ -1,34 +1,20 @@ package Classes::Juniper::IVE::Component::EnvironmentalSubsystem; our @ISA = qw(Classes::SGOS); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - method => $params{method}, - condition => $params{condition}, - status => $params{status}, - sensor_subsystem => undef, - disk_subsystem => undef, - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; $self->{disk_subsystem} = - Classes::Juniper::IVE::Component::DiskSubsystem->new(%params); + Classes::Juniper::IVE::Component::DiskSubsystem->new(); foreach (qw(iveTemperature fanDescription psDescription raidDescription)) { $self->{$_} = $self->get_snmp_object('JUNIPER-IVE-MIB', $_); } @@ -36,7 +22,6 @@ sub init { sub check { my $self = shift; - my $errorfound = 0; $self->{disk_subsystem}->check(); $self->add_info(sprintf "temperature is %.2f deg", $self->{iveTemperature}); $self->set_thresholds(warning => 70, critical => 75); diff --git a/plugins-scripts/Classes/Juniper/IVE/Component/MemSubsystem.pm b/plugins-scripts/Classes/Juniper/IVE/Component/MemSubsystem.pm index bc0075ac..611e4ab6 100644 --- a/plugins-scripts/Classes/Juniper/IVE/Component/MemSubsystem.pm +++ b/plugins-scripts/Classes/Juniper/IVE/Component/MemSubsystem.pm @@ -1,35 +1,24 @@ package Classes::Juniper::IVE::Component::MemSubsystem; our @ISA = qw(Classes::Juniper::IVE); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - mems => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; $self->{iveMemoryUtil} = $self->get_snmp_object('JUNIPER-IVE-MIB', 'iveMemoryUtil'); $self->{iveSwapUtil} = $self->get_snmp_object('JUNIPER-IVE-MIB', 'iveSwapUtil'); } sub check { my $self = shift; - my $errorfound = 0; $self->add_info('checking memory'); $self->blacklist('m', ''); my $info = sprintf 'memory usage is %.2f%%, swap usage is %.2f%%', diff --git a/plugins-scripts/Classes/Juniper/IVE/Component/UserSubsystem.pm b/plugins-scripts/Classes/Juniper/IVE/Component/UserSubsystem.pm index 628f1c08..13c3bfed 100644 --- a/plugins-scripts/Classes/Juniper/IVE/Component/UserSubsystem.pm +++ b/plugins-scripts/Classes/Juniper/IVE/Component/UserSubsystem.pm @@ -1,28 +1,18 @@ package Classes::Juniper::IVE::Component::UserSubsystem; our @ISA = qw(Classes::Juniper::IVE); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - mems => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; foreach (qw(signedInWebUsers signedInMailUsers meetingUserCount iveConcurrentUsers clusterConcurrentUsers)) { $self->{$_} = $self->valid_response('JUNIPER-IVE-MIB', $_) || 0; } @@ -30,7 +20,6 @@ sub init { sub check { my $self = shift; - my $errorfound = 0; $self->add_info('checking memory'); $self->blacklist('m', ''); my $info = sprintf 'Users: cluster=%d, node=%d, web=%d, mail=%d, meeting=%d', diff --git a/plugins-scripts/Classes/Juniper/NetScreen.pm b/plugins-scripts/Classes/Juniper/NetScreen.pm index 96a9c0e0..3ec80094 100644 --- a/plugins-scripts/Classes/Juniper/NetScreen.pm +++ b/plugins-scripts/Classes/Juniper/NetScreen.pm @@ -1,10 +1,6 @@ package Classes::Juniper::NetScreen; - -use strict; - -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - our @ISA = qw(Classes::Juniper); +use strict; use constant trees => ( '1.3.6.1.2.1', # mib-2 @@ -13,47 +9,12 @@ use constant trees => ( sub init { my $self = shift; - $self->SUPER::init(); - $self->{components} = { - powersupply_subsystem => undef, - fan_subsystem => undef, - temperature_subsystem => undef, - cpu_subsystem => undef, - memory_subsystem => undef, - disk_subsystem => undef, - environmental_subsystem => undef, - }; - $self->{serial} = 'unknown'; - $self->{product} = 'unknown'; - $self->{romversion} = 'unknown'; - # serial is 1.3.6.1.2.1.47.1.1.1.1.11.1 - #$self->collect(); - if (! $self->check_messages()) { - ##$self->set_serial(); - if ($self->mode =~ /device::hardware::health/) { - $self->no_such_mode(); - } elsif ($self->mode =~ /device::hardware::load/) { - $self->analyze_cpu_subsystem(); - $self->check_cpu_subsystem(); - } elsif ($self->mode =~ /device::hardware::memory/) { - $self->analyze_mem_subsystem(); - $self->check_mem_subsystem(); - } elsif ($self->mode =~ /device::interfaces/) { - $self->analyze_interface_subsystem(); - $self->check_interface_subsystem(); - } + if ($self->mode =~ /device::hardware::load/) { + $self->analyze_and_check_cpu_subsystem("Classes::Juniper::NetScreen::Component::CpuSubsystem"); + } elsif ($self->mode =~ /device::hardware::memory/) { + $self->analyze_and_check_mem_subsystem("Classes::Juniper::NetScreen::Component::MemSubsystem"); + } else { + $self->no_such_mode(); } } -sub analyze_mem_subsystem { - my $self = shift; - $self->{components}->{mem_subsystem} = - Classes::Juniper::NetScreen::Component::MemSubsystem->new(); -} - -sub analyze_cpu_subsystem { - my $self = shift; - $self->{components}->{cpu_subsystem} = - Classes::Juniper::NetScreen::Component::CpuSubsystem->new(); -} - diff --git a/plugins-scripts/Classes/Juniper/NetScreen/Component/CpuSubsystem.pm b/plugins-scripts/Classes/Juniper/NetScreen/Component/CpuSubsystem.pm index ffa3a368..d652f811 100644 --- a/plugins-scripts/Classes/Juniper/NetScreen/Component/CpuSubsystem.pm +++ b/plugins-scripts/Classes/Juniper/NetScreen/Component/CpuSubsystem.pm @@ -1,27 +1,18 @@ package Classes::Juniper::NetScreen::Component::CpuSubsystem; our @ISA = qw(Classes::Juniper::NetScreen); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - loads => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; - my $type = 0; foreach (qw(nsResCpuAvg)) { $self->{$_} = $self->get_snmp_object('NETSCREEN-RESOURCE-MIB', $_); } @@ -55,38 +46,9 @@ sub dump { printf "\n"; } -sub unix_init { - my $self = shift; - my %params = @_; - my $type = 0; - foreach ($self->get_snmp_table_objects( - 'UCD-SNMP-MIB', 'laTable')) { - push(@{$self->{loads}}, - Classes::Juniper::NetScreen::Component::CpuSubsystem::Load->new(%{$_})); - } -} - -sub unix_check { - my $self = shift; - my $errorfound = 0; - $self->add_info('checking loads'); - $self->blacklist('c', ''); - foreach (@{$self->{loads}}) { - $_->check(); - } -} - -sub unix_dump { - my $self = shift; - foreach (@{$self->{loads}}) { - $_->dump(); - } -} - package Classes::Juniper::NetScreen::Component::CpuSubsystem::Load; our @ISA = qw(Classes::Juniper::NetScreen::Component::CpuSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/Juniper/NetScreen/Component/MemSubsystem.pm b/plugins-scripts/Classes/Juniper/NetScreen/Component/MemSubsystem.pm index fb6ed6a3..abb099bf 100644 --- a/plugins-scripts/Classes/Juniper/NetScreen/Component/MemSubsystem.pm +++ b/plugins-scripts/Classes/Juniper/NetScreen/Component/MemSubsystem.pm @@ -1,28 +1,18 @@ package Classes::Juniper::NetScreen::Component::MemSubsystem; our @ISA = qw(Classes::Juniper::NetScreen); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - mems => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; foreach (qw(nsResMemAllocate nsResMemLeft nsResMemFrag)) { $self->{$_} = $self->get_snmp_object('NETSCREEN-RESOURCE-MIB', $_); } @@ -32,7 +22,6 @@ sub init { sub check { my $self = shift; - my $errorfound = 0; $self->add_info('checking memory'); $self->blacklist('m', ''); if (defined $self->{mem_usage}) { diff --git a/plugins-scripts/Classes/MEOS.pm b/plugins-scripts/Classes/MEOS.pm index 77abd85f..cbe823e7 100644 --- a/plugins-scripts/Classes/MEOS.pm +++ b/plugins-scripts/Classes/MEOS.pm @@ -1,36 +1,17 @@ package Classes::MEOS; - -use strict; - -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - our @ISA = qw(Classes::Brocade); +use strict; sub init { my $self = shift; - my %params = @_; - $self->{components} = { - powersupply_subsystem => undef, - fan_subsystem => undef, - temperature_subsystem => undef, - cpu_subsystem => undef, - }; - $self->{serial} = 'unknown'; - $self->{product} = 'unknown'; - $self->{romversion} = 'unknown'; - # serial is 1.3.6.1.2.1.47.1.1.1.1.11.1 - #$self->collect(); - if (! $self->check_messages()) { - if ($self->mode =~ /device::hardware::health/) { - $self->analyze_environmental_subsystem(); - $self->check_environmental_subsystem(); - } elsif ($self->mode =~ /device::hardware::load/) { - $self->analyze_cpu_subsystem(); - $self->check_cpu_subsystem(); - } elsif ($self->mode =~ /device::hardware::memory/) { - $self->analyze_mem_subsystem(); - $self->check_mem_subsystem(); - } + if ($self->mode =~ /device::hardware::health/) { + $self->analyze_and_check_and_check_environmental_subsystem(); + } elsif ($self->mode =~ /device::hardware::load/) { + $self->analyze_and_check_and_check_cpu_subsystem("Classes::UCDMIB::Component::CpuSubsystem"); + } elsif ($self->mode =~ /device::hardware::memory/) { + $self->analyze_and_check_and_check_mem_subsystem("Classes::UCDMIB::Component::MemSubsystem"); + } else { + $self->no_such_mode(); } } @@ -42,20 +23,6 @@ sub analyze_environmental_subsystem { Classes::FCEOS::Component::EnvironmentalSubsystem->new(); } -sub analyze_cpu_subsystem { - my $self = shift; - $self->no_such_mode(); - $self->{components}->{cpu_subsystem} = - Classes::UCDMIB::Component::CpuSubsystem->new(); -} - -sub analyze_mem_subsystem { - my $self = shift; - $self->no_such_mode(); - $self->{components}->{mem_subsystem} = - Classes::UCDMIB::Component::MemSubsystem->new(); -} - sub check_environmental_subsystem { my $self = shift; $self->{components}->{environmental_subsystem1}->check(); diff --git a/plugins-scripts/Classes/MIBII.pm b/plugins-scripts/Classes/MIBII.pm index 0368e597..fa20dee0 100644 --- a/plugins-scripts/Classes/MIBII.pm +++ b/plugins-scripts/Classes/MIBII.pm @@ -1,8 +1,4 @@ package Classes::MIBII; - -use strict; - -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - our @ISA = qw(Classes::Device); +use strict; diff --git a/plugins-scripts/Classes/Nortel.pm b/plugins-scripts/Classes/Nortel.pm index 5da14b29..faf2f8b3 100644 --- a/plugins-scripts/Classes/Nortel.pm +++ b/plugins-scripts/Classes/Nortel.pm @@ -1,75 +1,19 @@ package Classes::Nortel; - -use strict; - -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - our @ISA = qw(Classes::Device); +use strict; sub init { my $self = shift; - my %params = @_; - $self->SUPER::init(%params); - $self->{components} = { - powersupply_subsystem => undef, - fan_subsystem => undef, - temperature_subsystem => undef, - cpu_subsystem => undef, - memory_subsystem => undef, - disk_subsystem => undef, - environmental_subsystem => undef, - }; - $self->{serial} = 'unknown'; - $self->{product} = 'unknown'; - $self->{romversion} = 'unknown'; - # serial is 1.3.6.1.2.1.47.1.1.1.1.11.1 - #$self->collect(); - if (! $self->check_messages()) { - ##$self->set_serial(); - if ($self->mode =~ /device::hardware::health/) { - $self->analyze_environmental_subsystem(); - #$self->auto_blacklist(); - $self->check_environmental_subsystem(); - } elsif ($self->mode =~ /device::hardware::load/) { - $self->analyze_cpu_subsystem(); - #$self->auto_blacklist(); - $self->check_cpu_subsystem(); - } elsif ($self->mode =~ /device::hardware::memory/) { - $self->analyze_mem_subsystem(); - #$self->auto_blacklist(); - $self->check_mem_subsystem(); - } elsif ($self->mode =~ /device::shinken::interface/) { - $self->analyze_interface_subsystem(); - $self->shinken_interface_subsystem(); - } elsif ($self->mode =~ /device::hsrp/) { - $self->analyze_hsrp_subsystem(); - $self->check_interface_subsystem(); - } + if ($self->mode =~ /device::hardware::health/) { + $self->analyze_and_check_environmental_subsystem("Classes::Nortel::Component::EnvironmentalSubsystem"); + } elsif ($self->mode =~ /device::hardware::load/) { + $self->analyze_and_check_cpu_subsystem("Classes::Nortel::Component::CpuSubsystem"); + } elsif ($self->mode =~ /device::hardware::memory/) { + $self->analyze_and_check_mem_subsystem("Classes::Nortel::Component::MemSubsystem"); + } elsif ($self->mode =~ /device::hsrp/) { + $self->analyze_and_check_hsrp_subsystem("Classes::HSRP::Component::HSRPSubsystem"); + } else { + $self->no_such_mode(); } } -sub analyze_hsrp_subsystem { - my $self = shift; - $self->{components}->{hsrp} = - Classes::HSRP::Component::HSRPSubsystem->new(); -} - -sub analyze_environmental_subsystem { - my $self = shift; - $self->{components}->{environmental_subsystem} = - Classes::Nortel::Component::EnvironmentalSubsystem->new(); -} - -sub analyze_cpu_subsystem { - my $self = shift; - $self->{components}->{cpu_subsystem} = - Classes::Nortel::Component::CpuSubsystem->new(); -} - -sub analyze_mem_subsystem { - my $self = shift; - $self->{components}->{mem_subsystem} = - Classes::Nortel::Component::MemSubsystem->new(); -} - - diff --git a/plugins-scripts/Classes/SGOS.pm b/plugins-scripts/Classes/SGOS.pm index c110fa35..bb94c44d 100644 --- a/plugins-scripts/Classes/SGOS.pm +++ b/plugins-scripts/Classes/SGOS.pm @@ -1,74 +1,21 @@ package Classes::SGOS; - -use strict; - -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - our @ISA = qw(Classes::Bluecoat); +use strict; sub init { my $self = shift; - my %params = @_; - $self->{components} = { - powersupply_subsystem => undef, - fan_subsystem => undef, - temperature_subsystem => undef, - cpu_subsystem => undef, - security_subsystem => undef, - }; - $self->{serial} = 'unknown'; - $self->{product} = 'unknown'; - $self->{romversion} = 'unknown'; - # serial is 1.3.6.1.2.1.47.1.1.1.1.11.1 - #$self->collect(); - if (! $self->check_messages()) { - ##$self->set_serial(); - if ($self->mode =~ /device::hardware::health/) { - $self->analyze_environmental_subsystem(); - $self->check_environmental_subsystem(); - } elsif ($self->mode =~ /device::hardware::load/) { - $self->analyze_cpu_subsystem(); - $self->check_cpu_subsystem(); - } elsif ($self->mode =~ /device::hardware::memory/) { - $self->analyze_mem_subsystem(); - $self->check_mem_subsystem(); - } elsif ($self->mode =~ /device::security/) { - $self->analyze_security_subsystem(); - $self->check_security_subsystem(); - } elsif ($self->mode =~ /device::(users|connections)::(count|check)/) { - $self->analyze_connection_subsystem(); - $self->check_connection_subsystem(); - } + if ($self->mode =~ /device::hardware::health/) { + $self->analyze_and_check_environmental_subsystem("Classes::SGOS::Component::EnvironmentalSubsystem"); + } elsif ($self->mode =~ /device::hardware::load/) { + $self->analyze_and_check_cpu_subsystem("Classes::SGOS::Component::CpuSubsystem"); + } elsif ($self->mode =~ /device::hardware::memory/) { + $self->analyze_and_check_mem_subsystem("Classes::SGOS::Component::MemSubsystem"); + } elsif ($self->mode =~ /device::security/) { + $self->analyze_and_check_security_subsystem("Classes::SGOS::Component::SecuritySubsystem"); + } elsif ($self->mode =~ /device::(users|connections)::(count|check)/) { + $self->analyze_and_check_connection_subsystem("Classes::SGOS::Component::ConnectionSubsystem"); + } else { + $self->no_such_mode(); } } -sub analyze_environmental_subsystem { - my $self = shift; - $self->{components}->{environmental_subsystem} = - Classes::SGOS::Component::EnvironmentalSubsystem->new(); -} - -sub analyze_cpu_subsystem { - my $self = shift; - $self->{components}->{cpu_subsystem} = - Classes::SGOS::Component::CpuSubsystem->new(); -} - -sub analyze_mem_subsystem { - my $self = shift; - $self->{components}->{mem_subsystem} = - Classes::SGOS::Component::MemSubsystem->new(); -} - -sub analyze_security_subsystem { - my $self = shift; - $self->{components}->{security_subsystem} = - Classes::SGOS::Component::SecuritySubsystem->new(); -} - -sub analyze_connection_subsystem { - my $self = shift; - $self->{components}->{connection_subsystem} = - Classes::SGOS::Component::ConnectionSubsystem->new(); -} - diff --git a/plugins-scripts/Classes/SGOS/Component/ConnectionSubsystem.pm b/plugins-scripts/Classes/SGOS/Component/ConnectionSubsystem.pm index f544a849..ecbd2dff 100644 --- a/plugins-scripts/Classes/SGOS/Component/ConnectionSubsystem.pm +++ b/plugins-scripts/Classes/SGOS/Component/ConnectionSubsystem.pm @@ -1,28 +1,18 @@ package Classes::SGOS::Component::ConnectionSubsystem; our @ISA = qw(Classes::SGOS); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - mems => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; foreach (qw(sgProxyHttpResponseTimeAll sgProxyHttpResponseFirstByte sgProxyHttpResponseByteRate sgProxyHttpResponseSize sgProxyHttpClientConnections sgProxyHttpClientConnectionsActive @@ -36,7 +26,6 @@ sub init { sub check { my $self = shift; - my $errorfound = 0; $self->add_info('checking connections'); if ($self->mode =~ /device::connections::check/) { my $info = sprintf 'average service time for http requests is %.5fs', diff --git a/plugins-scripts/Classes/SGOS/Component/CpuSubsystem.pm b/plugins-scripts/Classes/SGOS/Component/CpuSubsystem.pm index 83aded3e..dd0c81a7 100644 --- a/plugins-scripts/Classes/SGOS/Component/CpuSubsystem.pm +++ b/plugins-scripts/Classes/SGOS/Component/CpuSubsystem.pm @@ -1,26 +1,18 @@ package Classes::SGOS::Component::CpuSubsystem; our @ISA = qw(Classes::SGOS); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - cpus => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; # With SGOS version 5.5.4.1, 5.4.6.1 and 6.1.2.1, the SNMP MIB has been extended to support multiple CPU cores. # The new OID is defined as a table 1.3.6.1.4.1.3417.2.11.2.4.1 in the BLUECOAT-SG-PROXY-MIB file with the following sub-OIDs. # https://kb.bluecoat.com/index?page=content&id=FAQ1244&actp=search&viewlocale=en_US&searchid=1360452047002 @@ -41,7 +33,6 @@ sub init { sub check { my $self = shift; - my $errorfound = 0; $self->add_info('checking cpus'); $self->blacklist('ff', ''); if (scalar (@{$self->{cpus}}) == 0) { @@ -62,7 +53,6 @@ sub dump { package Classes::SGOS::Component::CpuSubsystem::Cpu; our @ISA = qw(Classes::SGOS::Component::CpuSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; @@ -124,7 +114,6 @@ sub dump { package Classes::SGOS::Component::CpuSubsystem::DevCpu; our @ISA = qw(Classes::SGOS::Component::CpuSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/SGOS/Component/DiskSubsystem.pm b/plugins-scripts/Classes/SGOS/Component/DiskSubsystem.pm index 734b58a8..cf35d1bf 100644 --- a/plugins-scripts/Classes/SGOS/Component/DiskSubsystem.pm +++ b/plugins-scripts/Classes/SGOS/Component/DiskSubsystem.pm @@ -1,21 +1,13 @@ package Classes::SGOS::Component::DiskSubsystem; our @ISA = qw(Classes::SGOS::Component::EnvironmentalSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - disks => [], - fss => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } @@ -62,7 +54,6 @@ sub dump { package Classes::SGOS::Component::DiskSubsystem::Disk; our @ISA = qw(Classes::SGOS::Component::DiskSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; @@ -112,7 +103,6 @@ sub dump { package Classes::SGOS::Component::DiskSubsystem::FS; our @ISA = qw(Classes::SGOS::Component::DiskSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/SGOS/Component/EnvironmentalSubsystem.pm b/plugins-scripts/Classes/SGOS/Component/EnvironmentalSubsystem.pm index a928732b..20fdddd8 100644 --- a/plugins-scripts/Classes/SGOS/Component/EnvironmentalSubsystem.pm +++ b/plugins-scripts/Classes/SGOS/Component/EnvironmentalSubsystem.pm @@ -1,41 +1,26 @@ package Classes::SGOS::Component::EnvironmentalSubsystem; our @ISA = qw(Classes::SGOS); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - method => $params{method}, - condition => $params{condition}, - status => $params{status}, - sensor_subsystem => undef, - disk_subsystem => undef, - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; $self->{sensor_subsystem} = - Classes::SGOS::Component::SensorSubsystem->new(%params); + Classes::SGOS::Component::SensorSubsystem->new(); $self->{disk_subsystem} = - Classes::SGOS::Component::DiskSubsystem->new(%params); + Classes::SGOS::Component::DiskSubsystem->new(); } sub check { my $self = shift; - my $errorfound = 0; $self->{sensor_subsystem}->check(); $self->{disk_subsystem}->check(); if (! $self->check_messages()) { diff --git a/plugins-scripts/Classes/SGOS/Component/MemSubsystem.pm b/plugins-scripts/Classes/SGOS/Component/MemSubsystem.pm index 02f631b3..8cdaaf85 100644 --- a/plugins-scripts/Classes/SGOS/Component/MemSubsystem.pm +++ b/plugins-scripts/Classes/SGOS/Component/MemSubsystem.pm @@ -1,22 +1,13 @@ package Classes::SGOS::Component::MemSubsystem; our @ISA = qw(Classes::SGOS); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - mems => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } @@ -28,10 +19,6 @@ sub init { # SGOSV4: memPressureValue - OIDs: 1.3.6.1.4.1.3417.2.8.2.3 (systemResourceMIB) # SGOSV5: sgProxyMemoryPressure - OIDs: 1.3.6.1.4.1.3417.2.11.2.3.4 (bluecoatSGProxyMIB) my $self = shift; - my %params = @_; - my $snmpwalk = $params{rawdata}; - my $ignore_redundancy = $params{ignore_redundancy}; - my $type = 0; foreach (qw(sgProxyMemPressure sgProxyMemAvailable sgProxyMemCacheUsage sgProxyMemSysUsage)) { $self->{$_} = $self->get_snmp_object('BLUECOAT-SG-PROXY-MIB', $_); @@ -40,7 +27,6 @@ sub init { sub check { my $self = shift; - my $errorfound = 0; $self->add_info('checking memory'); $self->blacklist('m', ''); my $info = sprintf 'memory usage is %.2f%%', diff --git a/plugins-scripts/Classes/SGOS/Component/SecuritySubsystem.pm b/plugins-scripts/Classes/SGOS/Component/SecuritySubsystem.pm index 7bb7eecc..910b02a9 100644 --- a/plugins-scripts/Classes/SGOS/Component/SecuritySubsystem.pm +++ b/plugins-scripts/Classes/SGOS/Component/SecuritySubsystem.pm @@ -1,26 +1,18 @@ package Classes::SGOS::Component::SecuritySubsystem; our @ISA = qw(Classes::SGOS); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - securitys => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; foreach ($self->get_snmp_table_objects( 'ATTACK-MIB', 'deviceAttackTable')) { push(@{$self->{securitys}}, @@ -55,7 +47,6 @@ sub dump { package Classes::SGOS::Component::SecuritySubsystem::Security; our @ISA = qw(Classes::SGOS::Component::SecuritySubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/SGOS/Component/SensorSubsystem.pm b/plugins-scripts/Classes/SGOS/Component/SensorSubsystem.pm index 95ba3320..809fd7df 100644 --- a/plugins-scripts/Classes/SGOS/Component/SensorSubsystem.pm +++ b/plugins-scripts/Classes/SGOS/Component/SensorSubsystem.pm @@ -1,27 +1,18 @@ package Classes::SGOS::Component::SensorSubsystem; our @ISA = qw(Classes::SGOS::Component::EnvironmentalSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - sensors => [], - sensorthresholds => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my $sensors = {}; foreach ($self->get_snmp_table_objects( 'SENSOR-MIB', 'deviceSensorValueTable')) { push(@{$self->{sensors}}, @@ -31,7 +22,6 @@ sub init { sub check { my $self = shift; - my $errorfound = 0; $self->add_info('checking sensors'); $self->blacklist('ses', ''); if (scalar (@{$self->{sensors}}) == 0) { @@ -52,7 +42,6 @@ sub dump { package Classes::SGOS::Component::SensorSubsystem::Sensor; our @ISA = qw(Classes::SGOS::Component::SensorSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/SecureOS.pm b/plugins-scripts/Classes/SecureOS.pm index 54610909..11c18d0f 100644 --- a/plugins-scripts/Classes/SecureOS.pm +++ b/plugins-scripts/Classes/SecureOS.pm @@ -1,55 +1,18 @@ package Classes::SecureOS; - -use strict; - -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - our @ISA = qw(Classes::Device); +use strict; sub init { my $self = shift; - my %params = @_; - $self->SUPER::init(%params); - $self->{components} = { - mem_subsystem => undef, - cpu_subsystem => undef, - }; - $self->{serial} = 'unknown'; - $self->{product} = 'unknown'; - $self->{romversion} = 'unknown'; - # serial is 1.3.6.1.2.1.47.1.1.1.1.11.1 - #$self->collect(); - if (! $self->check_messages()) { - if ($self->mode =~ /device::hardware::health/) { - $self->analyze_environmental_subsystem(); - $self->check_environmental_subsystem(); - } elsif ($self->mode =~ /device::hardware::load/) { - $self->analyze_cpu_subsystem(); - $self->check_cpu_subsystem(); - } elsif ($self->mode =~ /device::hardware::memory/) { - $self->analyze_mem_subsystem(); - $self->check_mem_subsystem(); - } + if ($self->mode =~ /device::hardware::health/) { + # not sure if this works fa25239716cb74c672f8dd390430dc4056caffa7 + $self->analyze_and_check_environmental_subsystem("Classes::FCMGMT::Component::EnvironmentalSubsystem"); + } elsif ($self->mode =~ /device::hardware::load/) { + $self->analyze_and_check_cpu_subsystem("Classes::UCDMIB::Component::CpuSubsystem"); + } elsif ($self->mode =~ /device::hardware::memory/) { + $self->analyze_and_check_mem_subsystem("Classes::UCDMIB::Component::MemSubsystem"); + } else { + $self->no_such_mode(); } } -sub analyze_environmental_subsystem { - my $self = shift; - $self->no_such_mode(); - $self->{components}->{environmental_subsystem} = - #Classes::SecureOS::Component::EnvironmentalSubsystem->new(); - Classes::FCMGMT::Component::EnvironmentalSubsystem->new(); -} - -sub analyze_cpu_subsystem { - my $self = shift; - $self->{components}->{cpu_subsystem} = - Classes::UCDMIB::Component::CpuSubsystem->new(); -} - -sub analyze_mem_subsystem { - my $self = shift; - $self->{components}->{mem_subsystem} = - Classes::UCDMIB::Component::MemSubsystem->new(); -} - diff --git a/plugins-scripts/Classes/UCDMIB.pm b/plugins-scripts/Classes/UCDMIB.pm index a0cc1a21..e2483ee2 100644 --- a/plugins-scripts/Classes/UCDMIB.pm +++ b/plugins-scripts/Classes/UCDMIB.pm @@ -1,8 +1,4 @@ package Classes::UCDMIB; - -use strict; - -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - our @ISA = qw(Classes::Device); +use strict; diff --git a/plugins-scripts/Classes/UCDMIB/Components/CpuSubsystem.pm b/plugins-scripts/Classes/UCDMIB/Components/CpuSubsystem.pm index 28e9d6d7..22c28d03 100644 --- a/plugins-scripts/Classes/UCDMIB/Components/CpuSubsystem.pm +++ b/plugins-scripts/Classes/UCDMIB/Components/CpuSubsystem.pm @@ -1,27 +1,18 @@ package Classes::UCDMIB::Component::CpuSubsystem; our @ISA = qw(Classes::UCDMIB); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - loads => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; - my $type = 0; foreach (qw(ssCpuUser ssCpuSystem ssCpuIdle ssCpuRawUser ssCpuRawSystem ssCpuRawIdle ssCpuRawNice)) { $self->{$_} = $self->get_snmp_object('UCD-SNMP-MIB', $_, 0); @@ -38,7 +29,6 @@ sub init { sub check { my $self = shift; - my $errorfound = 0; $self->add_info('checking cpus'); $self->blacklist('c', undef); my $info = sprintf 'cpu usage is %.2f%%', $self->{cpu_usage}; @@ -78,7 +68,6 @@ sub unix_init { sub unix_check { my $self = shift; - my $errorfound = 0; $self->add_info('checking loads'); $self->blacklist('c', ''); foreach (@{$self->{loads}}) { @@ -96,7 +85,6 @@ sub unix_dump { package Classes::UCDMIB::Component::CpuSubsystem::Load; our @ISA = qw(Classes::UCDMIB::Component::CpuSubsystem); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; diff --git a/plugins-scripts/Classes/UCDMIB/Components/MemSubsystem.pm b/plugins-scripts/Classes/UCDMIB/Components/MemSubsystem.pm index ab1b5f23..ceeefd84 100644 --- a/plugins-scripts/Classes/UCDMIB/Components/MemSubsystem.pm +++ b/plugins-scripts/Classes/UCDMIB/Components/MemSubsystem.pm @@ -1,31 +1,18 @@ package Classes::UCDMIB::Component::MemSubsystem; our @ISA = qw(Classes::UCDMIB); - use strict; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; sub new { my $class = shift; - my %params = @_; - my $self = { - runtime => $params{runtime}, - rawdata => $params{rawdata}, - mems => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; + my $self = {}; bless $self, $class; - $self->init(%params); + $self->init(); return $self; } sub init { my $self = shift; - my %params = @_; - my $snmpwalk = $params{rawdata}; - my $ignore_redundancy = $params{ignore_redundancy}; - my $type = 0; foreach (qw(memTotalSwap memAvailSwap memTotalReal memAvailReal memTotalFree)) { $self->{$_} = $self->get_snmp_object('UCD-SNMP-MIB', $_, 0); } @@ -37,7 +24,6 @@ sub init { sub check { my $self = shift; - my $errorfound = 0; $self->add_info('checking memory'); $self->blacklist('m', ''); if (defined $self->{mem_usage}) { diff --git a/plugins-scripts/GLPlugin.pm b/plugins-scripts/GLPlugin.pm new file mode 100755 index 00000000..cf8cf470 --- /dev/null +++ b/plugins-scripts/GLPlugin.pm @@ -0,0 +1,1894 @@ +package GLPlugin; + +use strict; +use IO::File; +use File::Basename; +use Digest::MD5 qw(md5_hex); +use Errno; +use AutoLoader; +our $AUTOLOAD; + +use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; + +{ + our $mode = undef; + our $plugin = undef; + our $blacklist = undef; + our $info = []; + our $extendedinfo = []; + our $summary = []; + our $statefilesdir = undef; +} + + +sub init { + my $self = shift; + $self->{method} = 'snmp'; + if ($self->opts->blacklist && + -f $self->opts->blacklist) { + $self->opts->blacklist = do { + local (@ARGV, $/) = $self->opts->blacklist; <> }; + } +} + +sub debug { + my $self = shift; + my $format = shift; + my $tracefile = "/tmp/".$0.".trace"; + $self->{trace} = -f $tracefile ? 1 : 0; + if ($self->opts->verbose && $self->opts->verbose > 10) { + printf("%s: ", scalar localtime); + printf($format, @_); + printf "\n"; + } + if ($self->{trace}) { + my $logfh = new IO::File; + $logfh->autoflush(1); + if ($logfh->open($tracefile, "a")) { + $logfh->printf("%s: ", scalar localtime); + $logfh->printf($format, @_); + $logfh->printf("\n"); + $logfh->close(); + } + } +} + +sub filter_name { + my $self = shift; + my $name = shift; + if ($self->opts->name) { + if ($self->opts->regexp) { + my $pattern = $self->opts->name; + if ($name =~ /$pattern/i) { + return 1; + } + } else { + if (lc $self->opts->name eq lc $name) { + return 1; + } + } + } else { + return 1; + } + return 0; +} + +sub blacklist { + my $self = shift; + my $type = shift; + my $name = shift; + $self->{blacklisted} = $self->is_blacklisted($type, $name); +} + +sub add_blacklist { + my $self = shift; + my $list = shift; + $GLPlugin::blacklist = join('/', + (split('/', $self->opts->blacklist), $list)); +} + +sub is_blacklisted { + my $self = shift; + my $type = shift; + my $name = shift; + my $blacklisted = 0; + foreach my $bl_items (split(/\//, $self->opts->blacklist)) { + if ($bl_items =~ /^(\w+):([\:\d\-,]+)$/) { + my $bl_type = $1; + my $bl_names = $2; + foreach my $bl_name (split(/,/, $bl_names)) { + if ($bl_type eq $type && $bl_name eq $name) { + $blacklisted = 1; + } + } + } elsif ($bl_items =~ /^(\w+)$/) { + my $bl_type = $1; + if ($bl_type eq $type) { + $blacklisted = 1; + } + } + } + return $blacklisted; +} + +sub mode { + my $self = shift; + return $GLPlugin::mode; +} + +sub add_message { + my $self = shift; + my $level = shift; + my $message = shift; + $GLPlugin::plugin->add_message($level, $message) + unless $self->{blacklisted}; + if (exists $self->{failed}) { + if ($level == UNKNOWN && $self->{failed} == OK) { + $self->{failed} = $level; + } elsif ($level > $self->{failed}) { + $self->{failed} = $level; + } + } +} + +sub status_code { + my $self = shift; + return $GLPlugin::plugin->status_code(@_); +} + +sub check_messages { + my $self = shift; + return $GLPlugin::plugin->check_messages(@_); +} + +sub clear_messages { + my $self = shift; + return $GLPlugin::plugin->clear_messages(@_); +} + +sub suppress_messages { + my $self = shift; + return $GLPlugin::plugin->suppress_messages(@_); +} + +sub add_perfdata { + my $self = shift; + $GLPlugin::plugin->add_perfdata(@_); +} + +sub set_thresholds { + my $self = shift; + $GLPlugin::plugin->set_thresholds(@_); +} + +sub force_thresholds { + my $self = shift; + $GLPlugin::plugin->force_thresholds(@_); +} + +sub check_thresholds { + my $self = shift; + my @params = @_; + ($self->{warning}, $self->{critical}) = + $GLPlugin::plugin->get_thresholds(@params); + return $GLPlugin::plugin->check_thresholds(@params); +} + +sub get_thresholds { + my $self = shift; + my @params = @_; + my @thresholds = $GLPlugin::plugin->get_thresholds(@params); + my($warning, $critical) = $GLPlugin::plugin->get_thresholds(@params); + $self->{warning} = $thresholds[0]; + $self->{critical} = $thresholds[1]; + return @thresholds; +} + +sub set_level { + my $self = shift; + my $code = shift; + $code = (qw(ok warning critical unknown))[$code] if $code =~ /^\d+$/; + $code = lc $code; + if (! exists $self->{tmp_level}) { + $self->{tmp_level} = { + ok => 0, + warning => 0, + critical => 0, + unknown => 0, + }; + } + $self->{tmp_level}->{$code}++; +} + +sub get_level { + my $self = shift; + return OK if ! exists $self->{tmp_level}; + my $code = OK; + $code ||= CRITICAL if $self->{tmp_level}->{critical}; + $code ||= WARNING if $self->{tmp_level}->{warning}; + $code ||= UNKNOWN if $self->{tmp_level}->{unknown}; + return $code; +} + +sub add_info { + my $self = shift; + my $info = shift; + $info = $self->{blacklisted} ? $info.' (blacklisted)' : $info; + $self->{info} = $info; + push(@{$GLPlugin::info}, $info); +} + +sub annotate_info { + my $self = shift; + my $annotation = shift; + my $lastinfo = pop(@{$GLPlugin::info}); + $lastinfo .= sprintf ' (%s)', $annotation; + push(@{$GLPlugin::info}, $lastinfo); +} + +sub add_extendedinfo { + my $self = shift; + my $info = shift; + $self->{extendedinfo} = $info; + return if ! $self->opts->extendedinfo; + push(@{$GLPlugin::extendedinfo}, $info); +} + +sub get_info { + my $self = shift; + my $separator = shift || ' '; + return join($separator , @{$GLPlugin::info}); +} + +sub get_extendedinfo { + my $self = shift; + my $separator = shift || ' '; + return join($separator, @{$GLPlugin::extendedinfo}); +} + +sub add_summary { + my $self = shift; + my $summary = shift; + push(@{$GLPlugin::summary}, $summary); +} + +sub get_summary { + my $self = shift; + return join(', ', @{$GLPlugin::summary}); +} + +sub opts { + my $self = shift; + return $GLPlugin::plugin->opts(); +} + +sub valdiff { + my $self = shift; + my $pparams = shift; + my %params = %{$pparams}; + my @keys = @_; + my $now = time; + my $newest_history_set = {}; + my $last_values = $self->load_state(%params) || eval { + my $empty_events = {}; + foreach (@keys) { + if (ref($self->{$_}) eq "ARRAY") { + $empty_events->{$_} = []; + } else { + $empty_events->{$_} = 0; + } + } + $empty_events->{timestamp} = 0; + if ($self->opts->lookback) { + $empty_events->{lookback_history} = {}; + } + $empty_events; + }; + foreach (@keys) { + if ($self->opts->lookback) { + # find a last_value in the history which fits lookback best + # and overwrite $last_values->{$_} with historic data + if (exists $last_values->{lookback_history}->{$_}) { + foreach my $date (sort {$a <=> $b} keys %{$last_values->{lookback_history}->{$_}}) { + $newest_history_set->{$_} = $last_values->{lookback_history}->{$_}->{$date}; + $newest_history_set->{timestamp} = $date; + } + foreach my $date (sort {$a <=> $b} keys %{$last_values->{lookback_history}->{$_}}) { + if ($date >= ($now - $self->opts->lookback)) { + $last_values->{$_} = $last_values->{lookback_history}->{$_}->{$date}; + $last_values->{timestamp} = $date; + last; + } else { + delete $last_values->{lookback_history}->{$_}->{$date}; + } + } + } + } + if ($self->{$_} =~ /^\d+$/) { + $last_values->{$_} = 0 if ! exists $last_values->{$_}; + if ($self->{$_} >= $last_values->{$_}) { + $self->{'delta_'.$_} = $self->{$_} - $last_values->{$_}; + } else { + # vermutlich db restart und zaehler alle auf null + $self->{'delta_'.$_} = $self->{$_}; + } + $self->debug(sprintf "delta_%s %f", $_, $self->{'delta_'.$_}); + } elsif (ref($self->{$_}) eq "ARRAY") { + if ((! exists $last_values->{$_} || ! defined $last_values->{$_}) && exists $params{lastarray}) { + # innerhalb der lookback-zeit wurde nichts in der lookback_history + # gefunden. allenfalls irgendwas aelteres. normalerweise + # wuerde jetzt das array als [] initialisiert. + # d.h. es wuerde ein delta geben, @found s.u. + # wenn man das nicht will, sondern einfach aktuelles array mit + # dem array des letzten laufs vergleichen will, setzt man lastarray + $last_values->{$_} = %{$newest_history_set} ? + $newest_history_set->{$_} : [] + } elsif ((! exists $last_values->{$_} || ! defined $last_values->{$_}) && ! exists $params{lastarray}) { + $last_values->{$_} = [] if ! exists $last_values->{$_}; + } elsif (exists $last_values->{$_} && ! defined $last_values->{$_}) { + # $_ kann es auch ausserhalb des lookback_history-keys als normalen + # key geben. der zeigt normalerweise auf den entspr. letzten + # lookback_history eintrag. wurde der wegen ueberalterung abgeschnitten + # ist der hier auch undef. + $last_values->{$_} = %{$newest_history_set} ? + $newest_history_set->{$_} : [] + } + my %saved = map { $_ => 1 } @{$last_values->{$_}}; + my %current = map { $_ => 1 } @{$self->{$_}}; + my @found = grep(!defined $saved{$_}, @{$self->{$_}}); + my @lost = grep(!defined $current{$_}, @{$last_values->{$_}}); + $self->{'delta_found_'.$_} = \@found; + $self->{'delta_lost_'.$_} = \@lost; + } + } + $self->{'delta_timestamp'} = $now - $last_values->{timestamp}; + $params{save} = eval { + my $empty_events = {}; + foreach (@keys) { + $empty_events->{$_} = $self->{$_}; + } + $empty_events->{timestamp} = $now; + if ($self->opts->lookback) { + $empty_events->{lookback_history} = $last_values->{lookback_history}; + foreach (@keys) { + $empty_events->{lookback_history}->{$_}->{$now} = $self->{$_}; + } + } + $empty_events; + }; + $self->save_state(%params); +} + +sub create_statefilesdir { + my $self = shift; + if (! -d $GLPlugin::statefilesdir) { + eval { + use File::Path; + mkpath $GLPlugin::statefilesdir; + }; + if ($@ || ! -w $GLPlugin::statefilesdir) { + $self->add_message(UNKNOWN, + sprintf "cannot create status dir %s! check your filesystem (permissions/usage/integrity) and disk devices", $GLPlugin::statefilesdir); + } + } elsif (! -w $GLPlugin::statefilesdir) { + $self->add_message(UNKNOWN, + sprintf "cannot write status dir %s! check your filesystem (permissions/usage/integrity) and disk devices", $GLPlugin::statefilesdir); + } +} + +sub create_statefile { + my $self = shift; + my %params = @_; + my $extension = ""; + $extension .= $params{name} ? '_'.$params{name} : ''; + if ($self->opts->community) { + $extension .= md5_hex($self->opts->community); + } + $extension =~ s/\//_/g; + $extension =~ s/\(/_/g; + $extension =~ s/\)/_/g; + $extension =~ s/\*/_/g; + $extension =~ s/\s/_/g; + if ($self->opts->snmpwalk && ! $self->opts->hostname) { + return sprintf "%s/%s_%s%s", $GLPlugin::statefilesdir, + 'snmpwalk.file'.md5_hex($self->opts->snmpwalk), + $self->opts->mode, lc $extension; + } elsif ($self->opts->snmpwalk && $self->opts->hostname eq "walkhost") { + return sprintf "%s/%s_%s%s", $GLPlugin::statefilesdir, + 'snmpwalk.file'.md5_hex($self->opts->snmpwalk), + $self->opts->mode, lc $extension; + } else { + return sprintf "%s/%s_%s%s", $GLPlugin::statefilesdir, + $self->opts->hostname, $self->opts->mode, lc $extension; + } +} + +sub schimpf { + my $self = shift; + printf "statefilesdir %s is not writable.\nYou didn't run this plugin as root, didn't you?\n", $GLPlugin::statefilesdir; +} + +sub save_state { + my $self = shift; + my %params = @_; + $self->create_statefilesdir(); + my $statefile = $self->create_statefile(%params); + if ((ref($params{save}) eq "HASH") && exists $params{save}->{timestamp}) { + $params{save}->{localtime} = scalar localtime $params{save}->{timestamp}; + } + my $seekfh = new IO::File; + if ($seekfh->open($statefile, "w")) { + $seekfh->printf("%s", Data::Dumper::Dumper($params{save})); + $seekfh->close(); + $self->debug(sprintf "saved %s to %s", + Data::Dumper::Dumper($params{save}), $statefile); + } else { + $self->add_message(UNKNOWN, + sprintf "cannot write status file %s! check your filesystem (permissions/usage/integrity) and disk devices", $statefile); + } +} + +sub load_state { + my $self = shift; + my %params = @_; + my $statefile = $self->create_statefile(%params); + if ( -f $statefile) { + our $VAR1; + eval { + require $statefile; + }; + if($@) { + printf "rumms\n"; + } + $self->debug(sprintf "load %s", Data::Dumper::Dumper($VAR1)); + return $VAR1; + } else { + return undef; + } +} + +sub dumper { + my $self = shift; + my $object = shift; + my $run = $object->{runtime}; + delete $object->{runtime}; + printf STDERR "%s\n", Data::Dumper::Dumper($object); + $object->{runtime} = $run; +} + +sub no_such_mode { + my $self = shift; + printf "Mode %s is not implemented for this type of device\n", + $self->opts->mode; + exit 3; +} + +sub check_pidfile { + my $self = shift; + my $fh = new IO::File; + if ($fh->open($self->{pidfile}, "r")) { + my $pid = $fh->getline(); + $fh->close(); + if (! $pid) { + $self->debug("Found pidfile %s with no valid pid. Exiting.", + $self->{pidfile}); + return 0; + } else { + $self->debug("Found pidfile %s with pid %d", $self->{pidfile}, $pid); + kill 0, $pid; + if ($! == Errno::ESRCH) { + $self->debug("This pidfile is stale. Writing a new one"); + $self->write_pidfile(); + return 1; + } else { + $self->debug("This pidfile is held by a running process. Exiting"); + return 0; + } + } + } else { + $self->debug("Found no pidfile. Writing a new one"); + $self->write_pidfile(); + return 1; + } +} + +sub write_pidfile { + my $self = shift; + if (! -d dirname($self->{pidfile})) { + eval "require File::Path;"; + if (defined(&File::Path::mkpath)) { + import File::Path; + eval { mkpath(dirname($self->{pidfile})); }; + } else { + my @dirs = (); + map { + push @dirs, $_; + mkdir(join('/', @dirs)) + if join('/', @dirs) && ! -d join('/', @dirs); + } split(/\//, dirname($self->{pidfile})); + } + } + my $fh = new IO::File; + $fh->autoflush(1); + if ($fh->open($self->{pidfile}, "w")) { + $fh->printf("%s", $$); + $fh->close(); + } else { + $self->debug("Could not write pidfile %s", $self->{pidfile}); + die "pid file could not be written"; + } +} + +sub accentfree { + my $self = shift; + my $text = shift; + # thanks mycoyne who posted this accent-remove-algorithm + # http://www.experts-exchange.com/Programming/Languages/Scripting/Perl/Q_23275533.html#a21234612 + my @transformed; + my %replace = ( + '9a' => 's', '9c' => 'oe', '9e' => 'z', '9f' => 'Y', 'c0' => 'A', 'c1' => 'A', + 'c2' => 'A', 'c3' => 'A', 'c4' => 'A', 'c5' => 'A', 'c6' => 'AE', 'c7' => 'C', + 'c8' => 'E', 'c9' => 'E', 'ca' => 'E', 'cb' => 'E', 'cc' => 'I', 'cd' => 'I', + 'ce' => 'I', 'cf' => 'I', 'd0' => 'D', 'd1' => 'N', 'd2' => 'O', 'd3' => 'O', + 'd4' => 'O', 'd5' => 'O', 'd6' => 'O', 'd8' => 'O', 'd9' => 'U', 'da' => 'U', + 'db' => 'U', 'dc' => 'U', 'dd' => 'Y', 'e0' => 'a', 'e1' => 'a', 'e2' => 'a', + 'e3' => 'a', 'e4' => 'a', 'e5' => 'a', 'e6' => 'ae', 'e7' => 'c', 'e8' => 'e', + 'e9' => 'e', 'ea' => 'e', 'eb' => 'e', 'ec' => 'i', 'ed' => 'i', 'ee' => 'i', + 'ef' => 'i', 'f0' => 'o', 'f1' => 'n', 'f2' => 'o', 'f3' => 'o', 'f4' => 'o', + 'f5' => 'o', 'f6' => 'o', 'f8' => 'o', 'f9' => 'u', 'fa' => 'u', 'fb' => 'u', + 'fc' => 'u', 'fd' => 'y', 'ff' => 'y', + ); + my @letters = split //, $text;; + for (my $i = 0; $i <= $#letters; $i++) { + my $hex = sprintf "%x", ord($letters[$i]); + $letters[$i] = $replace{$hex} if (exists $replace{$hex}); + } + push @transformed, @letters; + return join '', @transformed; +} + + +package GLPlugin::SNMP; +our @ISA = qw(GLPlugin); + +use strict; +use File::Basename; +use AutoLoader; +our $AUTOLOAD; + +use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; + +{ + our $mode = undef; + our $plugin = undef; + our $blacklist = undef; + our $session = undef; + our $rawdata = {}; + our $info = []; + our $extendedinfo = []; + our $summary = []; + our $statefilesdir = '/var/tmp/check_'.basename($0).'_health'; + our $oidtrace = []; + our $uptime = 0; +} + +sub init { + my $self = shift; + if ($self->mode =~ /device::walk/) { + my @trees = (); + my $name = $0; + $name =~ s/.*\///g; + $name = sprintf "/tmp/snmpwalk_%s_%s", $name, $self->opts->hostname; + if ($self->opts->oids) { + # create pid filename + # already running?;x + @trees = split(",", $self->opts->oids); + + } elsif ($self->can("trees")) { + @trees = $self->trees; + } + if ($self->opts->snmpdump) { + $name = $self->opts->snmpdump; + } + if (defined $self->opts->offline) { + $self->{pidfile} = $name.".pid"; + if (! $self->check_pidfile()) { + $self->trace("Exiting because another walk is already running"); + printf STDERR "Exiting because another walk is already running\n"; + exit 3; + } + $self->write_pidfile(); + my $timedout = 0; + my $snmpwalkpid = 0; + $SIG{'ALRM'} = sub { + $timedout = 1; + printf "UNKNOWN - %s timed out after %d seconds\n", + basename($0), + $self->opts->timeout; + kill 9, $snmpwalkpid; + }; + alarm($self->opts->timeout); + unlink $name.".partial"; + while (! $timedout && @trees) { + my $tree = shift @trees; + $SIG{CHLD} = 'IGNORE'; + my $cmd = sprintf "snmpwalk -ObentU -v%s -c %s %s %s >> %s", + $self->opts->protocol, + $self->opts->community, + $self->opts->hostname, + $tree, $name.".partial"; + $self->trace($cmd); + $snmpwalkpid = fork; + if (not $snmpwalkpid) { + exec($cmd); + } else { + wait(); + } + } + rename $name.".partial", $name if ! $timedout; + -f $self->{pidfile} && unlink $self->{pidfile}; + if ($timedout) { + printf "CRITICAL - timeout. There are still %d snmpwalks left\n", scalar(@trees); + exit 3; + } else { + printf "OK - all requested oids are in %s\n", $name; + } + } else { + printf "rm -f %s\n", $name; + foreach ($self->trees) { + printf "snmpwalk -ObentU -v%s -c %s %s %s >> %s\n", + $self->opts->protocol, + $self->opts->community, + $self->opts->hostname, + $_, $name; + } + } + exit 0; + } elsif ($self->mode =~ /device::uptime/) { + $self->{uptime} /= 60; + my $info = sprintf 'device is up since %s', + $self->human_timeticks($self->{uptime}); + $self->add_info($info); + $self->set_thresholds(warning => '15:', critical => '5:'); + $self->add_message($self->check_thresholds($self->{uptime}), $info); + $self->add_perfdata( + label => 'uptime', + value => $self->{uptime}, + warning => $self->{warning}, + critical => $self->{critical}, + ); + my ($code, $message) = $self->check_messages(join => ', ', join_all => ', '); + $GLPlugin::plugin->nagios_exit($code, $message); + } +} + +sub check_snmp_and_model { + my $self = shift; + $GLPlugin::SNMP::mibs_and_oids->{'MIB-II'} = { + sysDescr => '1.3.6.1.2.1.1.1', + sysObjectID => '1.3.6.1.2.1.1.2', + sysUpTime => '1.3.6.1.2.1.1.3', + sysName => '1.3.6.1.2.1.1.5', + }; + if ($self->opts->snmpwalk) { + my $response = {}; + if (! -f $self->opts->snmpwalk) { + $self->add_message(CRITICAL, + sprintf 'file %s not found', + $self->opts->snmpwalk); + } elsif (-x $self->opts->snmpwalk) { + my $cmd = sprintf "%s -ObentU -v%s -c%s %s 1.3.6.1.4.1 2>&1", + $self->opts->snmpwalk, + $self->opts->protocol, + $self->opts->community, + $self->opts->hostname; + open(WALK, "$cmd |"); + while () { + if (/^([\.\d]+) = .*?: (\-*\d+)/) { + $response->{$1} = $2; + } elsif (/^([\.\d]+) = .*?: "(.*?)"/) { + $response->{$1} = $2; + $response->{$1} =~ s/\s+$//; + } + } + close WALK; + } else { + if (defined $self->opts->offline) { + if ((time - (stat($self->opts->snmpwalk))[9]) > $self->opts->offline) { + $self->add_message(UNKNOWN, + sprintf 'snmpwalk file %s is too old', $self->opts->snmpwalk); + } + } + $self->opts->override_opt('hostname', 'walkhost'); + open(MESS, $self->opts->snmpwalk); + while() { + # SNMPv2-SMI::enterprises.232.6.2.6.7.1.3.1.4 = INTEGER: 6 + if (/^([\d\.]+) = .*?INTEGER: .*\((\-*\d+)\)/) { + # .1.3.6.1.2.1.2.2.1.8.1 = INTEGER: down(2) + $response->{$1} = $2; + } elsif (/^([\d\.]+) = .*?Opaque:.*?Float:.*?([\-\.\d]+)/) { + # .1.3.6.1.4.1.2021.10.1.6.1 = Opaque: Float: 0.938965 + $response->{$1} = $2; + } elsif (/^([\d\.]+) = STRING:\s*$/) { + $response->{$1} = ""; + } elsif (/^([\d\.]+) = Network Address: (.*)/) { + $response->{$1} = $2; + } elsif (/^([\d\.]+) = Hex-STRING: (.*)/) { + $response->{$1} = "0x".$2; + $response->{$1} =~ s/\s+$//; + } elsif (/^([\d\.]+) = \w+: (\-*\d+)/) { + $response->{$1} = $2; + } elsif (/^([\d\.]+) = \w+: "(.*?)"/) { + $response->{$1} = $2; + $response->{$1} =~ s/\s+$//; + } elsif (/^([\d\.]+) = \w+: (.*)/) { + $response->{$1} = $2; + $response->{$1} =~ s/\s+$//; + } elsif (/^([\d\.]+) = (\-*\d+)/) { + $response->{$1} = $2; + } elsif (/^([\d\.]+) = "(.*?)"/) { + $response->{$1} = $2; + $response->{$1} =~ s/\s+$//; + } + } + close MESS; + } + foreach my $oid (keys %$response) { + if ($oid =~ /^\./) { + my $nodot = $oid; + $nodot =~ s/^\.//g; + $response->{$nodot} = $response->{$oid}; + delete $response->{$oid}; + } + } + map { $response->{$_} =~ s/^\s+//; $response->{$_} =~ s/\s+$//; } + keys %$response; + $self->set_rawdata($response); + } else { + if (eval "require Net::SNMP") { + my %params = (); + my $net_snmp_version = Net::SNMP->VERSION(); # 5.002000 or 6.000000 + $params{'-translate'} = [ # because we see "NULL" coming from socomec devices + -all => 0x0 + ]; + $params{'-hostname'} = $self->opts->hostname; + $params{'-version'} = $self->opts->protocol; + if ($self->opts->port) { + $params{'-port'} = $self->opts->port; + } + if ($self->opts->domain) { + $params{'-domain'} = $self->opts->domain; + } + if ($self->opts->protocol eq '3') { + $params{'-username'} = $self->opts->username; + if ($self->opts->authpassword) { + $params{'-authpassword'} = $self->opts->authpassword; + } + if ($self->opts->authprotocol) { + $params{'-authprotocol'} = $self->opts->authprotocol; + } + if ($self->opts->privpassword) { + $params{'-privpassword'} = $self->opts->privpassword; + } + if ($self->opts->privprotocol) { + $params{'-privprotocol'} = $self->opts->privprotocol; + } + } else { + $params{'-community'} = $self->opts->community; + } + my ($session, $error) = Net::SNMP->session(%params); + if (! defined $session) { + $self->add_message(CRITICAL, + sprintf 'cannot create session object: %s', $error); + $self->debug(Data::Dumper::Dumper(\%params)); + } else { + my $max_msg_size = $session->max_msg_size(); + $session->max_msg_size(4 * $max_msg_size); + $GLPlugin::SNMP::session = $session; + } + } else { + $self->add_message(CRITICAL, + 'could not find Net::SNMP module'); + } + } + if (! $self->check_messages()) { + my $sysUptime = $self->get_snmp_object('MIB-II', 'sysUpTime', 0); + my $sysDescr = $self->get_snmp_object('MIB-II', 'sysDescr', 0); + if (defined $sysUptime && defined $sysDescr) { + $self->{uptime} = $self->timeticks($sysUptime); + $self->{productname} = $sysDescr; + $self->{sysobjectid} = $self->get_snmp_object('MIB-II', 'sysObjectID', 0); + $self->debug(sprintf 'uptime: %s', $self->{uptime}); + $self->debug(sprintf 'up since: %s', + scalar localtime (time - $self->{uptime})); + $GLPlugin::SNMP::uptime = $self->{uptime}; + $self->debug('whoami: '.$self->{productname}); + } else { + $self->add_message(CRITICAL, + 'could not contact snmp agent, got neither sysUptime nor sysDescr'); + $GLPlugin::SNMP::session->close if $GLPlugin::SNMP::session; + } + } +} + +sub discover_suitable_class { + my $self = shift; + my $sysobj = $self->get_snmp_object('MIB-II', 'sysObjectID', 0); + if ($sysobj && exists $GLPlugin::SNMP::discover_ids->{$sysobj}) { + return $GLPlugin::SNMP::discover_ids->{$sysobj}; + } +} +sub implements_mib { + my $self = shift; + my $mib = shift; + my $sysobj = $self->get_snmp_object('MIB-II', 'sysObjectID', 0); + $sysobj =~ s/^\.// if $sysobj; + if ($sysobj && $sysobj eq $GLPlugin::SNMP::mib_ids->{$mib}) { + return 1; + } +} + +sub timeticks { + my $self = shift; + my $timestr = shift; + if ($timestr =~ /\((\d+)\)/) { + # Timeticks: (20718727) 2 days, 9:33:07.27 + $timestr = $1 / 100; + } elsif ($timestr =~ /(\d+)\s*days.*?(\d+):(\d+):(\d+)\.(\d+)/) { + # Timeticks: 2 days, 9:33:07.27 + $timestr = $1 * 24 * 3600 + $2 * 3600 + $3 * 60 + $4; + } elsif ($timestr =~ /(\d+):(\d+):(\d+)\.(\d+)/) { + # Timeticks: 9:33:07.27 + $timestr = $1 * 3600 + $2 * 60 + $3; + } elsif ($timestr =~ /(\d+)\s*hour[s]*.*?(\d+):(\d+)\.(\d+)/) { + # Timeticks: 3 hours, 42:17.98 + $timestr = $1 * 3600 + $2 * 60 + $3; + } elsif ($timestr =~ /(\d+)\s*minute[s]*.*?(\d+)\.(\d+)/) { + # Timeticks: 36 minutes, 01.96 + $timestr = $1 * 60 + $2; + } elsif ($timestr =~ /(\d+)\.\d+\s*second[s]/) { + # Timeticks: 01.02 seconds + $timestr = $1; + } + return $timestr; +} + +sub human_timeticks { + my $self = shift; + my $timeticks = shift; + my $days = int($timeticks / 86400); + $timeticks -= ($days * 86400); + my $hours = int($timeticks / 3600); + $timeticks -= ($hours * 3600); + my $minutes = int($timeticks / 60); + my $seconds = $timeticks % 60; + $days = $days < 1 ? '' : $days .'d '; + return $days . sprintf "%dh %dm %ds", $hours, $minutes, $seconds; +} + +sub get_snmp_object { + my $self = shift; + my $mib = shift; + my $mo = shift; + my $index = shift; + if (exists $GLPlugin::SNMP::mibs_and_oids->{$mib} && + exists $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$mo}) { + my $oid = $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$mo}. + (defined $index ? '.'.$index : ''); + my $response = $self->get_request(-varbindlist => [$oid]); + if (defined $response->{$oid}) { + if ($response->{$oid} eq 'noSuchInstance') { + return undef; + } + if (my @symbols = $self->make_symbolic($mib, $response, [[$index]])) { + $response->{$oid} = $symbols[0]->{$mo}; + } + } + $self->debug(sprintf "GET: %s::%s (%s) : %s", $mib, $mo, $oid, defined $response->{$oid} ? $response->{$oid} : ""); + return $response->{$oid}; + } + return undef; +} + +sub get_snmp_objects { + my $self = shift; + my $mib = shift; + my @mos = @_; + foreach (@mos) { + my $value = $self->get_snmp_object($mib, $_, 0); + if (defined $value) { + $self->{$_} = $value; + } else { + my $value = $self->get_snmp_object($mib, $_); + if (defined $value) { + $self->{$_} = $value; + } + } + } +} + +sub get_single_request_iq { + my $self = shift; + my %params = @_; + my @oids = (); + my $result = $self->get_request_iq(%params); + foreach (keys %{$result}) { + return $result->{$_}; + } + return undef; +} + +sub get_request_iq { + my $self = shift; + my %params = @_; + my @oids = (); + my $mib = $params{'-mib'}; + foreach my $oid (@{$params{'-molist'}}) { + if (exists $GLPlugin::SNMP::mibs_and_oids->{$mib} && + exists $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$oid}) { + push(@oids, (exists $params{'-index'}) ? + $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$oid}.'.'.$params{'-index'} : + $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$oid}); + } + } + return $self->get_request( + -varbindlist => \@oids); +} + +sub valid_response { + my $self = shift; + my $mib = shift; + my $oid = shift; + my $index = shift; + if (exists $GLPlugin::SNMP::mibs_and_oids->{$mib} && + exists $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$oid}) { + # make it numerical + my $oid = $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$oid}; + if (defined $index) { + $oid .= '.'.$index; + } + my $result = $self->get_request( + -varbindlist => [$oid] + ); + if (!defined($result) || + ! defined $result->{$oid} || + $result->{$oid} eq 'noSuchInstance' || + $result->{$oid} eq 'noSuchObject' || + $result->{$oid} eq 'endOfMibView') { + return undef; + } else { + $self->add_rawdata($oid, $result->{$oid}); + return $result->{$oid}; + } + } else { + return undef; + } +} + +sub uptime { + my $self = shift; + return $GLPlugin::SNMP::uptime; +} + +sub set_rawdata { + my $self = shift; + $GLPlugin::SNMP::rawdata = shift; +} + +sub add_rawdata { + my $self = shift; + my $oid = shift; + my $value = shift; + $GLPlugin::SNMP::rawdata->{$oid} = $value; +} + +sub rawdata { + my $self = shift; + return $GLPlugin::SNMP::rawdata; +} + +sub add_oidtrace { + my $self = shift; + my $oid = shift; + $self->debug("cache: ".$oid); + push(@{$GLPlugin::SNMP::oidtrace}, $oid); +} + +sub get_snmp_table_attributes { + my $self = shift; + my $mib = shift; + my $table = shift; + my $indices = shift || []; + my @entries = (); + my $augmenting_table; + if ($table =~ /^(.*?)\+(.*)/) { + $table = $1; + $augmenting_table = $2; + } + my $entry = $table; + $entry =~ s/Table/Entry/g; + if (exists $GLPlugin::SNMP::mibs_and_oids->{$mib} && + exists $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$table}) { + my $toid = $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$table}.'.'; + my $toidlen = length($toid); + my @columns = grep { + substr($GLPlugin::SNMP::mibs_and_oids->{$mib}->{$_}, 0, $toidlen) eq + $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$table}.'.' + } keys %{$GLPlugin::SNMP::mibs_and_oids->{$mib}}; + if ($augmenting_table && + exists $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$augmenting_table}) { + my $toid = $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$augmenting_table}.'.'; + my $toidlen = length($toid); + push(@columns, grep { + substr($GLPlugin::SNMP::mibs_and_oids->{$mib}->{$_}, 0, $toidlen) eq + $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$augmenting_table}.'.' + } keys %{$GLPlugin::SNMP::mibs_and_oids->{$mib}}); + } + return @columns; + } else { + return (); + } +} + +sub get_request { + my $self = shift; + my %params = @_; + my @notcached = (); + foreach my $oid (@{$params{'-varbindlist'}}) { + $self->add_oidtrace($oid); + if (! exists $GLPlugin::SNMP::rawdata->{$oid}) { + push(@notcached, $oid); + } + } + if (! $self->opts->snmpwalk && (scalar(@notcached) > 0)) { + my $result = ($GLPlugin::SNMP::session->version() == 0) ? + $GLPlugin::SNMP::session->get_request( + -varbindlist => \@notcached, + ) + : + $GLPlugin::SNMP::session->get_request( # get_bulk_request liefert next + #-nonrepeaters => scalar(@notcached), + -varbindlist => \@notcached, + ); + foreach my $key (%{$result}) { + $self->add_rawdata($key, $result->{$key}); + } + } + my $result = {}; + map { $result->{$_} = $GLPlugin::SNMP::rawdata->{$_} } + @{$params{'-varbindlist'}}; + return $result; +} + +# Level1 +# get_snmp_table_objects('MIB-Name', 'Table-Name', 'Table-Entry', [indices]) +# +# returns array of hashrefs +# evt noch ein weiterer parameter fuer ausgewaehlte oids +# +sub get_snmp_table_objects_with_cache { + my $self = shift; + my $mib = shift; + my $table = shift; + my $key_attr = shift; + #return $self->get_snmp_table_objects($mib, $table); + $self->update_entry_cache(0, $mib, $table, $key_attr); + my @indices = $self->get_cache_indices($mib, $table, $key_attr); + my @entries = (); + foreach ($self->get_snmp_table_objects($mib, $table, \@indices)) { + push(@entries, $_); + } + return @entries; +} + +sub get_snmp_table_objects { + my $self = shift; + my $mib = shift; + my $table = shift; + my $indices = shift || []; + my @entries = (); + my $augmenting_table; + $self->debug(sprintf "get_snmp_table_objects %s %s", $mib, $table); + if ($table =~ /^(.*?)\+(.*)/) { + $table = $1; + $augmenting_table = $2; + } + my $entry = $table; + $entry =~ s/Table/Entry/g; + if (scalar(@{$indices}) == 1) { + if (exists $GLPlugin::SNMP::mibs_and_oids->{$mib} && + exists $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$table}) { + my $eoid = $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$entry}.'.'; + my $eoidlen = length($eoid); + my @columns = map { + $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$_} + } grep { + substr($GLPlugin::SNMP::mibs_and_oids->{$mib}->{$_}, 0, $eoidlen) eq + $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$entry}.'.' + } keys %{$GLPlugin::SNMP::mibs_and_oids->{$mib}}; + my $index = join('.', @{$indices->[0]}); + if ($augmenting_table && + exists $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$augmenting_table}) { + my $augmenting_entry = $augmenting_table; + $augmenting_entry =~ s/Table/Entry/g; + my $eoid = $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$augmenting_entry}.'.'; + my $eoidlen = length($eoid); + push(@columns, map { + $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$_} + } grep { + substr($GLPlugin::SNMP::mibs_and_oids->{$mib}->{$_}, 0, $eoidlen) eq + $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$augmenting_table}.'.' + } keys %{$GLPlugin::SNMP::mibs_and_oids->{$mib}}); + } + my $result = $self->get_entries( + -startindex => $index, + -endindex => $index, + -columns => \@columns, + ); + @entries = $self->make_symbolic($mib, $result, $indices); + @entries = map { $_->{indices} = shift @{$indices}; $_ } @entries; + } + } elsif (scalar(@{$indices}) > 1) { + # man koennte hier pruefen, ob die indices aufeinanderfolgen + # und dann get_entries statt get_table aufrufen + if (exists $GLPlugin::SNMP::mibs_and_oids->{$mib} && + exists $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$table}) { + my $result = {}; + my $eoid = $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$entry}.'.'; + my $eoidlen = length($eoid); + my @columns = map { + $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$_} + } grep { + substr($GLPlugin::SNMP::mibs_and_oids->{$mib}->{$_}, 0, $eoidlen) eq + $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$entry}.'.' + } keys %{$GLPlugin::SNMP::mibs_and_oids->{$mib}}; + my @sortedindices = map { $_->[0] } + sort { $a->[1] cmp $b->[1] } + map { [$_, + join '', map { sprintf("%30d",$_) } split( /\./, $_) + ] } map { join('.', @{$_})} @{$indices}; + my $startindex = $sortedindices[0]; + my $endindex = $sortedindices[$#sortedindices]; + if (0) { + # holzweg. dicke ciscos liefern unvollstaendiges resultat, d.h. + # bei 138,19,157 kommt nur 138..144, dann ist schluss. + # maxrepetitions bringt nichts. + $result = $self->get_entries( + -startindex => $startindex, + -endindex => $endindex, + -columns => \@columns, + ); + if (! $result) { + $result = $self->get_entries( + -startindex => $startindex, + -endindex => $endindex, + -columns => \@columns, + -maxrepetitions => 0, + ); + } + } else { + foreach my $ifidx (@sortedindices) { + my $ifresult = $self->get_entries( + -startindex => $ifidx, + -endindex => $ifidx, + -columns => \@columns, + ); + map { $result->{$_} = $ifresult->{$_} } + keys %{$ifresult}; + } + } + if ($augmenting_table && + exists $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$augmenting_table}) { + my $entry = $augmenting_table; + $entry =~ s/Table/Entry/g; + my $eoid = $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$entry}.'.'; + my $eoidlen = length($eoid); + my @columns = map { + $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$_} + } grep { + substr($GLPlugin::SNMP::mibs_and_oids->{$mib}->{$_}, 0, $eoidlen) eq + $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$entry}.'.' + } keys %{$GLPlugin::SNMP::mibs_and_oids->{$mib}}; + foreach my $ifidx (@sortedindices) { + my $ifresult = $self->get_entries( + -startindex => $ifidx, + -endindex => $ifidx, + -columns => \@columns, + ); + map { $result->{$_} = $ifresult->{$_} } + keys %{$ifresult}; + } + } + # now we have numerical_oid+index => value + # needs to become symboic_oid => value + #my @indices = + # $self->get_indices($GLPlugin::SNMP::mibs_and_oids->{$mib}->{$entry}); + @entries = $self->make_symbolic($mib, $result, $indices); + @entries = map { $_->{indices} = shift @{$indices}; $_ } @entries; + } + } else { + if (exists $GLPlugin::SNMP::mibs_and_oids->{$mib} && + exists $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$table}) { + $self->debug(sprintf "get_snmp_table_objects calls get_table %s", + $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$table}); + my $result = $self->get_table( + -baseoid => $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$table}); + $self->debug(sprintf "get_snmp_table_objects get_table returns %d oids", + scalar(keys %{$result})); + # now we have numerical_oid+index => value + # needs to become symboic_oid => value + my @indices = + $self->get_indices( + -baseoid => $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$entry}, + -oids => [keys %{$result}]); + $self->debug(sprintf "get_snmp_table_objects get_table returns %d indices", + scalar(@indices)); + @entries = $self->make_symbolic($mib, $result, \@indices); + @entries = map { $_->{indices} = shift @indices; $_ } @entries; + } + } + @entries = map { $_->{flat_indices} = join(".", @{$_->{indices}}); $_ } @entries; + return @entries; +} + +sub get_snmp_tables { + my $self = shift; + my $mib = shift; + my $infos = shift; + foreach my $info (@{$infos}) { + $self->{$info->[0]} = [] if ! exists $self->{$info->[0]}; + foreach ($self->get_snmp_table_objects($mib, $info->[1])) { + my $class = $info->[2]; + push(@{$self->{$info->[0]}}, $class->new(%{$_})); + } + } +} + +# make_symbolic +# mib is the name of a mib (must be in mibs_and_oids) +# result is a hash-key oid->value +# indices is a array ref of array refs. [[1],[2],...] or [[1,0],[1,1],[2,0].. +sub make_symbolic { + my $self = shift; + my $mib = shift; + my $result = shift; + my $indices = shift; + my @entries = (); + foreach my $index (@{$indices}) { + # skip [], [[]], [[undef]] + if (ref($index) eq "ARRAY") { + if (scalar(@{$index}) == 0) { + next; + } elsif (!defined $index->[0]) { + next; + } + } + my $mo = {}; + my $idx = join('.', @{$index}); # index can be multi-level + foreach my $symoid + (keys %{$GLPlugin::SNMP::mibs_and_oids->{$mib}}) { + my $oid = $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$symoid}; + if (ref($oid) ne 'HASH') { + my $fulloid = $oid . '.'.$idx; + if (exists $result->{$fulloid}) { + if (exists $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$symoid.'Definition'}) { + if (ref($GLPlugin::SNMP::mibs_and_oids->{$mib}->{$symoid.'Definition'}) eq 'HASH') { + if (exists $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$symoid.'Definition'}->{$result->{$fulloid}}) { + $mo->{$symoid} = $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$symoid.'Definition'}->{$result->{$fulloid}}; + } else { + $mo->{$symoid} = 'unknown_'.$result->{$fulloid}; + } + } elsif ($GLPlugin::SNMP::mibs_and_oids->{$mib}->{$symoid.'Definition'} =~ /^(.*?)::(.*)/) { + my $mib = $1; + my $definition = $2; + if (exists $GLPlugin::SNMP::definitions->{$mib} && exists $GLPlugin::SNMP::definitions->{$mib}->{$definition} + && exists $GLPlugin::SNMP::definitions->{$mib}->{$definition}->{$result->{$fulloid}}) { + $mo->{$symoid} = $GLPlugin::SNMP::definitions->{$mib}->{$definition}->{$result->{$fulloid}}; + } else { + $mo->{$symoid} = 'unknown_'.$result->{$fulloid}; + } + } else { + $mo->{$symoid} = 'unknown_'.$result->{$fulloid}; + # oder $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$symoid.'Definition'}? + } + } else { + $mo->{$symoid} = $result->{$fulloid}; + } + } + } + } + push(@entries, $mo); + } + if (@{$indices} and scalar(@{$indices}) == 1 and !defined $indices->[0]->[0]) { + my $mo = {}; + foreach my $symoid + (keys %{$GLPlugin::SNMP::mibs_and_oids->{$mib}}) { + my $oid = $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$symoid}; + if (ref($oid) ne 'HASH') { + if (exists $result->{$oid}) { + if (exists $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$symoid.'Definition'}) { + if (ref($GLPlugin::SNMP::mibs_and_oids->{$mib}->{$symoid.'Definition'}) eq 'HASH') { + if (exists $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$symoid.'Definition'}->{$result->{$oid}}) { + $mo->{$symoid} = $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$symoid.'Definition'}->{$result->{$oid}}; + push(@entries, $mo); + } + } elsif ($GLPlugin::SNMP::mibs_and_oids->{$mib}->{$symoid.'Definition'} =~ /^(.*?)::(.*)/) { + my $mib = $1; + my $definition = $2; + if (exists $GLPlugin::SNMP::definitions->{$mib} && exists $GLPlugin::SNMP::definitions->{$mib}->{$definition} + && exists $GLPlugin::SNMP::definitions->{$mib}->{$definition}->{$result->{$oid}}) { + $mo->{$symoid} = $GLPlugin::SNMP::definitions->{$mib}->{$definition}->{$result->{$oid}}; + } else { + $mo->{$symoid} = 'unknown_'.$result->{$oid}; + } + } else { + $mo->{$symoid} = 'unknown_'.$result->{$oid}; + # oder $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$symoid.'Definition'}? + } + } + } + } + } + push(@entries, $mo) if keys %{$mo}; + } + return @entries; +} + +# Level2 +# - get_table from Net::SNMP +# - get all baseoid-matching oids from rawdata +sub get_table { + my $self = shift; + my %params = @_; + $self->add_oidtrace($params{'-baseoid'}); + if (! $self->opts->snmpwalk) { + my @notcached = (); + $self->debug(sprintf "get_table %s", Data::Dumper::Dumper(\%params)); + my $result = $GLPlugin::SNMP::session->get_table(%params); + $self->debug(sprintf "get_table returned %d oids", scalar(keys %{$result})); + if (scalar(keys %{$result}) == 0) { + $self->debug(sprintf "get_table error: %s", + $GLPlugin::SNMP::session->error()); + $self->debug("get_table error: try fallback"); + $params{'-maxrepetitions'} = 1; + $self->debug(sprintf "get_table %s", Data::Dumper::Dumper(\%params)); + $result = $GLPlugin::SNMP::session->get_table(%params); + $self->debug(sprintf "get_table returned %d oids", scalar(keys %{$result})); + if (scalar(keys %{$result}) == 0) { + $self->debug(sprintf "get_table error: %s", + $GLPlugin::SNMP::session->error()); + $self->debug("get_table error: no more fallbacks. Try --protocol 1"); + } + } + foreach my $key (keys %{$result}) { + $self->add_rawdata($key, $result->{$key}); + } + } + return $self->get_matching_oids( + -columns => [$params{'-baseoid'}]); +} + +sub get_entries { + my $self = shift; + my %params = @_; + # [-startindex] + # [-endindex] + # -columns + my $result = {}; + $self->debug(sprintf "get_entries %s", Data::Dumper::Dumper(\%params)); + if (! $self->opts->snmpwalk) { + my %newparams = (); + $newparams{'-startindex'} = $params{'-startindex'} + if defined $params{'-startindex'}; + $newparams{'-endindex'} = $params{'-endindex'} + if defined $params{'-endindex'}; + $newparams{'-columns'} = $params{'-columns'}; + $result = $GLPlugin::SNMP::session->get_entries(%newparams); + if (! $result) { + $newparams{'-maxrepetitions'} = 0; + $result = $GLPlugin::SNMP::session->get_entries(%newparams); + if (! $result) { + $self->debug(sprintf "get_entries tries last fallback"); + delete $newparams{'-endindex'}; + delete $newparams{'-startindex'}; + delete $newparams{'-maxrepetitions'}; + $result = $GLPlugin::SNMP::session->get_entries(%newparams); + } + } + foreach my $key (keys %{$result}) { + $self->add_rawdata($key, $result->{$key}); + } + } else { + my $preresult = $self->get_matching_oids( + -columns => $params{'-columns'}); + foreach (keys %{$preresult}) { + $result->{$_} = $preresult->{$_}; + } + my @sortedkeys = map { $_->[0] } + sort { $a->[1] cmp $b->[1] } + map { [$_, + join '', map { sprintf("%30d",$_) } split( /\./, $_) + ] } keys %{$result}; + my @to_del = (); + if ($params{'-startindex'}) { + foreach my $resoid (@sortedkeys) { + foreach my $oid (@{$params{'-columns'}}) { + my $poid = $oid.'.'; + my $lpoid = length($poid); + if (substr($resoid, 0, $lpoid) eq $poid) { + my $oidpattern = $poid; + $oidpattern =~ s/\./\\./g; + if ($resoid =~ /^$oidpattern(.+)$/) { + if ($1 lt $params{'-startindex'}) { + push(@to_del, $oid.'.'.$1); + } + } + } + } + } + } + if ($params{'-endindex'}) { + foreach my $resoid (@sortedkeys) { + foreach my $oid (@{$params{'-columns'}}) { + my $poid = $oid.'.'; + my $lpoid = length($poid); + if (substr($resoid, 0, $lpoid) eq $poid) { + my $oidpattern = $poid; + $oidpattern =~ s/\./\\./g; + if ($resoid =~ /^$oidpattern(.+)$/) { + if ($1 gt $params{'-endindex'}) { + push(@to_del, $oid.'.'.$1); + } + } + } + } + } + } + foreach (@to_del) { + delete $result->{$_}; + } + } + return $result; +} + +# Level2 +# helper function +sub get_matching_oids { + my $self = shift; + my %params = @_; + my $result = {}; + $self->debug(sprintf "get_matching_oids %s", Data::Dumper::Dumper(\%params)); + foreach my $oid (@{$params{'-columns'}}) { + my $oidpattern = $oid; + $oidpattern =~ s/\./\\./g; + map { $result->{$_} = $GLPlugin::SNMP::rawdata->{$_} } + grep /^$oidpattern(?=\.|$)/, keys %{$GLPlugin::SNMP::rawdata}; + } + $self->debug(sprintf "get_matching_oids returns %d from %d oids", + scalar(keys %{$result}), scalar(keys %{$GLPlugin::SNMP::rawdata})); + return $result; +} + +sub create_interface_cache_file { + my $self = shift; + my $extension = ""; + if ($self->opts->snmpwalk && ! $self->opts->hostname) { + $self->opts->override_opt('hostname', + 'snmpwalk.file'.md5_hex($self->opts->snmpwalk)) + } + if ($self->opts->community) { + $extension .= md5_hex($self->opts->community); + } + $extension =~ s/\//_/g; + $extension =~ s/\(/_/g; + $extension =~ s/\)/_/g; + $extension =~ s/\*/_/g; + $extension =~ s/\s/_/g; + return sprintf "%s/%s_interface_cache_%s", $GLPlugin::statefilesdir, + $self->opts->hostname, lc $extension; +} + +sub no_such_model { + my $self = shift; + printf "Model %s is not implemented\n", $self->{productname}; + exit 3; +} + +# get_cached_table_entries +# get_table nur die table-basoid +# mit liste von indices +# get_entries -startindex x -endindex x konsekutive indices oder einzeln + +sub get_table_entries { + my $self = shift; + my $mib = shift; + my $table = shift; + my $elements = shift; + my $oids = {}; + my $entry; + if (exists $GLPlugin::SNMP::mibs_and_oids->{$mib} && + exists $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$table}) { + foreach my $key (keys %{$GLPlugin::SNMP::mibs_and_oids->{$mib}}) { + if ($GLPlugin::SNMP::mibs_and_oids->{$mib}->{$key} =~ + /^$GLPlugin::SNMP::mibs_and_oids->{$mib}->{$table}/) { + $oids->{$key} = $GLPlugin::SNMP::mibs_and_oids->{$mib}->{$key}; + } + } + } + ($entry = $table) =~ s/Table/Entry/g; + return $self->get_entries($oids, $entry); +} + + +sub xget_entries { + my $self = shift; + my $oids = shift; + my $entry = shift; + my $fallback = shift; + my @params = (); + my @indices = $self->get_indices($oids->{$entry}); + foreach (@indices) { + my @idx = @{$_}; + my %params = (); + my $maxdimension = scalar(@idx) - 1; + foreach my $idxnr (1..scalar(@idx)) { + $params{'index'.$idxnr} = $_->[$idxnr - 1]; + } + foreach my $oid (keys %{$oids}) { + next if $oid =~ /Table$/; + next if $oid =~ /Entry$/; + # there may be scalar oids ciscoEnvMonTemperatureStatusValue = curr. temp. + next if ($oid =~ /Value$/ && ref ($oids->{$oid}) eq 'HASH'); + if (exists $oids->{$oid.'Value'}) { + $params{$oid} = $self->get_object_value( + $oids->{$oid}, $oids->{$oid.'Value'}, @idx); + } else { + $params{$oid} = $self->get_object($oids->{$oid}, @idx); + } + } + push(@params, \%params); + } + if (! $fallback && scalar(@params) == 0) { + if ($GLPlugin::SNMP::session) { + my $table = $entry; + $table =~ s/(.*)\.\d+$/$1/; + my $result = $self->get_table( + -baseoid => $oids->{$table} + ); + if ($result) { + foreach my $key (keys %{$result}) { + $self->add_rawdata($key, $result->{$key}); + } + @params = $self->get_entries($oids, $entry, 1); + } + #printf "%s\n", Data::Dumper::Dumper($result); + } + } + return @params; +} + +sub get_indices { + my $self = shift; + my %params = @_; + # -baseoid : entry + # find all oids beginning with $entry + # then skip one field for the sequence + # then read the next numindices fields + my $entrypat = $params{'-baseoid'}; + $entrypat =~ s/\./\\\./g; + my @indices = map { + /^$entrypat\.\d+\.(.*)/ && $1; + } grep { + /^$entrypat/ + } keys %{$GLPlugin::SNMP::rawdata}; + my %seen = (); + my @o = map {[split /\./]} sort grep !$seen{$_}++, @indices; + return @o; +} + +sub get_size { + my $self = shift; + my $entry = shift; + my $entrypat = $entry; + $entrypat =~ s/\./\\\./g; + my @entries = grep { + /^$entrypat/ + } keys %{$GLPlugin::SNMP::rawdata}; + return scalar(@entries); +} + +sub get_object { + my $self = shift; + my $object = shift; + my @indices = @_; + #my $oid = $object.'.'.join('.', @indices); + my $oid = $object; + $oid .= '.'.join('.', @indices) if (@indices); + return $GLPlugin::SNMP::rawdata->{$oid}; +} + +sub get_object_value { + my $self = shift; + my $object = shift; + my $values = shift; + my @indices = @_; + my $key = $self->get_object($object, @indices); + if (defined $key) { + return $values->{$key}; + } else { + return undef; + } +} + +#SNMP::Utils::counter([$idxs1, $idxs2], $idx1, $idx2), +# this flattens a n-dimensional array and returns the absolute position +# of the element at position idx1,idx2,...,idxn +# element 1,2 in table 0,0 0,1 0,2 1,0 1,1 1,2 2,0 2,1 2,2 is at pos 6 +sub get_number { + my $self = shift; + my $indexlists = shift; #, zeiger auf array aus [1, 2] + my @element = @_; + my $dimensions = scalar(@{$indexlists->[0]}); + my @sorted = (); + my $number = 0; + if ($dimensions == 1) { + @sorted = + sort { $a->[0] <=> $b->[0] } @{$indexlists}; + } elsif ($dimensions == 2) { + @sorted = + sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] } @{$indexlists}; + } elsif ($dimensions == 3) { + @sorted = + sort { $a->[0] <=> $b->[0] || + $a->[1] <=> $b->[1] || + $a->[2] <=> $b->[2] } @{$indexlists}; + } + foreach (@sorted) { + if ($dimensions == 1) { + if ($_->[0] == $element[0]) { + last; + } + } elsif ($dimensions == 2) { + if ($_->[0] == $element[0] && $_->[1] == $element[1]) { + last; + } + } elsif ($dimensions == 3) { + if ($_->[0] == $element[0] && + $_->[1] == $element[1] && + $_->[2] == $element[2]) { + last; + } + } + $number++; + } + return ++$number; +} + +sub update_entry_cache { + my $self = shift; + my $force = shift; + my $mib = shift; + my $table = shift; + my $key_attr = shift; + if (ref($key_attr) ne "ARRAY") { + $key_attr = [$key_attr]; + } + my $cache = sprintf "%s_%s_%s_cache", + $mib, $table, join('#', @{$key_attr}); + my $statefile = lc sprintf "%s/%s_%s_%s-%s_%s_cache", + $GLPlugin::statefilesdir, $self->opts->hostname, + $self->opts->mode, $mib, $table, join('#', @{$key_attr}); + my $update = time - 3600; + #my $update = time - 1; + if ($force || ! -f $statefile || ((stat $statefile)[9]) < ($update)) { + $self->debug(sprintf 'force update of %s %s %s %s cache', + $self->opts->hostname, $self->opts->mode, $mib, $table); + $self->{$cache} = {}; + foreach my $entry ($self->get_snmp_table_objects($mib, $table)) { + my $key = join('#', map { $entry->{$_} } @{$key_attr}); + my $hash = $key . '-//-' . join('.', @{$entry->{indices}}); + $self->{$cache}->{$hash} = $entry->{indices}; + } + $self->save_cache($mib, $table, $key_attr); + } + $self->load_cache($mib, $table, $key_attr); +} + +# $self->update_entry_cache(0, $mib, $table, $key_attr); +# my @indices = $self->get_cache_indices(); +sub get_cache_indices { + my $self = shift; + my $mib = shift; + my $table = shift; + my $key_attr = shift; + if (ref($key_attr) ne "ARRAY") { + $key_attr = [$key_attr]; + } + my $cache = sprintf "%s_%s_%s_cache", + $mib, $table, join('#', @{$key_attr}); + my @indices = (); + foreach my $key (keys %{$self->{$cache}}) { + my ($descr, $index) = split('-//-', $key, 2); + if ($self->opts->name) { + if ($self->opts->regexp) { + my $pattern = $self->opts->name; + if ($descr =~ /$pattern/i) { + push(@indices, $self->{$cache}->{$key}); + } + } else { + if ($self->opts->name =~ /^\d+$/) { + if ($index == 1 * $self->opts->name) { + push(@indices, [1 * $self->opts->name]); + } + } else { + if (lc $descr eq lc $self->opts->name) { + push(@indices, $self->{$cache}->{$key}); + } + } + } + } else { + push(@indices, $self->{$cache}->{$key}); + } + } + return @indices; + return map { join('.', ref($_) eq "ARRAY" ? @{$_} : $_) } @indices; +} + +sub save_cache { + my $self = shift; + my $mib = shift; + my $table = shift; + my $key_attr = shift; + if (ref($key_attr) ne "ARRAY") { + $key_attr = [$key_attr]; + } + $self->create_statefilesdir(); + my $cache = sprintf "%s_%s_%s_cache", + $mib, $table, join('#', @{$key_attr}); + my $statefile = lc sprintf "%s/%s_%s_%s-%s_%s_cache", + $GLPlugin::statefilesdir, $self->opts->hostname, + $self->opts->mode, $mib, $table, join('#', @{$key_attr}); + open(STATE, ">".$statefile.".".$$); + printf STATE Data::Dumper::Dumper($self->{$cache}); + close STATE; + rename $statefile.".".$$, $statefile; + $self->debug(sprintf "saved %s to %s", + Data::Dumper::Dumper($self->{$cache}), $statefile); +} + +sub load_cache { + my $self = shift; + my $mib = shift; + my $table = shift; + my $key_attr = shift; + if (ref($key_attr) ne "ARRAY") { + $key_attr = [$key_attr]; + } + my $cache = sprintf "%s_%s_%s_cache", + $mib, $table, join('#', @{$key_attr}); + my $statefile = lc sprintf "%s/%s_%s_%s-%s_%s_cache", + $GLPlugin::statefilesdir, $self->opts->hostname, + $self->opts->mode, $mib, $table, join('#', @{$key_attr}); + $self->{$cache} = {}; + if ( -f $statefile) { + our $VAR1; + our $VAR2; + eval { + require $statefile; + }; + if($@) { + printf "rumms\n"; + } + # keinesfalls mehr require verwenden!!!!!! + # beim require enthaelt VAR1 andere werte als beim slurp + # und zwar diejenigen, die beim letzten save_cache geschrieben wurden. + my $content = do { local (@ARGV, $/) = $statefile; my $x = <>; close ARGV; $x }; + $VAR1 = eval "$content"; + $self->debug(sprintf "load %s", Data::Dumper::Dumper($VAR1)); + $self->{$cache} = $VAR1; + } +} + +sub no_such_mode { + my $self = shift; + if (ref($self) eq "Classes::Generic") { + $self->init(); + } elsif (ref($self) eq "Classes::Device") { + $self->add_message(UNKNOWN, 'the device did not implement the mibs this plugin is asking for'); + $self->add_message(UNKNOWN, + sprintf('unknown device%s', $self->{productname} eq 'unknown' ? + '' : '('.$self->{productname}.')')); + } elsif (ref($self) eq "GLPlugin::SNMP") { + # uptime, offline + $self->init(); + } else { + eval { + bless $self, "Classes::Generic"; + $self->init(); + }; + if ($@) { + bless $self, "GLPlugin::SNMP"; + $self->init(); + } + } + printf "Mode %s is not implemented for this type of device\n", + $self->opts->mode; + exit 3; +} + +sub AUTOLOAD { + my $self = shift; + return if ($AUTOLOAD =~ /DESTROY/); + if ($AUTOLOAD =~ /^(.*)::analyze_and_check_(.*)_subsystem$/) { + my $class = $1; + my $subsystem = $2; + my $analyze = sprintf "analyze_%s_subsystem", $subsystem; + my $check = sprintf "check_%s_subsystem", $subsystem; + my @params = @_; + if (@params) { + # analyzer class + my $subsystem_class = shift @params; + $self->{components}->{$subsystem.'_subsystem'} = $subsystem_class->new(); + } else { + $self->$analyze(); + } + $self->$check(); + } elsif ($AUTOLOAD =~ /^(.*)::check_(.*)_subsystem$/) { + my $class = $1; + my $subsystem = sprintf "%s_subsystem", $2; + $self->{components}->{$subsystem}->check(); + $self->{components}->{$subsystem}->dump() + if $self->opts->verbose >= 2; + } +else { +printf "auto %s\n", $AUTOLOAD; +} +} + + +package GLPlugin::Item; +our @ISA = qw(GLPlugin::SNMP); + +use strict; + +sub new { + my $class = shift; + my %params = @_; + my $self = { + blacklisted => 0, + info => undef, + extendedinfo => undef, + }; + bless $self, $class; + $self->init(%params); + return $self; +} + +sub dump { + my $self = shift; + my $class = ref($self); + $class =~ s/^.*:://; + printf "[%s_%s]\n", uc $class, $self->{flat_indices}; + foreach (grep !/^(blacklisted|extendedinfo|flat_indices|indices)/, keys %{$self}) { + printf "%s %s\n", $_, $self->{$_} if defined $self->{$_} && ref($self->{$_}) ne "ARRAY"; + } + printf "\n"; +} + +package GLPlugin::TableItem; +our @ISA = qw(GLPlugin::Item); + +use strict; + +sub new { + my $class = shift; + my %params = @_; + my $self = {}; + bless $self, $class; + foreach (keys %params) { + $self->{$_} = $params{$_}; + } + return $self; +} + + diff --git a/plugins-scripts/Makefile.am b/plugins-scripts/Makefile.am index 207ba51c..fa02042d 100644 --- a/plugins-scripts/Makefile.am +++ b/plugins-scripts/Makefile.am @@ -151,7 +151,6 @@ EXTRA_MODULES=\ Classes/Foundry.pm \ Classes/Bluecoat.pm \ Classes/MibsAndOids.pm \ - Classes/Generic.pm \ Classes/Device.pm EXTRA_DIST=check_nwc_health.pl $(EXTRA_MODULES) diff --git a/plugins-scripts/Nagios/MiniPlugin.pm b/plugins-scripts/Nagios/MiniPlugin.pm index bd09c8f6..2cb0f7e9 100644 --- a/plugins-scripts/Nagios/MiniPlugin.pm +++ b/plugins-scripts/Nagios/MiniPlugin.pm @@ -1,497 +1,497 @@ -package Nagios::MiniPlugin; - -use strict; -use Getopt::Long qw(:config no_ignore_case bundling); - -our @STATUS_CODES = qw(OK WARNING CRITICAL UNKNOWN DEPENDENT); - -require Exporter; -our @ISA = qw(Exporter); -our @EXPORT = (@STATUS_CODES, qw(nagios_exit nagios_die check_messages)); -our @EXPORT_OK = qw(%ERRORS); - -use constant OK => 0; -use constant WARNING => 1; -use constant CRITICAL => 2; -use constant UNKNOWN => 3; -use constant DEPENDENT => 4; - -our %ERRORS = ( - 'OK' => OK, - 'WARNING' => WARNING, - 'CRITICAL' => CRITICAL, - 'UNKNOWN' => UNKNOWN, - 'DEPENDENT' => DEPENDENT, -); - -our %STATUS_TEXT = reverse %ERRORS; - -sub new { - my $class = shift; - my %params = @_; - my $self = { - perfdata => [], - messages => { - ok => [], - warning => [], - critical => [], - unknown => [], - }, - args => [], - opts => Nagios::MiniPlugin::Getopt->new(%params), - }; - foreach (qw(shortname usage version url plugin blurb extra - license timeout)) { - $self->{$_} = $params{$_}; - } - bless $self, $class; -} - -sub add_arg { - my $self = shift; - $self->{opts}->add_arg(@_); -} - -sub getopts { - my $self = shift; - $self->{opts}->getopts(); -} - -sub override_opt { - my $self = shift; - $self->{opts}->override_opt(@_); -} - -sub create_opt { - my $self = shift; - $self->{opts}->create_opt(@_); -} - -sub opts { - my $self = shift; - return $self->{opts}; -} - -sub add_message { - my $self = shift; - my ($code, @messages) = @_; - $code = (qw(ok warning critical unknown))[$code] if $code =~ /^\d+$/; - $code = lc $code; - push @{$self->{messages}->{$code}}, @messages; -} - -sub add_perfdata { - my ($self, %args) = @_; - #if ($args{label} =~ /\s/) { - $args{label} = '\''.$args{label}.'\''; - #} - if (! exists $args{places}) { - $args{places} = 2; - } - my $format = '%d'; - if ($args{value} =~ /\./) { - $format = '%.'.$args{places}.'f'; - } - my $str = $args{label}.'='.sprintf $format, $args{value}; - if ($args{uom}) { - $str .= $args{uom}; - } - if ($args{warning}) { - $str .= ';'.$args{warning}; - } - if ($args{critical}) { - $str .= ';'.$args{critical}; - } - push @{$self->{perfdata}}, $str; -} - -sub add_html { - my $self = shift; - my $line = shift; - push @{$self->{html}}, $line; -} - -sub suppress_messages { - my $self = shift; - $self->{suppress_messages} = 1; -} - -sub clear_messages { - my $self = shift; - my $code = shift; - $code = (qw(ok warning critical unknown))[$code] if $code =~ /^\d+$/; - $code = lc $code; - $self->{messages}->{$code} = []; -} - -sub check_messages { - my $self = shift; - my %args = @_; - - # Add object messages to any passed in as args - for my $code (qw(critical warning unknown ok)) { - my $messages = $self->{messages}->{$code} || []; - if ($args{$code}) { - unless (ref $args{$code} eq 'ARRAY') { - if ($code eq 'ok') { - $args{$code} = [ $args{$code} ]; - } - } - push @{$args{$code}}, @$messages; - } else { - $args{$code} = $messages; - } - } - my %arg = %args; - $arg{join} = ' ' unless defined $arg{join}; - - # Decide $code - my $code = OK; - $code ||= CRITICAL if @{$arg{critical}}; - $code ||= WARNING if @{$arg{warning}}; - $code ||= UNKNOWN if @{$arg{unknown}}; - return $code unless wantarray; - - # Compose message - my $message = ''; - if ($arg{join_all}) { - $message = join( $arg{join_all}, - map { @$_ ? join( $arg{'join'}, @$_) : () } - $arg{critical}, - $arg{warning}, - $arg{unknown}, - $arg{ok} ? (ref $arg{ok} ? $arg{ok} : [ $arg{ok} ]) : [] - ); - } - - else { - $message ||= join( $arg{'join'}, @{$arg{critical}} ) - if $code == CRITICAL; - $message ||= join( $arg{'join'}, @{$arg{warning}} ) - if $code == WARNING; - $message ||= join( $arg{'join'}, @{$arg{unknown}} ) - if $code == UNKNOWN; - $message ||= ref $arg{ok} ? join( $arg{'join'}, @{$arg{ok}} ) : $arg{ok} - if $arg{ok}; - } - - return ($code, $message); -} - -sub status_code { - my $self = shift; - my $code = shift; - $code = (qw(ok warning critical unknown))[$code] if $code =~ /^\d+$/; - $code = uc $code; - $code = $ERRORS{$code} if defined $code && exists $ERRORS{$code}; - $code = UNKNOWN unless defined $code && exists $STATUS_TEXT{$code}; - return "$STATUS_TEXT{$code}"; -} - -sub perfdata_string { - my $self = shift; - if (scalar (@{$self->{perfdata}})) { - return join(" ", @{$self->{perfdata}}); - } else { - return ""; - } -} - -sub html_string { - my $self = shift; - if (scalar (@{$self->{html}})) { - return join(" ", @{$self->{html}}); - } else { - return ""; - } -} - -sub nagios_exit { - my $self = shift; - my ($code, $message, $arg) = @_; - $code = $ERRORS{$code} if defined $code && exists $ERRORS{$code}; - $code = UNKNOWN unless defined $code && exists $STATUS_TEXT{$code}; - $message = '' unless defined $message; - if (ref $message && ref $message eq 'ARRAY') { - $message = join(' ', map { chomp; $_ } @$message); - } else { - chomp $message; - } - my $output = "$STATUS_TEXT{$code}"; - $output .= " - $message" if defined $message && $message ne ''; - if (scalar (@{$self->{perfdata}})) { - $output .= " | ".$self->perfdata_string(); - } - $output .= "\n"; - if (! exists $self->{suppress_messages}) { - print $output; - } - exit $code; -} - -sub set_thresholds { - my $self = shift; - my %params = @_; - $self->{mywarning} = $self->opts->warning || $params{warning} || 0; - $self->{mycritical} = $self->opts->critical || $params{critical} || 0; -} - -sub force_thresholds { - my $self = shift; - my %params = @_; - $self->{mywarning} = $params{warning} || 0; - $self->{mycritical} = $params{critical} || 0; -} - -sub get_thresholds { - my $self = shift; - return ($self->{mywarning}, $self->{mycritical}); -} - -sub check_thresholds { - my $self = shift; - my @params = @_; - my $level = $ERRORS{OK}; - my $warningrange; - my $criticalrange; - my $value; - if (scalar(@params) > 1) { - my %params = @params; - $value = $params{check}; - $warningrange = (defined $params{warning}) ? - $params{warning} : $self->{mywarning}; - $criticalrange = (defined $params{critical}) ? - $params{critical} : $self->{mycritical}; - } else { - $value = $params[0]; - $warningrange = $self->{mywarning}; - $criticalrange = $self->{mycritical}; - } - if ($warningrange =~ /^(-*\d+)$/) { - # warning = 10, warn if > 10 or < 0 - $level = $ERRORS{WARNING} - if ($value > $1 || $value < 0); - } elsif ($warningrange =~ /^(-*\d+):$/) { - # warning = 10:, warn if < 10 - $level = $ERRORS{WARNING} - if ($value < $1); - } elsif ($warningrange =~ /^~:(-*\d+)$/) { - # warning = ~:10, warn if > 10 - $level = $ERRORS{WARNING} - if ($value > $1); - } elsif ($warningrange =~ /^(-*\d+):(-*\d+)$/) { - # warning = 10:20, warn if < 10 or > 20 - $level = $ERRORS{WARNING} - if ($value < $1 || $value > $2); - } elsif ($warningrange =~ /^@(-*\d+):(-*\d+)$/) { - # warning = @10:20, warn if >= 10 and <= 20 - $level = $ERRORS{WARNING} - if ($value >= $1 && $value <= $2); - } - if ($criticalrange =~ /^(-*\d+)$/) { - # critical = 10, crit if > 10 or < 0 - $level = $ERRORS{CRITICAL} - if ($value > $1 || $value < 0); - } elsif ($criticalrange =~ /^(-*\d+):$/) { - # critical = 10:, crit if < 10 - $level = $ERRORS{CRITICAL} - if ($value < $1); - } elsif ($criticalrange =~ /^~:(-*\d+)$/) { - # critical = ~:10, crit if > 10 - $level = $ERRORS{CRITICAL} - if ($value > $1); - } elsif ($criticalrange =~ /^(-*\d+):(-*\d+)$/) { - # critical = 10:20, crit if < 10 or > 20 - $level = $ERRORS{CRITICAL} - if ($value < $1 || $value > $2); - } elsif ($criticalrange =~ /^@(-*\d+):(-*\d+)$/) { - # critical = @10:20, crit if >= 10 and <= 20 - $level = $ERRORS{CRITICAL} - if ($value >= $1 && $value <= $2); - } - return $level; -} - - -package Nagios::MiniPlugin::Getopt; - -use strict; -use File::Basename; -use Data::Dumper; -use Getopt::Long qw(:config no_ignore_case bundling); - -# Standard defaults -my %DEFAULT = ( - timeout => 15, - verbose => 0, - license => -"This nagios plugin is free software, and comes with ABSOLUTELY NO WARRANTY. -It may be used, redistributed and/or modified under the terms of the GNU -General Public Licence (see http://www.fsf.org/licensing/licenses/gpl.txt).", -); -# Standard arguments -my @ARGS = ({ - spec => 'usage|?', - help => "-?, --usage\n Print usage information", - }, { - spec => 'help|h', - help => "-h, --help\n Print detailed help screen", - }, { - spec => 'version|V', - help => "-V, --version\n Print version information", - }, { - #spec => 'extra-opts:s@', - #help => "--extra-opts=[
[@]]\n Section and/or config_file from which to load extra options (may repeat)", - }, { - spec => 'timeout|t=i', - help => sprintf("-t, --timeout=INTEGER\n Seconds before plugin times out (default: %s)", $DEFAULT{timeout}), - default => $DEFAULT{timeout}, - }, { - spec => 'verbose|v+', - help => "-v, --verbose\n Show details for command-line debugging (can repeat up to 3 times)", - default => $DEFAULT{verbose}, - }, -); -# Standard arguments we traditionally display last in the help output -my %DEFER_ARGS = map { $_ => 1 } qw(timeout verbose); - -sub _init -{ - my $self = shift; - my %params = @_; - # Check params - my $plugin = basename($ENV{NAGIOS_PLUGIN} || $0); - #my %attr = validate( @_, { - my %attr = ( - usage => 1, - version => 0, - url => 0, - plugin => { default => $plugin }, - blurb => 0, - extra => 0, - 'extra-opts' => 0, - license => { default => $DEFAULT{license} }, - timeout => { default => $DEFAULT{timeout} }, - ); - - # Add attr to private _attr hash (except timeout) - $self->{timeout} = delete $attr{timeout}; - $self->{_attr} = { %attr }; - foreach (keys %{$self->{_attr}}) { - if (exists $params{$_}) { - $self->{_attr}->{$_} = $params{$_}; - } else { - $self->{_attr}->{$_} = $self->{_attr}->{$_}->{default} - if ref ($self->{_attr}->{$_}) eq 'HASH' && - exists $self->{_attr}->{$_}->{default}; - } - } - # Chomp _attr values - chomp foreach values %{$self->{_attr}}; - - # Setup initial args list - $self->{_args} = [ grep { exists $_->{spec} } @ARGS ]; - - $self -} - -sub new -{ - my $class = shift; - my $self = bless {}, $class; - $self->_init(@_); -} - -sub add_arg { - my $self = shift; - my %arg = @_; - push (@{$self->{_args}}, \%arg); -} - -sub getopts { - my $self = shift; - my %commandline = (); - my @params = map { $_->{spec} } @{$self->{_args}}; - if (! GetOptions(\%commandline, @params)) { - $self->print_help(); - exit 0; - } else { - no strict 'refs'; - do { $self->print_help(); exit 0; } if $commandline{help}; - do { $self->print_version(); exit 0 } if $commandline{version}; - do { $self->print_usage(); exit 3 } if $commandline{usage}; - foreach (map { $_->{spec} =~ /^([\w\-]+)/; $1; } @{$self->{_args}}) { - my $field = $_; - *{"$field"} = sub { - return $self->{opts}->{$field}; - }; - } - foreach (map { $_->{spec} =~ /^([\w\-]+)/; $1; } - grep { exists $_->{required} && $_->{required} } @{$self->{_args}}) { - do { $self->print_usage(); exit 0 } if ! exists $commandline{$_}; - } - foreach (grep { exists $_->{default} } @{$self->{_args}}) { - $_->{spec} =~ /^([\w\-]+)/; - my $spec = $1; - $self->{opts}->{$spec} = $_->{default}; - } - foreach (keys %commandline) { - $self->{opts}->{$_} = $commandline{$_}; - } - } -} - -sub create_opt { - my $self = shift; - my $key = shift; - no strict 'refs'; - *{"$key"} = sub { - return $self->{opts}->{$key}; - }; -} - -sub override_opt { - my $self = shift; - my $key = shift; - my $value = shift; - $self->{opts}->{$key} = $value; -} - -sub get { - my $self = shift; - my $opt = shift; - return $self->{opts}->{$opt}; -} - -sub print_help { - my $self = shift; - $self->print_version(); - printf "\n%s\n", $self->{_attr}->{license}; - printf "\n%s\n\n", $self->{_attr}->{blurb}; - $self->print_usage(); - foreach (@{$self->{_args}}) { - printf " %s\n", $_->{help}; - } - exit 0; -} - -sub print_usage { - my $self = shift; - printf $self->{_attr}->{usage}, $self->{_attr}->{plugin}; - print "\n"; -} - -sub print_version { - my $self = shift; - printf "%s %s", $self->{_attr}->{plugin}, $self->{_attr}->{version}; - printf " [%s]", $self->{_attr}->{url} if $self->{_attr}->{url}; - print "\n"; -} - -sub print_license { - my $self = shift; - printf "%s\n", $self->{_attr}->{license}; - print "\n"; -} - -1; +package Nagios::MiniPlugin; + +use strict; +use Getopt::Long qw(:config no_ignore_case bundling); + +our @STATUS_CODES = qw(OK WARNING CRITICAL UNKNOWN DEPENDENT); + +require Exporter; +our @ISA = qw(Exporter); +our @EXPORT = (@STATUS_CODES, qw(nagios_exit nagios_die check_messages)); +our @EXPORT_OK = qw(%ERRORS); + +use constant OK => 0; +use constant WARNING => 1; +use constant CRITICAL => 2; +use constant UNKNOWN => 3; +use constant DEPENDENT => 4; + +our %ERRORS = ( + 'OK' => OK, + 'WARNING' => WARNING, + 'CRITICAL' => CRITICAL, + 'UNKNOWN' => UNKNOWN, + 'DEPENDENT' => DEPENDENT, +); + +our %STATUS_TEXT = reverse %ERRORS; + +sub new { + my $class = shift; + my %params = @_; + my $self = { + perfdata => [], + messages => { + ok => [], + warning => [], + critical => [], + unknown => [], + }, + args => [], + opts => Nagios::MiniPlugin::Getopt->new(%params), + }; + foreach (qw(shortname usage version url plugin blurb extra + license timeout)) { + $self->{$_} = $params{$_}; + } + bless $self, $class; +} + +sub add_arg { + my $self = shift; + $self->{opts}->add_arg(@_); +} + +sub getopts { + my $self = shift; + $self->{opts}->getopts(); +} + +sub override_opt { + my $self = shift; + $self->{opts}->override_opt(@_); +} + +sub create_opt { + my $self = shift; + $self->{opts}->create_opt(@_); +} + +sub opts { + my $self = shift; + return $self->{opts}; +} + +sub add_message { + my $self = shift; + my ($code, @messages) = @_; + $code = (qw(ok warning critical unknown))[$code] if $code =~ /^\d+$/; + $code = lc $code; + push @{$self->{messages}->{$code}}, @messages; +} + +sub add_perfdata { + my ($self, %args) = @_; + #if ($args{label} =~ /\s/) { + $args{label} = '\''.$args{label}.'\''; + #} + if (! exists $args{places}) { + $args{places} = 2; + } + my $format = '%d'; + if ($args{value} =~ /\./) { + $format = '%.'.$args{places}.'f'; + } + my $str = $args{label}.'='.sprintf $format, $args{value}; + if ($args{uom}) { + $str .= $args{uom}; + } + if ($args{warning}) { + $str .= ';'.$args{warning}; + } + if ($args{critical}) { + $str .= ';'.$args{critical}; + } + push @{$self->{perfdata}}, $str; +} + +sub add_html { + my $self = shift; + my $line = shift; + push @{$self->{html}}, $line; +} + +sub suppress_messages { + my $self = shift; + $self->{suppress_messages} = 1; +} + +sub clear_messages { + my $self = shift; + my $code = shift; + $code = (qw(ok warning critical unknown))[$code] if $code =~ /^\d+$/; + $code = lc $code; + $self->{messages}->{$code} = []; +} + +sub check_messages { + my $self = shift; + my %args = @_; + + # Add object messages to any passed in as args + for my $code (qw(critical warning unknown ok)) { + my $messages = $self->{messages}->{$code} || []; + if ($args{$code}) { + unless (ref $args{$code} eq 'ARRAY') { + if ($code eq 'ok') { + $args{$code} = [ $args{$code} ]; + } + } + push @{$args{$code}}, @$messages; + } else { + $args{$code} = $messages; + } + } + my %arg = %args; + $arg{join} = ' ' unless defined $arg{join}; + + # Decide $code + my $code = OK; + $code ||= CRITICAL if @{$arg{critical}}; + $code ||= WARNING if @{$arg{warning}}; + $code ||= UNKNOWN if @{$arg{unknown}}; + return $code unless wantarray; + + # Compose message + my $message = ''; + if ($arg{join_all}) { + $message = join( $arg{join_all}, + map { @$_ ? join( $arg{'join'}, @$_) : () } + $arg{critical}, + $arg{warning}, + $arg{unknown}, + $arg{ok} ? (ref $arg{ok} ? $arg{ok} : [ $arg{ok} ]) : [] + ); + } + + else { + $message ||= join( $arg{'join'}, @{$arg{critical}} ) + if $code == CRITICAL; + $message ||= join( $arg{'join'}, @{$arg{warning}} ) + if $code == WARNING; + $message ||= join( $arg{'join'}, @{$arg{unknown}} ) + if $code == UNKNOWN; + $message ||= ref $arg{ok} ? join( $arg{'join'}, @{$arg{ok}} ) : $arg{ok} + if $arg{ok}; + } + + return ($code, $message); +} + +sub status_code { + my $self = shift; + my $code = shift; + $code = (qw(ok warning critical unknown))[$code] if $code =~ /^\d+$/; + $code = uc $code; + $code = $ERRORS{$code} if defined $code && exists $ERRORS{$code}; + $code = UNKNOWN unless defined $code && exists $STATUS_TEXT{$code}; + return "$STATUS_TEXT{$code}"; +} + +sub perfdata_string { + my $self = shift; + if (scalar (@{$self->{perfdata}})) { + return join(" ", @{$self->{perfdata}}); + } else { + return ""; + } +} + +sub html_string { + my $self = shift; + if (scalar (@{$self->{html}})) { + return join(" ", @{$self->{html}}); + } else { + return ""; + } +} + +sub nagios_exit { + my $self = shift; + my ($code, $message, $arg) = @_; + $code = $ERRORS{$code} if defined $code && exists $ERRORS{$code}; + $code = UNKNOWN unless defined $code && exists $STATUS_TEXT{$code}; + $message = '' unless defined $message; + if (ref $message && ref $message eq 'ARRAY') { + $message = join(' ', map { chomp; $_ } @$message); + } else { + chomp $message; + } + my $output = "$STATUS_TEXT{$code}"; + $output .= " - $message" if defined $message && $message ne ''; + if (scalar (@{$self->{perfdata}})) { + $output .= " | ".$self->perfdata_string(); + } + $output .= "\n"; + if (! exists $self->{suppress_messages}) { + print $output; + } + exit $code; +} + +sub set_thresholds { + my $self = shift; + my %params = @_; + $self->{mywarning} = $self->opts->warning || $params{warning} || 0; + $self->{mycritical} = $self->opts->critical || $params{critical} || 0; +} + +sub force_thresholds { + my $self = shift; + my %params = @_; + $self->{mywarning} = $params{warning} || 0; + $self->{mycritical} = $params{critical} || 0; +} + +sub get_thresholds { + my $self = shift; + return ($self->{mywarning}, $self->{mycritical}); +} + +sub check_thresholds { + my $self = shift; + my @params = @_; + my $level = $ERRORS{OK}; + my $warningrange; + my $criticalrange; + my $value; + if (scalar(@params) > 1) { + my %params = @params; + $value = $params{check}; + $warningrange = (defined $params{warning}) ? + $params{warning} : $self->{mywarning}; + $criticalrange = (defined $params{critical}) ? + $params{critical} : $self->{mycritical}; + } else { + $value = $params[0]; + $warningrange = $self->{mywarning}; + $criticalrange = $self->{mycritical}; + } + if ($warningrange =~ /^(-*\d+)$/) { + # warning = 10, warn if > 10 or < 0 + $level = $ERRORS{WARNING} + if ($value > $1 || $value < 0); + } elsif ($warningrange =~ /^(-*\d+):$/) { + # warning = 10:, warn if < 10 + $level = $ERRORS{WARNING} + if ($value < $1); + } elsif ($warningrange =~ /^~:(-*\d+)$/) { + # warning = ~:10, warn if > 10 + $level = $ERRORS{WARNING} + if ($value > $1); + } elsif ($warningrange =~ /^(-*\d+):(-*\d+)$/) { + # warning = 10:20, warn if < 10 or > 20 + $level = $ERRORS{WARNING} + if ($value < $1 || $value > $2); + } elsif ($warningrange =~ /^@(-*\d+):(-*\d+)$/) { + # warning = @10:20, warn if >= 10 and <= 20 + $level = $ERRORS{WARNING} + if ($value >= $1 && $value <= $2); + } + if ($criticalrange =~ /^(-*\d+)$/) { + # critical = 10, crit if > 10 or < 0 + $level = $ERRORS{CRITICAL} + if ($value > $1 || $value < 0); + } elsif ($criticalrange =~ /^(-*\d+):$/) { + # critical = 10:, crit if < 10 + $level = $ERRORS{CRITICAL} + if ($value < $1); + } elsif ($criticalrange =~ /^~:(-*\d+)$/) { + # critical = ~:10, crit if > 10 + $level = $ERRORS{CRITICAL} + if ($value > $1); + } elsif ($criticalrange =~ /^(-*\d+):(-*\d+)$/) { + # critical = 10:20, crit if < 10 or > 20 + $level = $ERRORS{CRITICAL} + if ($value < $1 || $value > $2); + } elsif ($criticalrange =~ /^@(-*\d+):(-*\d+)$/) { + # critical = @10:20, crit if >= 10 and <= 20 + $level = $ERRORS{CRITICAL} + if ($value >= $1 && $value <= $2); + } + return $level; +} + + +package Nagios::MiniPlugin::Getopt; + +use strict; +use File::Basename; +use Data::Dumper; +use Getopt::Long qw(:config no_ignore_case bundling); + +# Standard defaults +my %DEFAULT = ( + timeout => 15, + verbose => 0, + license => +"This nagios plugin is free software, and comes with ABSOLUTELY NO WARRANTY. +It may be used, redistributed and/or modified under the terms of the GNU +General Public Licence (see http://www.fsf.org/licensing/licenses/gpl.txt).", +); +# Standard arguments +my @ARGS = ({ + spec => 'usage|?', + help => "-?, --usage\n Print usage information", + }, { + spec => 'help|h', + help => "-h, --help\n Print detailed help screen", + }, { + spec => 'version|V', + help => "-V, --version\n Print version information", + }, { + #spec => 'extra-opts:s@', + #help => "--extra-opts=[
[@]]\n Section and/or config_file from which to load extra options (may repeat)", + }, { + spec => 'timeout|t=i', + help => sprintf("-t, --timeout=INTEGER\n Seconds before plugin times out (default: %s)", $DEFAULT{timeout}), + default => $DEFAULT{timeout}, + }, { + spec => 'verbose|v+', + help => "-v, --verbose\n Show details for command-line debugging (can repeat up to 3 times)", + default => $DEFAULT{verbose}, + }, +); +# Standard arguments we traditionally display last in the help output +my %DEFER_ARGS = map { $_ => 1 } qw(timeout verbose); + +sub _init +{ + my $self = shift; + my %params = @_; + # Check params + my $plugin = basename($ENV{NAGIOS_PLUGIN} || $0); + #my %attr = validate( @_, { + my %attr = ( + usage => 1, + version => 0, + url => 0, + plugin => { default => $plugin }, + blurb => 0, + extra => 0, + 'extra-opts' => 0, + license => { default => $DEFAULT{license} }, + timeout => { default => $DEFAULT{timeout} }, + ); + + # Add attr to private _attr hash (except timeout) + $self->{timeout} = delete $attr{timeout}; + $self->{_attr} = { %attr }; + foreach (keys %{$self->{_attr}}) { + if (exists $params{$_}) { + $self->{_attr}->{$_} = $params{$_}; + } else { + $self->{_attr}->{$_} = $self->{_attr}->{$_}->{default} + if ref ($self->{_attr}->{$_}) eq 'HASH' && + exists $self->{_attr}->{$_}->{default}; + } + } + # Chomp _attr values + chomp foreach values %{$self->{_attr}}; + + # Setup initial args list + $self->{_args} = [ grep { exists $_->{spec} } @ARGS ]; + + $self +} + +sub new +{ + my $class = shift; + my $self = bless {}, $class; + $self->_init(@_); +} + +sub add_arg { + my $self = shift; + my %arg = @_; + push (@{$self->{_args}}, \%arg); +} + +sub getopts { + my $self = shift; + my %commandline = (); + my @params = map { $_->{spec} } @{$self->{_args}}; + if (! GetOptions(\%commandline, @params)) { + $self->print_help(); + exit 0; + } else { + no strict 'refs'; + do { $self->print_help(); exit 0; } if $commandline{help}; + do { $self->print_version(); exit 0 } if $commandline{version}; + do { $self->print_usage(); exit 3 } if $commandline{usage}; + foreach (map { $_->{spec} =~ /^([\w\-]+)/; $1; } @{$self->{_args}}) { + my $field = $_; + *{"$field"} = sub { + return $self->{opts}->{$field}; + }; + } + foreach (map { $_->{spec} =~ /^([\w\-]+)/; $1; } + grep { exists $_->{required} && $_->{required} } @{$self->{_args}}) { + do { $self->print_usage(); exit 0 } if ! exists $commandline{$_}; + } + foreach (grep { exists $_->{default} } @{$self->{_args}}) { + $_->{spec} =~ /^([\w\-]+)/; + my $spec = $1; + $self->{opts}->{$spec} = $_->{default}; + } + foreach (keys %commandline) { + $self->{opts}->{$_} = $commandline{$_}; + } + } +} + +sub create_opt { + my $self = shift; + my $key = shift; + no strict 'refs'; + *{"$key"} = sub { + return $self->{opts}->{$key}; + }; +} + +sub override_opt { + my $self = shift; + my $key = shift; + my $value = shift; + $self->{opts}->{$key} = $value; +} + +sub get { + my $self = shift; + my $opt = shift; + return $self->{opts}->{$opt}; +} + +sub print_help { + my $self = shift; + $self->print_version(); + printf "\n%s\n", $self->{_attr}->{license}; + printf "\n%s\n\n", $self->{_attr}->{blurb}; + $self->print_usage(); + foreach (@{$self->{_args}}) { + printf " %s\n", $_->{help}; + } + exit 0; +} + +sub print_usage { + my $self = shift; + printf $self->{_attr}->{usage}, $self->{_attr}->{plugin}; + print "\n"; +} + +sub print_version { + my $self = shift; + printf "%s %s", $self->{_attr}->{plugin}, $self->{_attr}->{version}; + printf " [%s]", $self->{_attr}->{url} if $self->{_attr}->{url}; + print "\n"; +} + +sub print_license { + my $self = shift; + printf "%s\n", $self->{_attr}->{license}; + print "\n"; +} + +1; diff --git a/plugins-scripts/Server/Linux.pm b/plugins-scripts/Server/Linux.pm index 2528073c..af83ea9e 100644 --- a/plugins-scripts/Server/Linux.pm +++ b/plugins-scripts/Server/Linux.pm @@ -1,332 +1,332 @@ -package Server::Linux; - -use strict; - -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - -our @ISA = qw(Classes::Device); - -sub init { - my $self = shift; - $self->{components} = { - interface_subsystem => undef, - }; - $self->{serial} = 'unknown'; - $self->{product} = 'unknown'; - $self->{romversion} = 'unknown'; - if (! $self->check_messages()) { - if ($self->mode =~ /device::interfaces/) { - $self->analyze_interface_subsystem(); - $self->check_interface_subsystem(); - } - } -} - -sub analyze_interface_subsystem { - my $self = shift; - $self->{components}->{interface_subsystem} = - Server::Linux::Component::InterfaceSubsystem->new(); -} - -sub check_interface_subsystem { - my $self = shift; - $self->{components}->{interface_subsystem}->check(); - $self->{components}->{interface_subsystem}->dump() - if $self->opts->verbose >= 2; -} - -package Server::Linux::Component::InterfaceSubsystem; -our @ISA = qw(Server::Linux); - -use strict; -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - -sub new { - my $class = shift; - my %params = @_; - my $self = { - interfaces => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; - bless $self, $class; - $self->init(%params); - return $self; -} - -sub init { - my $self = shift; - my %params = @_; - if ($self->mode =~ /device::interfaces::list/) { - foreach (glob "/sys/class/net/*") { - my $name = $_; - next if ! -d $name; - $name =~ s/.*\///g; - my $tmpif = { - ifDescr => $name, - }; - push(@{$self->{interfaces}}, - Server::Linux::Component::InterfaceSubsystem::Interface->new(%{$tmpif})); - } - } else { - foreach (glob "/sys/class/net/*") { - my $name = $_; - $name =~ s/.*\///g; - if ($self->opts->name) { - if ($self->opts->regexp) { - my $pattern = $self->opts->name; - if ($name !~ /$pattern/i) { - next; - } - } elsif (lc $name ne lc $self->opts->name) { - next; - } - } - *SAVEERR = *STDERR; - open ERR ,'>/dev/null'; - *STDERR = *ERR; - my $tmpif = { - ifDescr => $name, - ifSpeed => (-f "/sys/class/net/$name/speed" ? do { local (@ARGV, $/) = "/sys/class/net/$name/speed"; my $x = <>; close ARGV; $x} * 1024*1024 : undef), - ifInOctets => do { local (@ARGV, $/) = "/sys/class/net/$name/statistics/rx_bytes"; my $x = <>; close ARGV; $x}, - ifInDiscards => do { local (@ARGV, $/) = "/sys/class/net/$name/statistics/rx_dropped"; my $x = <>; close ARGV; $x}, - ifInErrors => do { local (@ARGV, $/) = "/sys/class/net/$name/statistics/rx_errors"; my $x = <>; close ARGV; $x}, - ifOutOctets => do { local (@ARGV, $/) = "/sys/class/net/$name/statistics/tx_bytes"; my $x = <>; close ARGV; $x}, - ifOutDiscards => do { local (@ARGV, $/) = "/sys/class/net/$name/statistics/tx_dropped"; my $x = <>; close ARGV; $x}, - ifOutErrors => do { local (@ARGV, $/) = "/sys/class/net/$name/statistics/tx_errors"; my $x = <>; close ARGV; $x}, - }; - *STDERR = *SAVEERR; - foreach (keys %{$tmpif}) { - chomp($tmpif->{$_}) if defined $tmpif->{$_}; - } - if (defined $self->opts->ifspeed) { - $tmpif->{ifSpeed} = $self->opts->ifspeed * 1024*1024; - } - if (! defined $tmpif->{ifSpeed}) { - $self->add_message(UNKNOWN, sprintf "There is no /sys/class/net/%s/speed. Use --ifspeed", $name); - } else { - push(@{$self->{interfaces}}, - Server::Linux::Component::InterfaceSubsystem::Interface->new(%{$tmpif})); - } - } - } -} - -sub check { - my $self = shift; - my $errorfound = 0; - $self->add_info('checking interfaces'); - $self->blacklist('ff', ''); - if (scalar(@{$self->{interfaces}}) == 0) { - $self->add_message(UNKNOWN, 'no interfaces'); - return; - } - if ($self->mode =~ /device::interfaces::list/) { - foreach (sort {$a->{ifDescr} cmp $b->{ifDescr}} @{$self->{interfaces}}) { - $_->list(); - } - } else { - if (scalar (@{$self->{interfaces}}) == 0) { - } else { - foreach (@{$self->{interfaces}}) { - $_->check(); - } - } - } -} - -sub dump { - my $self = shift; - foreach (@{$self->{interfaces}}) { - $_->dump(); - } -} - - -package Server::Linux::Component::InterfaceSubsystem::Interface; -our @ISA = qw(Server::Linux::Component::InterfaceSubsystem); - -use strict; -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - -sub new { - my $class = shift; - my %params = @_; - my $self = { - ifDescr => $params{ifDescr}, - ifSpeed => $params{ifSpeed}, - ifInOctets => $params{ifInOctets}, - ifInDiscards => $params{ifInDiscards}, - ifInErrors => $params{ifInErrors}, - ifOutOctets => $params{ifOutOctets}, - ifOutDiscards => $params{ifOutDiscards}, - ifOutErrors => $params{ifOutErrors}, - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; - foreach my $key (keys %params) { - $self->{$key} = 0 if ! defined $params{$key}; - } - bless $self, $class; - $self->init(); - return $self; -} - -sub init { - my $self = shift; - if ($self->mode =~ /device::interfaces::traffic/) { - $self->valdiff({name => $self->{ifDescr}}, qw(ifInOctets ifInDiscards ifInErrors ifOutOctets ifOutDiscards ifOutErrors)); - } elsif ($self->mode =~ /device::interfaces::usage/) { - $self->valdiff({name => $self->{ifDescr}}, qw(ifInOctets ifOutOctets)); - if ($self->{ifSpeed} == 0) { - # vlan graffl - $self->{inputUtilization} = 0; - $self->{outputUtilization} = 0; - } else { - $self->{inputUtilization} = $self->{delta_ifInOctets} * 8 * 100 / - ($self->{delta_timestamp} * $self->{ifSpeed}); - $self->{outputUtilization} = $self->{delta_ifOutOctets} * 8 * 100 / - ($self->{delta_timestamp} * $self->{ifSpeed}); - } - $self->{inputRate} = $self->{delta_ifInOctets} / $self->{delta_timestamp}; - $self->{outputRate} = $self->{delta_ifOutOctets} / $self->{delta_timestamp}; - my $factor = 1/8; # default Bits - if ($self->opts->units) { - if ($self->opts->units eq "GB") { - $factor = 1024 * 1024 * 1024; - } elsif ($self->opts->units eq "MB") { - $factor = 1024 * 1024; - } elsif ($self->opts->units eq "KB") { - $factor = 1024; - } elsif ($self->opts->units eq "GBi") { - $factor = 1024 * 1024 * 1024 / 8; - } elsif ($self->opts->units eq "MBi") { - $factor = 1024 * 1024 / 8; - } elsif ($self->opts->units eq "KBi") { - $factor = 1024 / 8; - } elsif ($self->opts->units eq "B") { - $factor = 1; - } elsif ($self->opts->units eq "Bit") { - $factor = 1/8; - } - } - $self->{inputRate} /= $factor; - $self->{outputRate} /= $factor; - } elsif ($self->mode =~ /device::interfaces::errors/) { - $self->valdiff({name => $self->{ifDescr}}, qw(ifInErrors ifOutErrors ifInDiscards ifOutDiscards)); - $self->{inputErrorRate} = $self->{delta_ifInErrors} - / $self->{delta_timestamp}; - $self->{outputErrorRate} = $self->{delta_ifOutErrors} - / $self->{delta_timestamp}; - $self->{inputDiscardRate} = $self->{delta_ifInDiscards} - / $self->{delta_timestamp}; - $self->{outputDiscardRate} = $self->{delta_ifOutDiscards} - / $self->{delta_timestamp}; - $self->{inputRate} = ($self->{delta_ifInErrors} + $self->{delta_ifInDiscards}) - / $self->{delta_timestamp}; - $self->{outputRate} = ($self->{delta_ifOutErrors} + $self->{delta_ifOutDiscards}) - / $self->{delta_timestamp}; - } elsif ($self->mode =~ /device::interfaces::operstatus/) { - } - return $self; -} - -sub check { - my $self = shift; - $self->blacklist('if', $self->{ifDescr}); - if ($self->mode =~ /device::interfaces::traffic/) { - } elsif ($self->mode =~ /device::interfaces::usage/) { - my $info = sprintf 'interface %s usage is in:%.2f%% (%s) out:%.2f%% (%s)', - $self->{ifDescr}, - $self->{inputUtilization}, - sprintf("%.2f%s/s", $self->{inputRate}, - ($self->opts->units ? $self->opts->units : 'Bits')), - $self->{outputUtilization}, - sprintf("%.2f%s/s", $self->{outputRate}, - ($self->opts->units ? $self->opts->units : 'Bits')); - $self->add_info($info); - $self->set_thresholds(warning => 80, critical => 90); - my $in = $self->check_thresholds($self->{inputUtilization}); - my $out = $self->check_thresholds($self->{outputUtilization}); - my $level = ($in > $out) ? $in : ($out > $in) ? $out : $in; - $self->add_message($level, $info); - $self->add_perfdata( - label => $self->{ifDescr}.'_usage_in', - value => $self->{inputUtilization}, - uom => '%', - warning => $self->{warning}, - critical => $self->{critical}, - ); - $self->add_perfdata( - label => $self->{ifDescr}.'_usage_out', - value => $self->{outputUtilization}, - uom => '%', - warning => $self->{warning}, - critical => $self->{critical}, - ); - $self->add_perfdata( - label => $self->{ifDescr}.'_traffic_in', - value => $self->{inputRate}, - uom => $self->opts->units, - ); - $self->add_perfdata( - label => $self->{ifDescr}.'_traffic_out', - value => $self->{outputRate}, - uom => $self->opts->units, - ); - } elsif ($self->mode =~ /device::interfaces::errors/) { - my $info = sprintf 'interface %s errors in:%.2f/s out:%.2f/s '. - 'discards in:%.2f/s out:%.2f/s', - $self->{ifDescr}, - $self->{inputErrorRate} , $self->{outputErrorRate}, - $self->{inputDiscardRate} , $self->{outputDiscardRate}; - $self->add_info($info); - $self->set_thresholds(warning => 1, critical => 10); - my $in = $self->check_thresholds($self->{inputRate}); - my $out = $self->check_thresholds($self->{outputRate}); - my $level = ($in > $out) ? $in : ($out > $in) ? $out : $in; - $self->add_message($level, $info); - $self->add_perfdata( - label => $self->{ifDescr}.'_errors_in', - value => $self->{inputErrorRate}, - warning => $self->{warning}, - critical => $self->{critical}, - ); - $self->add_perfdata( - label => $self->{ifDescr}.'_errors_out', - value => $self->{outputErrorRate}, - warning => $self->{warning}, - critical => $self->{critical}, - ); - $self->add_perfdata( - label => $self->{ifDescr}.'_discards_in', - value => $self->{inputDiscardRate}, - warning => $self->{warning}, - critical => $self->{critical}, - ); - $self->add_perfdata( - label => $self->{ifDescr}.'_discards_out', - value => $self->{outputDiscardRate}, - warning => $self->{warning}, - critical => $self->{critical}, - ); - } -} - -sub list { - my $self = shift; - printf "%s\n", $self->{ifDescr}; -} - -sub dump { - my $self = shift; - printf "[IF_%s]\n", $self->{ifDescr}; - foreach (qw(ifDescr ifSpeed ifInOctets ifInDiscards ifInErrors ifOutOctets ifOutDiscards ifOutErrors)) { - printf "%s: %s\n", $_, defined $self->{$_} ? $self->{$_} : 'undefined'; - } -# printf "info: %s\n", $self->{info}; - printf "\n"; -} - +package Server::Linux; + +use strict; + +use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; + +our @ISA = qw(Classes::Device); + +sub init { + my $self = shift; + $self->{components} = { + interface_subsystem => undef, + }; + $self->{serial} = 'unknown'; + $self->{product} = 'unknown'; + $self->{romversion} = 'unknown'; + if (! $self->check_messages()) { + if ($self->mode =~ /device::interfaces/) { + $self->analyze_interface_subsystem(); + $self->check_interface_subsystem(); + } + } +} + +sub analyze_interface_subsystem { + my $self = shift; + $self->{components}->{interface_subsystem} = + Server::Linux::Component::InterfaceSubsystem->new(); +} + +sub check_interface_subsystem { + my $self = shift; + $self->{components}->{interface_subsystem}->check(); + $self->{components}->{interface_subsystem}->dump() + if $self->opts->verbose >= 2; +} + +package Server::Linux::Component::InterfaceSubsystem; +our @ISA = qw(Server::Linux); + +use strict; +use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; + +sub new { + my $class = shift; + my %params = @_; + my $self = { + interfaces => [], + blacklisted => 0, + info => undef, + extendedinfo => undef, + }; + bless $self, $class; + $self->init(%params); + return $self; +} + +sub init { + my $self = shift; + my %params = @_; + if ($self->mode =~ /device::interfaces::list/) { + foreach (glob "/sys/class/net/*") { + my $name = $_; + next if ! -d $name; + $name =~ s/.*\///g; + my $tmpif = { + ifDescr => $name, + }; + push(@{$self->{interfaces}}, + Server::Linux::Component::InterfaceSubsystem::Interface->new(%{$tmpif})); + } + } else { + foreach (glob "/sys/class/net/*") { + my $name = $_; + $name =~ s/.*\///g; + if ($self->opts->name) { + if ($self->opts->regexp) { + my $pattern = $self->opts->name; + if ($name !~ /$pattern/i) { + next; + } + } elsif (lc $name ne lc $self->opts->name) { + next; + } + } + *SAVEERR = *STDERR; + open ERR ,'>/dev/null'; + *STDERR = *ERR; + my $tmpif = { + ifDescr => $name, + ifSpeed => (-f "/sys/class/net/$name/speed" ? do { local (@ARGV, $/) = "/sys/class/net/$name/speed"; my $x = <>; close ARGV; $x} * 1024*1024 : undef), + ifInOctets => do { local (@ARGV, $/) = "/sys/class/net/$name/statistics/rx_bytes"; my $x = <>; close ARGV; $x}, + ifInDiscards => do { local (@ARGV, $/) = "/sys/class/net/$name/statistics/rx_dropped"; my $x = <>; close ARGV; $x}, + ifInErrors => do { local (@ARGV, $/) = "/sys/class/net/$name/statistics/rx_errors"; my $x = <>; close ARGV; $x}, + ifOutOctets => do { local (@ARGV, $/) = "/sys/class/net/$name/statistics/tx_bytes"; my $x = <>; close ARGV; $x}, + ifOutDiscards => do { local (@ARGV, $/) = "/sys/class/net/$name/statistics/tx_dropped"; my $x = <>; close ARGV; $x}, + ifOutErrors => do { local (@ARGV, $/) = "/sys/class/net/$name/statistics/tx_errors"; my $x = <>; close ARGV; $x}, + }; + *STDERR = *SAVEERR; + foreach (keys %{$tmpif}) { + chomp($tmpif->{$_}) if defined $tmpif->{$_}; + } + if (defined $self->opts->ifspeed) { + $tmpif->{ifSpeed} = $self->opts->ifspeed * 1024*1024; + } + if (! defined $tmpif->{ifSpeed}) { + $self->add_message(UNKNOWN, sprintf "There is no /sys/class/net/%s/speed. Use --ifspeed", $name); + } else { + push(@{$self->{interfaces}}, + Server::Linux::Component::InterfaceSubsystem::Interface->new(%{$tmpif})); + } + } + } +} + +sub check { + my $self = shift; + my $errorfound = 0; + $self->add_info('checking interfaces'); + $self->blacklist('ff', ''); + if (scalar(@{$self->{interfaces}}) == 0) { + $self->add_message(UNKNOWN, 'no interfaces'); + return; + } + if ($self->mode =~ /device::interfaces::list/) { + foreach (sort {$a->{ifDescr} cmp $b->{ifDescr}} @{$self->{interfaces}}) { + $_->list(); + } + } else { + if (scalar (@{$self->{interfaces}}) == 0) { + } else { + foreach (@{$self->{interfaces}}) { + $_->check(); + } + } + } +} + +sub dump { + my $self = shift; + foreach (@{$self->{interfaces}}) { + $_->dump(); + } +} + + +package Server::Linux::Component::InterfaceSubsystem::Interface; +our @ISA = qw(Server::Linux::Component::InterfaceSubsystem); + +use strict; +use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; + +sub new { + my $class = shift; + my %params = @_; + my $self = { + ifDescr => $params{ifDescr}, + ifSpeed => $params{ifSpeed}, + ifInOctets => $params{ifInOctets}, + ifInDiscards => $params{ifInDiscards}, + ifInErrors => $params{ifInErrors}, + ifOutOctets => $params{ifOutOctets}, + ifOutDiscards => $params{ifOutDiscards}, + ifOutErrors => $params{ifOutErrors}, + blacklisted => 0, + info => undef, + extendedinfo => undef, + }; + foreach my $key (keys %params) { + $self->{$key} = 0 if ! defined $params{$key}; + } + bless $self, $class; + $self->init(); + return $self; +} + +sub init { + my $self = shift; + if ($self->mode =~ /device::interfaces::traffic/) { + $self->valdiff({name => $self->{ifDescr}}, qw(ifInOctets ifInDiscards ifInErrors ifOutOctets ifOutDiscards ifOutErrors)); + } elsif ($self->mode =~ /device::interfaces::usage/) { + $self->valdiff({name => $self->{ifDescr}}, qw(ifInOctets ifOutOctets)); + if ($self->{ifSpeed} == 0) { + # vlan graffl + $self->{inputUtilization} = 0; + $self->{outputUtilization} = 0; + } else { + $self->{inputUtilization} = $self->{delta_ifInOctets} * 8 * 100 / + ($self->{delta_timestamp} * $self->{ifSpeed}); + $self->{outputUtilization} = $self->{delta_ifOutOctets} * 8 * 100 / + ($self->{delta_timestamp} * $self->{ifSpeed}); + } + $self->{inputRate} = $self->{delta_ifInOctets} / $self->{delta_timestamp}; + $self->{outputRate} = $self->{delta_ifOutOctets} / $self->{delta_timestamp}; + my $factor = 1/8; # default Bits + if ($self->opts->units) { + if ($self->opts->units eq "GB") { + $factor = 1024 * 1024 * 1024; + } elsif ($self->opts->units eq "MB") { + $factor = 1024 * 1024; + } elsif ($self->opts->units eq "KB") { + $factor = 1024; + } elsif ($self->opts->units eq "GBi") { + $factor = 1024 * 1024 * 1024 / 8; + } elsif ($self->opts->units eq "MBi") { + $factor = 1024 * 1024 / 8; + } elsif ($self->opts->units eq "KBi") { + $factor = 1024 / 8; + } elsif ($self->opts->units eq "B") { + $factor = 1; + } elsif ($self->opts->units eq "Bit") { + $factor = 1/8; + } + } + $self->{inputRate} /= $factor; + $self->{outputRate} /= $factor; + } elsif ($self->mode =~ /device::interfaces::errors/) { + $self->valdiff({name => $self->{ifDescr}}, qw(ifInErrors ifOutErrors ifInDiscards ifOutDiscards)); + $self->{inputErrorRate} = $self->{delta_ifInErrors} + / $self->{delta_timestamp}; + $self->{outputErrorRate} = $self->{delta_ifOutErrors} + / $self->{delta_timestamp}; + $self->{inputDiscardRate} = $self->{delta_ifInDiscards} + / $self->{delta_timestamp}; + $self->{outputDiscardRate} = $self->{delta_ifOutDiscards} + / $self->{delta_timestamp}; + $self->{inputRate} = ($self->{delta_ifInErrors} + $self->{delta_ifInDiscards}) + / $self->{delta_timestamp}; + $self->{outputRate} = ($self->{delta_ifOutErrors} + $self->{delta_ifOutDiscards}) + / $self->{delta_timestamp}; + } elsif ($self->mode =~ /device::interfaces::operstatus/) { + } + return $self; +} + +sub check { + my $self = shift; + $self->blacklist('if', $self->{ifDescr}); + if ($self->mode =~ /device::interfaces::traffic/) { + } elsif ($self->mode =~ /device::interfaces::usage/) { + my $info = sprintf 'interface %s usage is in:%.2f%% (%s) out:%.2f%% (%s)', + $self->{ifDescr}, + $self->{inputUtilization}, + sprintf("%.2f%s/s", $self->{inputRate}, + ($self->opts->units ? $self->opts->units : 'Bits')), + $self->{outputUtilization}, + sprintf("%.2f%s/s", $self->{outputRate}, + ($self->opts->units ? $self->opts->units : 'Bits')); + $self->add_info($info); + $self->set_thresholds(warning => 80, critical => 90); + my $in = $self->check_thresholds($self->{inputUtilization}); + my $out = $self->check_thresholds($self->{outputUtilization}); + my $level = ($in > $out) ? $in : ($out > $in) ? $out : $in; + $self->add_message($level, $info); + $self->add_perfdata( + label => $self->{ifDescr}.'_usage_in', + value => $self->{inputUtilization}, + uom => '%', + warning => $self->{warning}, + critical => $self->{critical}, + ); + $self->add_perfdata( + label => $self->{ifDescr}.'_usage_out', + value => $self->{outputUtilization}, + uom => '%', + warning => $self->{warning}, + critical => $self->{critical}, + ); + $self->add_perfdata( + label => $self->{ifDescr}.'_traffic_in', + value => $self->{inputRate}, + uom => $self->opts->units, + ); + $self->add_perfdata( + label => $self->{ifDescr}.'_traffic_out', + value => $self->{outputRate}, + uom => $self->opts->units, + ); + } elsif ($self->mode =~ /device::interfaces::errors/) { + my $info = sprintf 'interface %s errors in:%.2f/s out:%.2f/s '. + 'discards in:%.2f/s out:%.2f/s', + $self->{ifDescr}, + $self->{inputErrorRate} , $self->{outputErrorRate}, + $self->{inputDiscardRate} , $self->{outputDiscardRate}; + $self->add_info($info); + $self->set_thresholds(warning => 1, critical => 10); + my $in = $self->check_thresholds($self->{inputRate}); + my $out = $self->check_thresholds($self->{outputRate}); + my $level = ($in > $out) ? $in : ($out > $in) ? $out : $in; + $self->add_message($level, $info); + $self->add_perfdata( + label => $self->{ifDescr}.'_errors_in', + value => $self->{inputErrorRate}, + warning => $self->{warning}, + critical => $self->{critical}, + ); + $self->add_perfdata( + label => $self->{ifDescr}.'_errors_out', + value => $self->{outputErrorRate}, + warning => $self->{warning}, + critical => $self->{critical}, + ); + $self->add_perfdata( + label => $self->{ifDescr}.'_discards_in', + value => $self->{inputDiscardRate}, + warning => $self->{warning}, + critical => $self->{critical}, + ); + $self->add_perfdata( + label => $self->{ifDescr}.'_discards_out', + value => $self->{outputDiscardRate}, + warning => $self->{warning}, + critical => $self->{critical}, + ); + } +} + +sub list { + my $self = shift; + printf "%s\n", $self->{ifDescr}; +} + +sub dump { + my $self = shift; + printf "[IF_%s]\n", $self->{ifDescr}; + foreach (qw(ifDescr ifSpeed ifInOctets ifInDiscards ifInErrors ifOutOctets ifOutDiscards ifOutErrors)) { + printf "%s: %s\n", $_, defined $self->{$_} ? $self->{$_} : 'undefined'; + } +# printf "info: %s\n", $self->{info}; + printf "\n"; +} + diff --git a/plugins-scripts/UPNP.pm b/plugins-scripts/UPNP.pm index ffb4eb28..ffd0ebd8 100644 --- a/plugins-scripts/UPNP.pm +++ b/plugins-scripts/UPNP.pm @@ -1,68 +1,68 @@ -package UPNP; - -use strict; - -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - -our @ISA = qw(Classes::Device); - -sub init { - my $self = shift; - $self->{components} = { - interface_subsystem => undef, - }; - $self->{serial} = 'unknown'; - $self->{product} = 'unknown'; - $self->{romversion} = 'unknown'; - if (eval "require SOAP::Lite") { - require XML::LibXML; - } else { - $self->add_message(CRITICAL, - 'could not find SOAP::Lite module'); - } - if (! $self->check_messages()) { - eval { - my $igddesc = sprintf "http://%s:%s/igddesc.xml", - $self->opts->hostname, $self->opts->port; - my $parser = XML::LibXML->new(); - my $doc = $parser->parse_file($igddesc); - my $root = $doc->documentElement(); - my $xpc = XML::LibXML::XPathContext->new( $root ); - $xpc->registerNs('n', 'urn:schemas-upnp-org:device-1-0'); - $self->{productname} = $xpc->findvalue('(//n:device)[position()=1]/n:modelName' ); - }; - if ($@) { - $self->add_message(CRITICAL, $@); - } - } - if (! $self->check_messages()) { - if ($self->mode =~ /device::uptime/) { - my $som = SOAP::Lite - -> proxy(sprintf 'http://%s:%s/upnp/control/WANCommonIFC1', - $self->opts->hostname, $self->opts->port) - -> uri('urn:schemas-upnp-org:service:WANIPConnection:1') - -> GetStatusInfo(); - $self->{uptime} = $som->valueof("//GetStatusInfoResponse/NewUptime"); - $self->{uptime} /= 60; - my $info = sprintf 'device is up since %d minutes', $self->{uptime}; - $self->add_info($info); - $self->set_thresholds(warning => '15:', critical => '5:'); - $self->add_message($self->check_thresholds($self->{uptime}), $info); - $self->add_perfdata( - label => 'uptime', - value => $self->{uptime}, - warning => $self->{warning}, - critical => $self->{critical}, - ); - my ($code, $message) = $self->check_messages(join => ', ', join_all => ' , '); - $Classes::Device::plugin->nagios_exit($code, $message); - } elsif ($self->{productname} =~ /Fritz/i) { - bless $self, 'UPNP::AVM'; - $self->debug('using UPNP::AVM'); - } else { - $self->no_such_mode(); - } - $self->init(); - } -} - +package UPNP; + +use strict; + +use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; + +our @ISA = qw(Classes::Device); + +sub init { + my $self = shift; + $self->{components} = { + interface_subsystem => undef, + }; + $self->{serial} = 'unknown'; + $self->{product} = 'unknown'; + $self->{romversion} = 'unknown'; + if (eval "require SOAP::Lite") { + require XML::LibXML; + } else { + $self->add_message(CRITICAL, + 'could not find SOAP::Lite module'); + } + if (! $self->check_messages()) { + eval { + my $igddesc = sprintf "http://%s:%s/igddesc.xml", + $self->opts->hostname, $self->opts->port; + my $parser = XML::LibXML->new(); + my $doc = $parser->parse_file($igddesc); + my $root = $doc->documentElement(); + my $xpc = XML::LibXML::XPathContext->new( $root ); + $xpc->registerNs('n', 'urn:schemas-upnp-org:device-1-0'); + $self->{productname} = $xpc->findvalue('(//n:device)[position()=1]/n:modelName' ); + }; + if ($@) { + $self->add_message(CRITICAL, $@); + } + } + if (! $self->check_messages()) { + if ($self->mode =~ /device::uptime/) { + my $som = SOAP::Lite + -> proxy(sprintf 'http://%s:%s/upnp/control/WANCommonIFC1', + $self->opts->hostname, $self->opts->port) + -> uri('urn:schemas-upnp-org:service:WANIPConnection:1') + -> GetStatusInfo(); + $self->{uptime} = $som->valueof("//GetStatusInfoResponse/NewUptime"); + $self->{uptime} /= 60; + my $info = sprintf 'device is up since %d minutes', $self->{uptime}; + $self->add_info($info); + $self->set_thresholds(warning => '15:', critical => '5:'); + $self->add_message($self->check_thresholds($self->{uptime}), $info); + $self->add_perfdata( + label => 'uptime', + value => $self->{uptime}, + warning => $self->{warning}, + critical => $self->{critical}, + ); + my ($code, $message) = $self->check_messages(join => ', ', join_all => ' , '); + $Classes::Device::plugin->nagios_exit($code, $message); + } elsif ($self->{productname} =~ /Fritz/i) { + bless $self, 'UPNP::AVM'; + $self->debug('using UPNP::AVM'); + } else { + $self->no_such_mode(); + } + $self->init(); + } +} + diff --git a/plugins-scripts/UPNP/AVM.pm b/plugins-scripts/UPNP/AVM.pm index b8e12280..ddbd18e5 100644 --- a/plugins-scripts/UPNP/AVM.pm +++ b/plugins-scripts/UPNP/AVM.pm @@ -1,20 +1,20 @@ -package UPNP::AVM; - -use strict; - -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - -our @ISA = qw(UPNP); - -sub init { - my $self = shift; - $self->{components} = { - interface_subsystem => undef, - }; - if ($self->{productname} =~ /7390/) { - bless $self, 'UPNP::AVM::FritzBox7390'; - $self->debug('using UPNP::AVM::FritzBox7390'); - } - $self->init(); -} - +package UPNP::AVM; + +use strict; + +use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; + +our @ISA = qw(UPNP); + +sub init { + my $self = shift; + $self->{components} = { + interface_subsystem => undef, + }; + if ($self->{productname} =~ /7390/) { + bless $self, 'UPNP::AVM::FritzBox7390'; + $self->debug('using UPNP::AVM::FritzBox7390'); + } + $self->init(); +} + diff --git a/plugins-scripts/UPNP/AVM/FritzBox7390.pm b/plugins-scripts/UPNP/AVM/FritzBox7390.pm index 9c8f4faf..a9ac0fdc 100644 --- a/plugins-scripts/UPNP/AVM/FritzBox7390.pm +++ b/plugins-scripts/UPNP/AVM/FritzBox7390.pm @@ -1,171 +1,171 @@ -package UPNP::AVM::FritzBox7390; - -use strict; - -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - -our @ISA = qw(UPNP::AVM); - -sub init { - my $self = shift; - foreach my $module (qw(HTML::TreeBuilder LWP::UserAgent Encode Digest::MD5 JSON)) { - if (! eval "require $module") { - $self->add_message(UNKNOWN, - "could not find $module module"); - } - } - $self->{sid} = undef; - $self->{components} = { - interface_subsystem => undef, - smarthome_subsystem => undef, - }; - if (! $self->check_messages()) { - ##$self->set_serial(); - if ($self->mode =~ /device::hardware::health/) { - $self->analyze_environmental_subsystem(); - #$self->auto_blacklist(); - $self->check_environmental_subsystem(); - } elsif ($self->mode =~ /device::hardware::load/) { - $self->analyze_cpu_subsystem(); - #$self->auto_blacklist(); - $self->check_cpu_subsystem(); - } elsif ($self->mode =~ /device::hardware::memory/) { - $self->analyze_mem_subsystem(); - #$self->auto_blacklist(); - $self->check_mem_subsystem(); - } elsif ($self->mode =~ /device::interfaces/) { - $self->analyze_interface_subsystem(); - $self->check_interface_subsystem(); - } elsif ($self->mode =~ /device::smarthome/) { - $self->analyze_smarthome_subsystem(); - $self->check_smarthome_subsystem(); - } - } -} - -sub http_get { - my $self = shift; - my $page = shift; - my $ua = LWP::UserAgent->new; - if (! $self->{sid}) { - my $loginurl = sprintf "http://%s/login_sid.lua", $self->opts->hostname; - my $resp = $ua->get($loginurl); - my $content = $resp->content(); - my $challenge = ($content =~ /(.*?)<\/Challenge>/ && $1); - my $input = $challenge . '-' . $self->opts->community; - Encode::from_to($input, 'ascii', 'utf16le'); - my $challengeresponse = $challenge . '-' . lc(Digest::MD5::md5_hex($input)); - $resp = HTTP::Request->new(POST => $loginurl); - $resp->content_type("application/x-www-form-urlencoded"); - my $login = "response=$challengeresponse"; - if ($self->opts->username) { - $login .= "&username=" . $self->opts->username; - } - $resp->content($login); - my $loginresp = $ua->request($resp); - $content = $loginresp->content(); - $self->{sid} = ($content =~ /(.*?)<\/SID>/ && $1); - if (! $loginresp->is_success()) { - $self->add_message(CRITICAL, $loginresp->status_line()); - } - } - if ($page =~ /\?/) { - $page .= "&sid=$self->{sid}"; - } else { - $page .= "?sid=$self->{sid}"; - } - my $ecourl = sprintf "http://%s/%s", $self->opts->hostname, $page; - my $resp = $ua->get($ecourl); - if (! $resp->is_success()) { - $self->add_message(CRITICAL, $resp->status_line()); - } - return $resp->content(); -} - -sub analyze_smarthome_subsystem { - my $self = shift; - $self->{components}->{smarthome_subsystem} = - UPNP::AVM::FritzBox7390::Component::SmartHomeSubsystem->new(); -} - -sub analyze_interface_subsystem { - my $self = shift; - $self->{components}->{interface_subsystem} = - UPNP::AVM::FritzBox7390::Component::InterfaceSubsystem->new(); -} - -sub analyze_cpu_subsystem { - my $self = shift; - my $html = $self->http_get('system/ecostat.lua'); - my $cpu = (grep /StatCPU/, split(/\n/, $html))[0]; - my @cpu = ($cpu =~ /= "(.*?)"/ && split(/,/, $1)); - $self->{cpu_usage} = $cpu[0]; -} - -sub analyze_mem_subsystem { - my $self = shift; - my $html = $self->http_get('system/ecostat.lua'); - my $ramcacheused = (grep /StatRAMCacheUsed/, split(/\n/, $html))[0]; - my @ramcacheused = ($ramcacheused =~ /= "(.*?)"/ && split(/,/, $1)); - $self->{ram_cache_used} = $ramcacheused[0]; - my $ramphysfree = (grep /StatRAMPhysFree/, split(/\n/, $html))[0]; - my @ramphysfree = ($ramphysfree =~ /= "(.*?)"/ && split(/,/, $1)); - $self->{ram_phys_free} = $ramphysfree[0]; - my $ramstrictlyused = (grep /StatRAMStrictlyUsed/, split(/\n/, $html))[0]; - my @ramstrictlyused = ($ramstrictlyused =~ /= "(.*?)"/ && split(/,/, $1)); - $self->{ram_strictly_used} = $ramstrictlyused[0]; - $self->{ram_used} = $self->{ram_strictly_used} + $self->{ram_cache_used}; -} - -sub check_smarthome_subsystem { - my $self = shift; - $self->{components}->{smarthome_subsystem}->check(); - $self->{components}->{smarthome_subsystem}->dump() - if $self->opts->verbose >= 2; -} - -sub check_interface_subsystem { - my $self = shift; - $self->{components}->{interface_subsystem}->check(); - $self->{components}->{interface_subsystem}->dump() - if $self->opts->verbose >= 2; -} - -sub check_cpu_subsystem { - my $self = shift; - $self->add_info('checking cpus'); - $self->blacklist('c', undef); - my $info = sprintf 'cpu usage is %.2f%%', $self->{cpu_usage}; - $self->add_info($info); - $self->set_thresholds(warning => 40, critical => 60); - $self->add_message($self->check_thresholds($self->{cpu_usage}), $info); - $self->add_perfdata( - label => 'cpu_usage', - value => $self->{cpu_usage}, - uom => '%', - warning => $self->{warning}, - critical => $self->{critical}, - ); -} - -sub check_mem_subsystem { - my $self = shift; - $self->add_info('checking memory'); - $self->blacklist('m', undef); - my $info = sprintf 'memory usage is %.2f%%', $self->{ram_used}; - $self->add_info($info); - $self->set_thresholds(warning => 80, critical => 90); - $self->add_message($self->check_thresholds($self->{ram_used}), $info); - $self->add_perfdata( - label => 'memory_usage', - value => $self->{ram_used}, - uom => '%', - warning => $self->{warning}, - critical => $self->{critical}, - ); -} - - - - - +package UPNP::AVM::FritzBox7390; + +use strict; + +use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; + +our @ISA = qw(UPNP::AVM); + +sub init { + my $self = shift; + foreach my $module (qw(HTML::TreeBuilder LWP::UserAgent Encode Digest::MD5 JSON)) { + if (! eval "require $module") { + $self->add_message(UNKNOWN, + "could not find $module module"); + } + } + $self->{sid} = undef; + $self->{components} = { + interface_subsystem => undef, + smarthome_subsystem => undef, + }; + if (! $self->check_messages()) { + ##$self->set_serial(); + if ($self->mode =~ /device::hardware::health/) { + $self->analyze_environmental_subsystem(); + #$self->auto_blacklist(); + $self->check_environmental_subsystem(); + } elsif ($self->mode =~ /device::hardware::load/) { + $self->analyze_cpu_subsystem(); + #$self->auto_blacklist(); + $self->check_cpu_subsystem(); + } elsif ($self->mode =~ /device::hardware::memory/) { + $self->analyze_mem_subsystem(); + #$self->auto_blacklist(); + $self->check_mem_subsystem(); + } elsif ($self->mode =~ /device::interfaces/) { + $self->analyze_interface_subsystem(); + $self->check_interface_subsystem(); + } elsif ($self->mode =~ /device::smarthome/) { + $self->analyze_smarthome_subsystem(); + $self->check_smarthome_subsystem(); + } + } +} + +sub http_get { + my $self = shift; + my $page = shift; + my $ua = LWP::UserAgent->new; + if (! $self->{sid}) { + my $loginurl = sprintf "http://%s/login_sid.lua", $self->opts->hostname; + my $resp = $ua->get($loginurl); + my $content = $resp->content(); + my $challenge = ($content =~ /(.*?)<\/Challenge>/ && $1); + my $input = $challenge . '-' . $self->opts->community; + Encode::from_to($input, 'ascii', 'utf16le'); + my $challengeresponse = $challenge . '-' . lc(Digest::MD5::md5_hex($input)); + $resp = HTTP::Request->new(POST => $loginurl); + $resp->content_type("application/x-www-form-urlencoded"); + my $login = "response=$challengeresponse"; + if ($self->opts->username) { + $login .= "&username=" . $self->opts->username; + } + $resp->content($login); + my $loginresp = $ua->request($resp); + $content = $loginresp->content(); + $self->{sid} = ($content =~ /(.*?)<\/SID>/ && $1); + if (! $loginresp->is_success()) { + $self->add_message(CRITICAL, $loginresp->status_line()); + } + } + if ($page =~ /\?/) { + $page .= "&sid=$self->{sid}"; + } else { + $page .= "?sid=$self->{sid}"; + } + my $ecourl = sprintf "http://%s/%s", $self->opts->hostname, $page; + my $resp = $ua->get($ecourl); + if (! $resp->is_success()) { + $self->add_message(CRITICAL, $resp->status_line()); + } + return $resp->content(); +} + +sub analyze_smarthome_subsystem { + my $self = shift; + $self->{components}->{smarthome_subsystem} = + UPNP::AVM::FritzBox7390::Component::SmartHomeSubsystem->new(); +} + +sub analyze_interface_subsystem { + my $self = shift; + $self->{components}->{interface_subsystem} = + UPNP::AVM::FritzBox7390::Component::InterfaceSubsystem->new(); +} + +sub analyze_cpu_subsystem { + my $self = shift; + my $html = $self->http_get('system/ecostat.lua'); + my $cpu = (grep /StatCPU/, split(/\n/, $html))[0]; + my @cpu = ($cpu =~ /= "(.*?)"/ && split(/,/, $1)); + $self->{cpu_usage} = $cpu[0]; +} + +sub analyze_mem_subsystem { + my $self = shift; + my $html = $self->http_get('system/ecostat.lua'); + my $ramcacheused = (grep /StatRAMCacheUsed/, split(/\n/, $html))[0]; + my @ramcacheused = ($ramcacheused =~ /= "(.*?)"/ && split(/,/, $1)); + $self->{ram_cache_used} = $ramcacheused[0]; + my $ramphysfree = (grep /StatRAMPhysFree/, split(/\n/, $html))[0]; + my @ramphysfree = ($ramphysfree =~ /= "(.*?)"/ && split(/,/, $1)); + $self->{ram_phys_free} = $ramphysfree[0]; + my $ramstrictlyused = (grep /StatRAMStrictlyUsed/, split(/\n/, $html))[0]; + my @ramstrictlyused = ($ramstrictlyused =~ /= "(.*?)"/ && split(/,/, $1)); + $self->{ram_strictly_used} = $ramstrictlyused[0]; + $self->{ram_used} = $self->{ram_strictly_used} + $self->{ram_cache_used}; +} + +sub check_smarthome_subsystem { + my $self = shift; + $self->{components}->{smarthome_subsystem}->check(); + $self->{components}->{smarthome_subsystem}->dump() + if $self->opts->verbose >= 2; +} + +sub check_interface_subsystem { + my $self = shift; + $self->{components}->{interface_subsystem}->check(); + $self->{components}->{interface_subsystem}->dump() + if $self->opts->verbose >= 2; +} + +sub check_cpu_subsystem { + my $self = shift; + $self->add_info('checking cpus'); + $self->blacklist('c', undef); + my $info = sprintf 'cpu usage is %.2f%%', $self->{cpu_usage}; + $self->add_info($info); + $self->set_thresholds(warning => 40, critical => 60); + $self->add_message($self->check_thresholds($self->{cpu_usage}), $info); + $self->add_perfdata( + label => 'cpu_usage', + value => $self->{cpu_usage}, + uom => '%', + warning => $self->{warning}, + critical => $self->{critical}, + ); +} + +sub check_mem_subsystem { + my $self = shift; + $self->add_info('checking memory'); + $self->blacklist('m', undef); + my $info = sprintf 'memory usage is %.2f%%', $self->{ram_used}; + $self->add_info($info); + $self->set_thresholds(warning => 80, critical => 90); + $self->add_message($self->check_thresholds($self->{ram_used}), $info); + $self->add_perfdata( + label => 'memory_usage', + value => $self->{ram_used}, + uom => '%', + warning => $self->{warning}, + critical => $self->{critical}, + ); +} + + + + + diff --git a/plugins-scripts/UPNP/AVM/FritzBox7390/Components/InterfaceSubsystem.pm b/plugins-scripts/UPNP/AVM/FritzBox7390/Components/InterfaceSubsystem.pm index 712f1129..01f9a819 100644 --- a/plugins-scripts/UPNP/AVM/FritzBox7390/Components/InterfaceSubsystem.pm +++ b/plugins-scripts/UPNP/AVM/FritzBox7390/Components/InterfaceSubsystem.pm @@ -1,172 +1,172 @@ -package UPNP::AVM::FritzBox7390::Component::InterfaceSubsystem; -our @ISA = qw(NWC::IFMIB); - -use strict; -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - -sub new { - my $class = shift; - my %params = @_; - my $self = { - interface_cache => {}, - interfaces => [], - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; - bless $self, $class; - $self->init(%params); - return $self; -} - -sub init { - my $self = shift; - my %params = @_; - if ($self->mode =~ /device::interfaces::list/) { - $self->update_interface_cache(1); - foreach my $ifidxdescr (keys %{$self->{interface_cache}}) { - my ($ifIndex, $ifDescr) = split('#', $ifidxdescr, 2); - push(@{$self->{interfaces}}, - NWC::IFMIB::Component::InterfaceSubsystem::Interface->new( - #ifIndex => $self->{interface_cache}->{$ifDescr}, - #ifDescr => $ifDescr, - ifIndex => $ifIndex, - ifDescr => $ifDescr, - )); - } - } else { - $self->{ifDescr} = "WAN"; - $self->{ExternalIPAddress} = SOAP::Lite - -> proxy(sprintf 'http://%s:%s/upnp/control/WANCommonIFC1', - $self->opts->hostname, $self->opts->port) - -> uri('urn:schemas-upnp-org:service:WANIPConnection:1') - -> GetExternalIPAddress() - -> result; - $self->{ConnectionStatus} = SOAP::Lite - -> proxy(sprintf 'http://%s:%s/upnp/control/WANCommonIFC1', - $self->opts->hostname, $self->opts->port) - -> uri('urn:schemas-upnp-org:service:WANIPConnection:1') - -> GetStatusInfo() - -> valueof("//GetStatusInfoResponse/NewConnectionStatus");; - $self->{PhysicalLinkStatus} = SOAP::Lite - -> proxy(sprintf 'http://%s:%s/upnp/control/WANCommonIFC1', - $self->opts->hostname, $self->opts->port) - -> uri('urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1') - -> GetCommonLinkProperties() - -> valueof("//GetCommonLinkPropertiesResponse/NewPhysicalLinkStatus"); - $self->{Layer1UpstreamMaxBitRate} = SOAP::Lite - -> proxy(sprintf 'http://%s:%s/upnp/control/WANCommonIFC1', - $self->opts->hostname, $self->opts->port) - -> uri('urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1') - -> GetCommonLinkProperties() - -> valueof("//GetCommonLinkPropertiesResponse/NewLayer1UpstreamMaxBitRate"); - $self->{Layer1DownstreamMaxBitRate} = SOAP::Lite - -> proxy(sprintf 'http://%s:%s/upnp/control/WANCommonIFC1', - $self->opts->hostname, $self->opts->port) - -> uri('urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1') - -> GetCommonLinkProperties() - -> valueof("//GetCommonLinkPropertiesResponse/NewLayer1DownstreamMaxBitRate"); - $self->{TotalBytesSent} = SOAP::Lite - -> proxy(sprintf 'http://%s:%s/upnp/control/WANCommonIFC1', - $self->opts->hostname, $self->opts->port) - -> uri('urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1') - -> GetTotalBytesSent() - -> result; - $self->{TotalBytesReceived} = SOAP::Lite - -> proxy(sprintf 'http://%s:%s/upnp/control/WANCommonIFC1', - $self->opts->hostname, $self->opts->port) - -> uri('urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1') - -> GetTotalBytesReceived() - -> result; - - if ($self->mode =~ /device::interfaces::usage/) { - $self->valdiff({name => $self->{ifDescr}}, qw(TotalBytesSent TotalBytesReceived)); - $self->{inputUtilization} = $self->{delta_TotalBytesReceived} * 8 * 100 / - ($self->{delta_timestamp} * $self->{Layer1DownstreamMaxBitRate}); - $self->{outputUtilization} = $self->{delta_TotalBytesSent} * 8 * 100 / - ($self->{delta_timestamp} * $self->{Layer1UpstreamMaxBitRate}); - $self->{inputRate} = $self->{delta_TotalBytesReceived} / $self->{delta_timestamp}; - $self->{outputRate} = $self->{delta_TotalBytesSent} / $self->{delta_timestamp}; - my $factor = 1/8; # default Bits - if ($self->opts->units) { - if ($self->opts->units eq "GB") { - $factor = 1024 * 1024 * 1024; - } elsif ($self->opts->units eq "MB") { - $factor = 1024 * 1024; - } elsif ($self->opts->units eq "KB") { - $factor = 1024; - } elsif ($self->opts->units eq "GBi") { - $factor = 1024 * 1024 * 1024 / 8; - } elsif ($self->opts->units eq "MBi") { - $factor = 1024 * 1024 / 8; - } elsif ($self->opts->units eq "KBi") { - $factor = 1024 / 8; - } elsif ($self->opts->units eq "B") { - $factor = 1; - } elsif ($self->opts->units eq "Bit") { - $factor = 1/8; - } - } - $self->{inputRate} /= $factor; - $self->{outputRate} /= $factor; - $self->{Layer1DownstreamMaxKBRate} = - ($self->{Layer1DownstreamMaxBitRate} / 8) / 1024; - $self->{Layer1UpstreamMaxKBRate} = - ($self->{Layer1UpstreamMaxBitRate} / 8) / 1024; - } - } -} - -sub check { - my $self = shift; - $self->add_info('checking interfaces'); - if ($self->mode =~ /device::interfaces::usage/) { - my $info = sprintf 'interface %s usage is in:%.2f%% (%s) out:%.2f%% (%s)', - $self->{ifDescr}, - $self->{inputUtilization}, - sprintf("%.2f%s/s", $self->{inputRate}, - ($self->opts->units ? $self->opts->units : 'Bits')), - $self->{outputUtilization}, - sprintf("%.2f%s/s", $self->{outputRate}, - ($self->opts->units ? $self->opts->units : 'Bits')); - $self->add_info($info); - $self->set_thresholds(warning => 80, critical => 90); - my $in = $self->check_thresholds($self->{inputUtilization}); - my $out = $self->check_thresholds($self->{outputUtilization}); - my $level = ($in > $out) ? $in : ($out > $in) ? $out : $in; - $self->add_message($level, $info); - $self->add_perfdata( - label => $self->{ifDescr}.'_usage_in', - value => $self->{inputUtilization}, - uom => '%', - warning => $self->{warning}, - critical => $self->{critical}, - ); - $self->add_perfdata( - label => $self->{ifDescr}.'_usage_out', - value => $self->{outputUtilization}, - uom => '%', - warning => $self->{warning}, - critical => $self->{critical}, - ); - $self->add_perfdata( - label => $self->{ifDescr}.'_traffic_in', - value => $self->{inputRate}, - uom => $self->opts->units, - ); - $self->add_perfdata( - label => $self->{ifDescr}.'_traffic_out', - value => $self->{outputRate}, - uom => $self->opts->units, - ); - } -} - -sub dump { - my $self = shift; - printf "[WAN]\n"; - foreach (qw(TotalBytesSent TotalBytesReceived Layer1DownstreamMaxBitRate Layer1UpstreamMaxBitRate Layer1DownstreamMaxKBRate Layer1UpstreamMaxKBRate)) { - printf "%s: %s\n", $_, $self->{$_}; - } -} - +package UPNP::AVM::FritzBox7390::Component::InterfaceSubsystem; +our @ISA = qw(NWC::IFMIB); + +use strict; +use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; + +sub new { + my $class = shift; + my %params = @_; + my $self = { + interface_cache => {}, + interfaces => [], + blacklisted => 0, + info => undef, + extendedinfo => undef, + }; + bless $self, $class; + $self->init(%params); + return $self; +} + +sub init { + my $self = shift; + my %params = @_; + if ($self->mode =~ /device::interfaces::list/) { + $self->update_interface_cache(1); + foreach my $ifidxdescr (keys %{$self->{interface_cache}}) { + my ($ifIndex, $ifDescr) = split('#', $ifidxdescr, 2); + push(@{$self->{interfaces}}, + NWC::IFMIB::Component::InterfaceSubsystem::Interface->new( + #ifIndex => $self->{interface_cache}->{$ifDescr}, + #ifDescr => $ifDescr, + ifIndex => $ifIndex, + ifDescr => $ifDescr, + )); + } + } else { + $self->{ifDescr} = "WAN"; + $self->{ExternalIPAddress} = SOAP::Lite + -> proxy(sprintf 'http://%s:%s/upnp/control/WANCommonIFC1', + $self->opts->hostname, $self->opts->port) + -> uri('urn:schemas-upnp-org:service:WANIPConnection:1') + -> GetExternalIPAddress() + -> result; + $self->{ConnectionStatus} = SOAP::Lite + -> proxy(sprintf 'http://%s:%s/upnp/control/WANCommonIFC1', + $self->opts->hostname, $self->opts->port) + -> uri('urn:schemas-upnp-org:service:WANIPConnection:1') + -> GetStatusInfo() + -> valueof("//GetStatusInfoResponse/NewConnectionStatus");; + $self->{PhysicalLinkStatus} = SOAP::Lite + -> proxy(sprintf 'http://%s:%s/upnp/control/WANCommonIFC1', + $self->opts->hostname, $self->opts->port) + -> uri('urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1') + -> GetCommonLinkProperties() + -> valueof("//GetCommonLinkPropertiesResponse/NewPhysicalLinkStatus"); + $self->{Layer1UpstreamMaxBitRate} = SOAP::Lite + -> proxy(sprintf 'http://%s:%s/upnp/control/WANCommonIFC1', + $self->opts->hostname, $self->opts->port) + -> uri('urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1') + -> GetCommonLinkProperties() + -> valueof("//GetCommonLinkPropertiesResponse/NewLayer1UpstreamMaxBitRate"); + $self->{Layer1DownstreamMaxBitRate} = SOAP::Lite + -> proxy(sprintf 'http://%s:%s/upnp/control/WANCommonIFC1', + $self->opts->hostname, $self->opts->port) + -> uri('urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1') + -> GetCommonLinkProperties() + -> valueof("//GetCommonLinkPropertiesResponse/NewLayer1DownstreamMaxBitRate"); + $self->{TotalBytesSent} = SOAP::Lite + -> proxy(sprintf 'http://%s:%s/upnp/control/WANCommonIFC1', + $self->opts->hostname, $self->opts->port) + -> uri('urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1') + -> GetTotalBytesSent() + -> result; + $self->{TotalBytesReceived} = SOAP::Lite + -> proxy(sprintf 'http://%s:%s/upnp/control/WANCommonIFC1', + $self->opts->hostname, $self->opts->port) + -> uri('urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1') + -> GetTotalBytesReceived() + -> result; + + if ($self->mode =~ /device::interfaces::usage/) { + $self->valdiff({name => $self->{ifDescr}}, qw(TotalBytesSent TotalBytesReceived)); + $self->{inputUtilization} = $self->{delta_TotalBytesReceived} * 8 * 100 / + ($self->{delta_timestamp} * $self->{Layer1DownstreamMaxBitRate}); + $self->{outputUtilization} = $self->{delta_TotalBytesSent} * 8 * 100 / + ($self->{delta_timestamp} * $self->{Layer1UpstreamMaxBitRate}); + $self->{inputRate} = $self->{delta_TotalBytesReceived} / $self->{delta_timestamp}; + $self->{outputRate} = $self->{delta_TotalBytesSent} / $self->{delta_timestamp}; + my $factor = 1/8; # default Bits + if ($self->opts->units) { + if ($self->opts->units eq "GB") { + $factor = 1024 * 1024 * 1024; + } elsif ($self->opts->units eq "MB") { + $factor = 1024 * 1024; + } elsif ($self->opts->units eq "KB") { + $factor = 1024; + } elsif ($self->opts->units eq "GBi") { + $factor = 1024 * 1024 * 1024 / 8; + } elsif ($self->opts->units eq "MBi") { + $factor = 1024 * 1024 / 8; + } elsif ($self->opts->units eq "KBi") { + $factor = 1024 / 8; + } elsif ($self->opts->units eq "B") { + $factor = 1; + } elsif ($self->opts->units eq "Bit") { + $factor = 1/8; + } + } + $self->{inputRate} /= $factor; + $self->{outputRate} /= $factor; + $self->{Layer1DownstreamMaxKBRate} = + ($self->{Layer1DownstreamMaxBitRate} / 8) / 1024; + $self->{Layer1UpstreamMaxKBRate} = + ($self->{Layer1UpstreamMaxBitRate} / 8) / 1024; + } + } +} + +sub check { + my $self = shift; + $self->add_info('checking interfaces'); + if ($self->mode =~ /device::interfaces::usage/) { + my $info = sprintf 'interface %s usage is in:%.2f%% (%s) out:%.2f%% (%s)', + $self->{ifDescr}, + $self->{inputUtilization}, + sprintf("%.2f%s/s", $self->{inputRate}, + ($self->opts->units ? $self->opts->units : 'Bits')), + $self->{outputUtilization}, + sprintf("%.2f%s/s", $self->{outputRate}, + ($self->opts->units ? $self->opts->units : 'Bits')); + $self->add_info($info); + $self->set_thresholds(warning => 80, critical => 90); + my $in = $self->check_thresholds($self->{inputUtilization}); + my $out = $self->check_thresholds($self->{outputUtilization}); + my $level = ($in > $out) ? $in : ($out > $in) ? $out : $in; + $self->add_message($level, $info); + $self->add_perfdata( + label => $self->{ifDescr}.'_usage_in', + value => $self->{inputUtilization}, + uom => '%', + warning => $self->{warning}, + critical => $self->{critical}, + ); + $self->add_perfdata( + label => $self->{ifDescr}.'_usage_out', + value => $self->{outputUtilization}, + uom => '%', + warning => $self->{warning}, + critical => $self->{critical}, + ); + $self->add_perfdata( + label => $self->{ifDescr}.'_traffic_in', + value => $self->{inputRate}, + uom => $self->opts->units, + ); + $self->add_perfdata( + label => $self->{ifDescr}.'_traffic_out', + value => $self->{outputRate}, + uom => $self->opts->units, + ); + } +} + +sub dump { + my $self = shift; + printf "[WAN]\n"; + foreach (qw(TotalBytesSent TotalBytesReceived Layer1DownstreamMaxBitRate Layer1UpstreamMaxBitRate Layer1DownstreamMaxKBRate Layer1UpstreamMaxKBRate)) { + printf "%s: %s\n", $_, $self->{$_}; + } +} + diff --git a/plugins-scripts/UPNP/AVM/FritzBox7390/Components/SmartHomeSubsystem.pm b/plugins-scripts/UPNP/AVM/FritzBox7390/Components/SmartHomeSubsystem.pm index 06c1404c..123d6dd0 100644 --- a/plugins-scripts/UPNP/AVM/FritzBox7390/Components/SmartHomeSubsystem.pm +++ b/plugins-scripts/UPNP/AVM/FritzBox7390/Components/SmartHomeSubsystem.pm @@ -1,307 +1,307 @@ -package UPNP::AVM::FritzBox7390::Component::SmartHomeSubsystem; - -our @ISA = qw(UPNP::AVM::FritzBox7390); - -use strict; -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - -sub new { - my $class = shift; - my %params = @_; - my $self = { - blacklisted => 0, - info => undef, - extendedinfo => undef, - smart_home_devices => [], - }; - bless $self, $class; - $self->init(%params); - return $self; -} - -sub init { - my $self = shift; - if ($self->mode =~ /smarthome::device::list/) { - $self->update_device_cache(1); - foreach my $id (keys %{$self->{device_cache}}) { - my $name = $self->{device_cache}->{$id}->{name}; - printf "%02d %s\n", $id, $name; - } - } elsif ($self->mode =~ /smarthome::device/) { - $self->update_device_cache(0); - my @indices = $self->get_device_indices(); - foreach my $id (map {$_->[0]} @indices) { - my %tmp_dev = (id => $id, name => $self->{device_cache}->{$id}->{name}); - push(@{$self->{smart_home_devices}}, - UPNP::AVM::FritzBox7390::Component::SmartHomeSubsystem::Device->new(%tmp_dev)); - } - } -} - -sub check { - my $self = shift; - foreach (@{$self->{smart_home_devices}}) { - $_->check(); - } -} - -sub create_device_cache_file { - my $self = shift; - my $extension = ""; - if ($self->opts->community) { - $extension .= Digest::MD5::md5_hex($self->opts->community); - } - $extension =~ s/\//_/g; - $extension =~ s/\(/_/g; - $extension =~ s/\)/_/g; - $extension =~ s/\*/_/g; - $extension =~ s/\s/_/g; - return sprintf "%s/%s_interface_cache_%s", $NWC::Device::statefilesdir, - $self->opts->hostname, lc $extension; -} - -sub update_device_cache { - my $self = shift; - my $force = shift; - my $statefile = $self->create_device_cache_file(); - my $update = time - 3600; - if ($force || ! -f $statefile || ((stat $statefile)[9]) < ($update)) { - $self->debug('force update of device cache'); - $self->{device_cache} = {}; - my $html = $self->http_get('/net/home_auto_overview.lua'); - my $tree = HTML::TreeBuilder->new_from_content(Encode::decode_utf8($html)); - my $table = $tree->look_down(_tag => 'table', id => 'tHAdevices'); - my @rows = @{$table->content()}; - foreach my $row (@rows[1..$#rows]) { - # skip the tr/th - my %tmp_device = (); - foreach (map {$_->as_HTML()} @{$row->content()}) { - if (/class="c1".*img id=".*?(\d+)".*title="(.*?)"/) { - $tmp_device{id} = $1; - } elsif (/class="c2".*title="(.*?)"/) { - $tmp_device{name} = $1; - } - } - $self->{device_cache}->{$tmp_device{id}}->{name} = $tmp_device{name}; - } - $self->save_device_cache(); - } - $self->load_device_cache(); -} - -sub save_device_cache { - my $self = shift; - $self->create_statefilesdir(); - my $statefile = $self->create_device_cache_file(); - my $tmpfile = $NWC::Device::statefilesdir.'/check_nwc_health_tmp_'.$$; - my $fh = IO::File->new(); - $fh->open(">$tmpfile"); - $fh->print(Data::Dumper::Dumper($self->{device_cache})); - $fh->flush(); - $fh->close(); - my $ren = rename $tmpfile, $statefile; - $self->debug(sprintf "saved %s to %s", - Data::Dumper::Dumper($self->{device_cache}), $statefile); - -} - -sub load_device_cache { - my $self = shift; - my $statefile = $self->create_device_cache_file(); - if ( -f $statefile) { - our $VAR1; - eval { - require $statefile; - }; - if($@) { - printf "rumms\n"; - } - $self->debug(sprintf "load %s", Data::Dumper::Dumper($VAR1)); - $self->{device_cache} = $VAR1; - eval { - foreach (keys %{$self->{device_cache}}) { - /^\d+$/ || die "newrelease"; - } - }; - if($@) { - $self->{device_cache} = {}; - unlink $statefile; - delete $INC{$statefile}; - $self->update_device_cache(1); - } - } -} - -sub get_device_indices { - my $self = shift; - my @indices = (); - foreach my $id (keys %{$self->{device_cache}}) { - my $name = $self->{device_cache}->{$id}->{name}; - if ($self->opts->name) { - if ($self->opts->regexp) { - my $pattern = $self->opts->name; - if ($name =~ /$pattern/i) { - push(@indices, [$id]); - } - } else { - if ($self->opts->name =~ /^\d+$/) { - if ($id == 1 * $self->opts->name) { - push(@indices, [1 * $self->opts->name]); - } - } else { - if (lc $name eq lc $self->opts->name) { - push(@indices, [$id]); - } - } - } - } else { - push(@indices, [$id]); - } - } - return @indices; -} - - -package UPNP::AVM::FritzBox7390::Component::SmartHomeSubsystem::Device; - -our @ISA = qw(UPNP::AVM::FritzBox7390::Component::SmartHomeSubsystem); - -use strict; -use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; - -sub new { - my $class = shift; - my %params = @_; - my $self = { - blacklisted => 0, - info => undef, - extendedinfo => undef, - }; - foreach my $param (qw(id model switched connected ain name)) { - $self->{$param} = $params{$param}; - } - bless $self, $class; - $self->init(%params); - return $self; -} - -sub init { - my $self = shift; - if ($self->mode =~ /smarthome::device::status/) { - my $device = $self->http_get( - sprintf '/net/home_auto_energy_view.lua?device=%d&sub_tab=10', $self->{id}); - $device =~ /Modell<.*?>(.*?)<\/nobr>/; $self->{model} = $1; - $device =~ /\(AIN\)<.*?>(.*?)<\/nobr>/; $self->{ain} = $1; - $device =~ /Name<.*?>(.*?)<\/nobr>/; $self->{name} = $1; - $device =~ /{connected} = $1 eq "green" ? 1 : 0; - $device =~ /{switched} = $1 eq "green" ? 1 : 0; - } elsif ($self->mode =~ /smarthome::device::energy/) { - my $json = JSON->new->allow_nonref; - my $html = $self->http_get( - sprintf '/net/home_auto_query.lua?id=%d&command=OutletStates', $self->{id}); - my $energy = $self->http_get( - sprintf '/net/home_auto_query.lua?id=%d&command=EnergyStats_10&xhr=1&t%d=nocache', $self->{id}, time); - $energy = $json->decode($energy); - my @watts = map { /value_(\d+)/; [$1, $energy->{$_}] } grep /watt_value/, keys %{$energy}; @watts = ([0, 0]) if $#watts == -1; - $self->{last_watt} = (map { $_->[1] / 100; } sort { $a->[0] <=> $b->[0] } @watts)[0]; - my @volts = map { /value_(\d+)/; [$1, $energy->{$_}] } grep /volt_value/, keys %{$energy}; @volts = ([0, 0]) if $#volts == -1; - $self->{last_volt} = (map { $_->[1] / 1000; } sort { $a->[0] <=> $b->[0] } @volts)[0]; - $self->{max_watt} = $energy->{EnStats_max_value} / 100; - $self->{min_watt} = $energy->{EnStats_min_value} / 100; - } elsif ($self->mode =~ /smarthome::device::consumption/) { - my $html = $self->http_get( - sprintf '/net/home_auto_energy_view.lua?device=%d&sub_tab=10', $self->{id}); - my $tree = HTML::TreeBuilder->new_from_content(Encode::decode_utf8($html)); - my $table = $tree->look_down(_tag => 'table', id => 'tHAconsumption'); - my @rows = @{$table->content()}; - foreach (map {$_->as_HTML();} @rows[1..$#rows]) { - if (/Pro Tag.*?>([\d,]+)<.*?>([\d,]+)<.*?>([\d,]+){d}->{euro} = $1; - $self->{d}->{kwh} = $2; - $self->{d}->{kgco2} = $3; - } elsif (/Pro Monat.*?>([\d,]+)<.*?>([\d,]+)<.*?>([\d,]+){m}->{euro} = $1; - $self->{m}->{kwh} = $2; - $self->{m}->{kgco2} = $3; - } elsif (/Pro Jahr.*?>([\d,]+)<.*?>([\d,]+)<.*?>([\d,]+){y}->{euro} = $1; - $self->{y}->{kwh} = $2; - $self->{y}->{kgco2} = $3; - } - } - foreach my $t (qw(d m y)) { - foreach my $u (qw(kwh euro kgco2)) { - $self->{$t}->{$u} =~ s/,/./g; - } - } - } -} - -sub check { - my $self = shift; - if ($self->mode =~ /smarthome::device::status/) { - my $info = sprintf "device %s is %sconnected and switched %s", - $self->{name}, $self->{connected} ? "" : "not ", $self->{switched} ? "on" : "off"; - $self->add_info($info); - if (! $self->{connected} || ! $self->{switched}) { - $self->add_message(CRITICAL, $info); - } else { - $self->add_message(OK, sprintf "device %s ok", $self->{name}); - } - } elsif ($self->mode =~ /smarthome::device::energy/) { - my $info = sprintf "device %s consumes %.2f watts at %.2f volts", - $self->{name}, $self->{last_watt}, $self->{last_volt}; - $self->add_info($info); - $self->set_thresholds( - warning => 80 / 100 * 220 * 10, - critical => 90 / 100 * 220 * 10); - $self->add_message($self->check_thresholds($self->{last_watt}), $info); - $self->add_perfdata( - label => 'watt', - value => $self->{last_watt}, - warning => $self->{warning}, - critical => $self->{critical}, - ); - $self->add_perfdata( - label => 'watt_min', - value => $self->{min_watt}, - ); - $self->add_perfdata( - label => 'watt_max', - value => $self->{max_watt}, - ); - $self->add_perfdata( - label => 'volt', - value => $self->{last_volt}, - ); - } elsif ($self->mode =~ /smarthome::device::consumption/) { - my $i = 'kwh'; - my $info = ''; - $self->set_thresholds(warning => 1000, critical => 1000); - if (! $self->opts->units || $self->opts->units eq 'kwh') { - $i = 'kwh'; - $info = sprintf '%s consumes %.2f kwh per day', $self->{name}, $self->{d}->{kwh}; - } elsif ($self->opts->units eq 'euro') { - $i = 'euro'; - $info = sprintf '%s costs %.2f euro per day', $self->{name}, $self->{d}->{euro}; - } elsif ($self->opts->units eq 'kgco2') { - $i = 'kgco2'; - $info = sprintf '%s produces %.2f kg co2 per day', $self->{name}, $self->{d}->{kgco2}; - } - $self->add_message($self->check_thresholds($self->{m}->{$i}), $info); - foreach (qw(day)) { - $self->add_perfdata( - label => $i.'_'.$_, - value => $self->{substr($_,0,1)}->{$i}, - warning => $self->{warning}, - critical => $self->{critical}, - ); - } - foreach (qw(month year)) { - $self->add_perfdata( - label => $i.'_'.$_, - value => $self->{substr($_,0,1)}->{$i}, - ); - } - } -} +package UPNP::AVM::FritzBox7390::Component::SmartHomeSubsystem; + +our @ISA = qw(UPNP::AVM::FritzBox7390); + +use strict; +use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; + +sub new { + my $class = shift; + my %params = @_; + my $self = { + blacklisted => 0, + info => undef, + extendedinfo => undef, + smart_home_devices => [], + }; + bless $self, $class; + $self->init(%params); + return $self; +} + +sub init { + my $self = shift; + if ($self->mode =~ /smarthome::device::list/) { + $self->update_device_cache(1); + foreach my $id (keys %{$self->{device_cache}}) { + my $name = $self->{device_cache}->{$id}->{name}; + printf "%02d %s\n", $id, $name; + } + } elsif ($self->mode =~ /smarthome::device/) { + $self->update_device_cache(0); + my @indices = $self->get_device_indices(); + foreach my $id (map {$_->[0]} @indices) { + my %tmp_dev = (id => $id, name => $self->{device_cache}->{$id}->{name}); + push(@{$self->{smart_home_devices}}, + UPNP::AVM::FritzBox7390::Component::SmartHomeSubsystem::Device->new(%tmp_dev)); + } + } +} + +sub check { + my $self = shift; + foreach (@{$self->{smart_home_devices}}) { + $_->check(); + } +} + +sub create_device_cache_file { + my $self = shift; + my $extension = ""; + if ($self->opts->community) { + $extension .= Digest::MD5::md5_hex($self->opts->community); + } + $extension =~ s/\//_/g; + $extension =~ s/\(/_/g; + $extension =~ s/\)/_/g; + $extension =~ s/\*/_/g; + $extension =~ s/\s/_/g; + return sprintf "%s/%s_interface_cache_%s", $NWC::Device::statefilesdir, + $self->opts->hostname, lc $extension; +} + +sub update_device_cache { + my $self = shift; + my $force = shift; + my $statefile = $self->create_device_cache_file(); + my $update = time - 3600; + if ($force || ! -f $statefile || ((stat $statefile)[9]) < ($update)) { + $self->debug('force update of device cache'); + $self->{device_cache} = {}; + my $html = $self->http_get('/net/home_auto_overview.lua'); + my $tree = HTML::TreeBuilder->new_from_content(Encode::decode_utf8($html)); + my $table = $tree->look_down(_tag => 'table', id => 'tHAdevices'); + my @rows = @{$table->content()}; + foreach my $row (@rows[1..$#rows]) { + # skip the tr/th + my %tmp_device = (); + foreach (map {$_->as_HTML()} @{$row->content()}) { + if (/class="c1".*img id=".*?(\d+)".*title="(.*?)"/) { + $tmp_device{id} = $1; + } elsif (/class="c2".*title="(.*?)"/) { + $tmp_device{name} = $1; + } + } + $self->{device_cache}->{$tmp_device{id}}->{name} = $tmp_device{name}; + } + $self->save_device_cache(); + } + $self->load_device_cache(); +} + +sub save_device_cache { + my $self = shift; + $self->create_statefilesdir(); + my $statefile = $self->create_device_cache_file(); + my $tmpfile = $NWC::Device::statefilesdir.'/check_nwc_health_tmp_'.$$; + my $fh = IO::File->new(); + $fh->open(">$tmpfile"); + $fh->print(Data::Dumper::Dumper($self->{device_cache})); + $fh->flush(); + $fh->close(); + my $ren = rename $tmpfile, $statefile; + $self->debug(sprintf "saved %s to %s", + Data::Dumper::Dumper($self->{device_cache}), $statefile); + +} + +sub load_device_cache { + my $self = shift; + my $statefile = $self->create_device_cache_file(); + if ( -f $statefile) { + our $VAR1; + eval { + require $statefile; + }; + if($@) { + printf "rumms\n"; + } + $self->debug(sprintf "load %s", Data::Dumper::Dumper($VAR1)); + $self->{device_cache} = $VAR1; + eval { + foreach (keys %{$self->{device_cache}}) { + /^\d+$/ || die "newrelease"; + } + }; + if($@) { + $self->{device_cache} = {}; + unlink $statefile; + delete $INC{$statefile}; + $self->update_device_cache(1); + } + } +} + +sub get_device_indices { + my $self = shift; + my @indices = (); + foreach my $id (keys %{$self->{device_cache}}) { + my $name = $self->{device_cache}->{$id}->{name}; + if ($self->opts->name) { + if ($self->opts->regexp) { + my $pattern = $self->opts->name; + if ($name =~ /$pattern/i) { + push(@indices, [$id]); + } + } else { + if ($self->opts->name =~ /^\d+$/) { + if ($id == 1 * $self->opts->name) { + push(@indices, [1 * $self->opts->name]); + } + } else { + if (lc $name eq lc $self->opts->name) { + push(@indices, [$id]); + } + } + } + } else { + push(@indices, [$id]); + } + } + return @indices; +} + + +package UPNP::AVM::FritzBox7390::Component::SmartHomeSubsystem::Device; + +our @ISA = qw(UPNP::AVM::FritzBox7390::Component::SmartHomeSubsystem); + +use strict; +use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; + +sub new { + my $class = shift; + my %params = @_; + my $self = { + blacklisted => 0, + info => undef, + extendedinfo => undef, + }; + foreach my $param (qw(id model switched connected ain name)) { + $self->{$param} = $params{$param}; + } + bless $self, $class; + $self->init(%params); + return $self; +} + +sub init { + my $self = shift; + if ($self->mode =~ /smarthome::device::status/) { + my $device = $self->http_get( + sprintf '/net/home_auto_energy_view.lua?device=%d&sub_tab=10', $self->{id}); + $device =~ /Modell<.*?>(.*?)<\/nobr>/; $self->{model} = $1; + $device =~ /\(AIN\)<.*?>(.*?)<\/nobr>/; $self->{ain} = $1; + $device =~ /Name<.*?>(.*?)<\/nobr>/; $self->{name} = $1; + $device =~ /{connected} = $1 eq "green" ? 1 : 0; + $device =~ /{switched} = $1 eq "green" ? 1 : 0; + } elsif ($self->mode =~ /smarthome::device::energy/) { + my $json = JSON->new->allow_nonref; + my $html = $self->http_get( + sprintf '/net/home_auto_query.lua?id=%d&command=OutletStates', $self->{id}); + my $energy = $self->http_get( + sprintf '/net/home_auto_query.lua?id=%d&command=EnergyStats_10&xhr=1&t%d=nocache', $self->{id}, time); + $energy = $json->decode($energy); + my @watts = map { /value_(\d+)/; [$1, $energy->{$_}] } grep /watt_value/, keys %{$energy}; @watts = ([0, 0]) if $#watts == -1; + $self->{last_watt} = (map { $_->[1] / 100; } sort { $a->[0] <=> $b->[0] } @watts)[0]; + my @volts = map { /value_(\d+)/; [$1, $energy->{$_}] } grep /volt_value/, keys %{$energy}; @volts = ([0, 0]) if $#volts == -1; + $self->{last_volt} = (map { $_->[1] / 1000; } sort { $a->[0] <=> $b->[0] } @volts)[0]; + $self->{max_watt} = $energy->{EnStats_max_value} / 100; + $self->{min_watt} = $energy->{EnStats_min_value} / 100; + } elsif ($self->mode =~ /smarthome::device::consumption/) { + my $html = $self->http_get( + sprintf '/net/home_auto_energy_view.lua?device=%d&sub_tab=10', $self->{id}); + my $tree = HTML::TreeBuilder->new_from_content(Encode::decode_utf8($html)); + my $table = $tree->look_down(_tag => 'table', id => 'tHAconsumption'); + my @rows = @{$table->content()}; + foreach (map {$_->as_HTML();} @rows[1..$#rows]) { + if (/Pro Tag.*?>([\d,]+)<.*?>([\d,]+)<.*?>([\d,]+){d}->{euro} = $1; + $self->{d}->{kwh} = $2; + $self->{d}->{kgco2} = $3; + } elsif (/Pro Monat.*?>([\d,]+)<.*?>([\d,]+)<.*?>([\d,]+){m}->{euro} = $1; + $self->{m}->{kwh} = $2; + $self->{m}->{kgco2} = $3; + } elsif (/Pro Jahr.*?>([\d,]+)<.*?>([\d,]+)<.*?>([\d,]+){y}->{euro} = $1; + $self->{y}->{kwh} = $2; + $self->{y}->{kgco2} = $3; + } + } + foreach my $t (qw(d m y)) { + foreach my $u (qw(kwh euro kgco2)) { + $self->{$t}->{$u} =~ s/,/./g; + } + } + } +} + +sub check { + my $self = shift; + if ($self->mode =~ /smarthome::device::status/) { + my $info = sprintf "device %s is %sconnected and switched %s", + $self->{name}, $self->{connected} ? "" : "not ", $self->{switched} ? "on" : "off"; + $self->add_info($info); + if (! $self->{connected} || ! $self->{switched}) { + $self->add_message(CRITICAL, $info); + } else { + $self->add_message(OK, sprintf "device %s ok", $self->{name}); + } + } elsif ($self->mode =~ /smarthome::device::energy/) { + my $info = sprintf "device %s consumes %.2f watts at %.2f volts", + $self->{name}, $self->{last_watt}, $self->{last_volt}; + $self->add_info($info); + $self->set_thresholds( + warning => 80 / 100 * 220 * 10, + critical => 90 / 100 * 220 * 10); + $self->add_message($self->check_thresholds($self->{last_watt}), $info); + $self->add_perfdata( + label => 'watt', + value => $self->{last_watt}, + warning => $self->{warning}, + critical => $self->{critical}, + ); + $self->add_perfdata( + label => 'watt_min', + value => $self->{min_watt}, + ); + $self->add_perfdata( + label => 'watt_max', + value => $self->{max_watt}, + ); + $self->add_perfdata( + label => 'volt', + value => $self->{last_volt}, + ); + } elsif ($self->mode =~ /smarthome::device::consumption/) { + my $i = 'kwh'; + my $info = ''; + $self->set_thresholds(warning => 1000, critical => 1000); + if (! $self->opts->units || $self->opts->units eq 'kwh') { + $i = 'kwh'; + $info = sprintf '%s consumes %.2f kwh per day', $self->{name}, $self->{d}->{kwh}; + } elsif ($self->opts->units eq 'euro') { + $i = 'euro'; + $info = sprintf '%s costs %.2f euro per day', $self->{name}, $self->{d}->{euro}; + } elsif ($self->opts->units eq 'kgco2') { + $i = 'kgco2'; + $info = sprintf '%s produces %.2f kg co2 per day', $self->{name}, $self->{d}->{kgco2}; + } + $self->add_message($self->check_thresholds($self->{m}->{$i}), $info); + foreach (qw(day)) { + $self->add_perfdata( + label => $i.'_'.$_, + value => $self->{substr($_,0,1)}->{$i}, + warning => $self->{warning}, + critical => $self->{critical}, + ); + } + foreach (qw(month year)) { + $self->add_perfdata( + label => $i.'_'.$_, + value => $self->{substr($_,0,1)}->{$i}, + ); + } + } +} diff --git a/plugins-scripts/check_nwc_health.pl b/plugins-scripts/check_nwc_health.pl index a536f6dc..6490f789 100644 --- a/plugins-scripts/check_nwc_health.pl +++ b/plugins-scripts/check_nwc_health.pl @@ -2,7 +2,6 @@ use strict; use Digest::MD5 qw(md5_hex); -use Devel::TraceMethods; use vars qw ($PROGNAME $REVISION $CONTACT $TIMEOUT $STATEFILESDIR $needs_restart %commandline);