├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── check_tr64_fritz ├── devel └── fetch_tr64_data.sh ├── doc ├── 01-smarthome.md ├── github_doc_fritzbox_services.png └── images │ └── image_fritzbox_smarthome_index.png └── getSecurityPort /.gitignore: -------------------------------------------------------------------------------- 1 | .ideas/ 2 | .devel/ 3 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [2.3](https://github.com/mcktr/check_tr64_fritz/releases/tag/v2.3) (2018-01-15) 4 | 5 | ### Enhancements: 6 | 7 | - None 8 | 9 | ### Fixed bugs: 10 | 11 | - Fix default function [#54](https://github.com/mcktr/check_tr64_fritz/pull/54) 12 | - Fix wrong attribute usage in update function [#52](https://github.com/mcktr/check_tr64_fritz/pull/52) 13 | - Improve error handling for thermometer function [#56](https://github.com/mcktr/check_tr64_fritz/pull/56) 14 | 15 | ### Support: 16 | 17 | - Fix uppercase letters to normal letters in documentation [#57](https://github.com/mcktr/check_tr64_fritz/pull/57) 18 | 19 | ## [2.2](https://github.com/mcktr/check_tr64_fritz/releases/tag/v2.2) (2017-11-29) 20 | 21 | ### Enhancements: 22 | 23 | - Added documentation for enable the TR-064 feature [#33](https://github.com/mcktr/check_tr64_fritz/pull/33) 24 | - Implement check function for FritzBox smart home thermometers [#29](https://github.com/mcktr/check_tr64_fritz/pull/29) 25 | - Make warning/critical values adjustable for down-/upstreamrate [#42](https://github.com/mcktr/check_tr64_fritz/pull/42) 26 | 27 | ### Fixed bugs: 28 | 29 | - Remove expected argument for debug parameter [#27](https://github.com/mcktr/check_tr64_fritz/pull/27) 30 | - Fix downstream/upstream function warning/critical calculation [#39](https://github.com/mcktr/check_tr64_fritz/pull/39) 31 | - Fix status/linkuptime functions for FritzBox cable [#44](https://github.com/mcktr/check_tr64_fritz/pull/44) 32 | 33 | ### Support: 34 | 35 | - Enhance documentation [#35](https://github.com/mcktr/check_tr64_fritz/pull/35) 36 | - Add .gitignore file [#37](https://github.com/mcktr/check_tr64_fritz/pull/37) 37 | - Remove icingaexchange.yml [#45](https://github.com/mcktr/check_tr64_fritz/pull/45) 38 | - Add development documentation [#36](https://github.com/mcktr/check_tr64_fritz/pull/36) 39 | - Update the contributors [#46](https://github.com/mcktr/check_tr64_fritz/pull/46) 40 | 41 | ## [2.1](https://github.com/mcktr/check_tr64_fritz/releases/tag/v2.1) (2017-10-18) 42 | 43 | ### Enhancements: 44 | 45 | - Added Icinga 2 CheckCommand definition [#17](https://github.com/mcktr/check_tr64_fritz/pull/17) 46 | - Added warning/critical values to performance data output [#20](https://github.com/mcktr/check_tr64_fritz/pull/20) 47 | - Added dedicated version/usage parameter [#19](https://github.com/mcktr/check_tr64_fritz/pull/19) 48 | - Added Changelog [#18](https://github.com/mcktr/check_tr64_fritz/pull/18) 49 | 50 | ### Fixed bugs: 51 | 52 | - Malformed performance data output [#21](https://github.com/mcktr/check_tr64_fritz/pull/21) 53 | - Split vars uptime/linkuptime [#23](https://github.com/mcktr/check_tr64_fritz/pull/23) 54 | 55 | ## [2.0](https://github.com/mcktr/check_tr64_fritz/releases/tag/v2.0) (2017-07-01) 56 | 57 | ### Enhancements: 58 | 59 | - Added performance data output [#5](https://github.com/mcktr/check_tr64_fritz/pull/5) 60 | - Improved README [#9](https://github.com/mcktr/check_tr64_fritz/pull/9) 61 | 62 | ### Fixed bugs: 63 | 64 | - None 65 | 66 | ## [1.0](https://github.com/mcktr/check_tr64_fritz/releases/tag/v1.0) (2017-04-03) 67 | 68 | ### Enhancements: 69 | 70 | - Initial release 71 | - Basic check functions for Fritz!Box 72 | 73 | ### Fixed bugs: 74 | 75 | - None 76 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | > **Note:** 2 | > 3 | > This check plugin is no longer actively maintained. 4 | > For the motives and alternatives please read the following comment: 5 | > https://github.com/mcktr/check_tr64_fritz/issues/80 6 | 7 | # check_tr64_fritz 8 | 9 | #### Table of Contents 10 | 11 | 1. [Introduction](#introduction) 12 | 2. [Support](#support) 13 | 3. [Requirements](#requirements) 14 | 4. [Usage](#usage) 15 | 5. [CheckCommand](#checkcommand) 16 | 6. [Security](#security) 17 | 7. [Contributors](#contributors) 18 | 8. [Thanks](#thanks) 19 | 9. [Development](#development) 20 | 21 | ## Introduction 22 | 23 | This is a check plugin for Icinga 2 to monitor a Fritz!Box. 24 | 25 | ## Support 26 | 27 | If you have any questions, please hop onto the community channels. 28 | 29 | ## Requirements 30 | 31 | __Required packages__ 32 | 33 | The following packages are required to use this check plugin. 34 | 35 | - `curl` 36 | - `bc` 37 | 38 | Please use your favorite package manager to install them. 39 | 40 | __Fritz!Box configuration__ 41 | 42 | The TR-064 feature must be enabled on the Fritz!Box. You can enable the feature in the following menu: 43 | 44 | _Heimnetz_ -> _Netzwerk_, switch over to the tab _Netzwerkeinstellungen_ 45 | 46 | The setting _Zugriff für Anwendungen zulassen_ must be activated. After a restart of your Fritz!Box the 47 | TR-064 feature is activated. 48 | 49 | > **Note**: 50 | > 51 | > You may need to activate the advanced view (_Erweiterte Ansicht_) to see the setting. 52 | 53 | ## Installation 54 | 55 | 1. Get the [latest stable release](https://github.com/mcktr/check_tr64_fritz/releases) 56 | 2. Extract the archive 57 | 3. Execute the `getSecurityPort` script, to find your TR-064 SSL port 58 | 4. Copy the `check_tr64_fritz` script to your Icinga 2 check plugin directory 59 | 5. Add the CheckCommand definition to your Icinga 2 configuration. 60 | 6. Create a new service in Icinga 2 for your Fritz!Box 61 | 62 | You can find additional information on how to setup check plugins for Icinga 2 in the offical [Icinga 2 documentation](https://www.icinga.com/docs/icinga2/latest/doc/05-service-monitoring/#service-monitoring-plugins) 63 | 64 | ## Usage 65 | 66 | __getSecurityPort__ 67 | 68 | ``` 69 | getSecurityPort 70 | ``` 71 | 72 | | Name | Description | 73 | | --- | --- | 74 | | HOST | Hostname or IP address of your Fritz!Box. | 75 | 76 | _Example:_ 77 | 78 | ``` 79 | $ ./getSecurityPort 192.168.178.1 80 | Your Fritz!Box Security Port (for TR-064 over SSL) is: 49443 81 | ``` 82 | 83 | __check_tr64_fritz__ 84 | 85 | ``` 86 | check_tr64_fritz -h -p -u -P -f -w -c 87 | ``` 88 | 89 | __Arguments__ 90 | 91 | | Name | Description | 92 | | --- | --- | 93 | | -h | **Optional.** Hostname or IP address of your Fritz!Box. _Defaults to "fritz.box"._ | 94 | | -p | **Optional.** The port number for TR-064 over SSL. _Defaults to "49443"._ | 95 | | -u | **Optional.** Username to authenticate against the Fritz!Box. _Defaults to "dslf-config"._ | 96 | | -P | **Required.** Password to authenticate against the Fritz!Box. | 97 | | -f | **Optional.** Function that should be checked. _Defaults to "status"._ | 98 | | -w | **Optional.** Warning threshold. _Defaults to "0"._ | 99 | | -c | **Optional.** Critical threshold. _Defaults to "0"._ | 100 | | -v | **Optional.** Print current plugin version and usage text. | 101 | | -d | **Optional.** Print debug information (TR-064 XML output). | 102 | 103 | > **Note**: 104 | > 105 | > The username and password are the same as for the web interface of your 106 | > Fritz!Box. If you don't use the login method with username and password, you 107 | > can leave the username empty. 108 | 109 | __Functions__ 110 | 111 | | Name | Description | 112 | | --- | --- | 113 | | status | **Optional Index.** Returns the connection state. _Default Index to "pppoe"._ | 114 | | linkuptime | **Optional Index.** Returns the uptime of the WAN link. _Default Index to "pppoe"._ | 115 | | uptime | Returns the device uptime. | 116 | | downstream | Returns the usable downstream rate in MBit/s. | 117 | | upstream | Returns the usable upstream rate in MBit/s. | 118 | | downstreamrate | Returns the current downstream speed in MBit/s. | 119 | | upstreamrate | Returns the current upstream speed in MBits/s. | 120 | | update | Returns the update state. | 121 | | thermometer | **Requires Index.** Returns the connection status and temperature of a smart home thermometer device. | 122 | | socketpower | **Requires Index.** Returns the connection status and current power usage in watts of a smart home socket device. | 123 | | socketenergy | **Requires Index.** Returns the connection status and total consumption over the last year in kWh of a smart home socket device. | 124 | | socketswitch | **Requires Index.** Returns the connection status and the current switch state. Setting the thresholds to 1 or greater will threat the `OFF` state as critical. | 125 | 126 | __Indexes__ 127 | 128 | | Function | Index | Description | 129 | | --- | --- | --- | 130 | | status | `cable`, `pppoe` | Check the specified connection type. | 131 | | linkuptime | `cable`, `pppoe` | Check the specified connection type. | 132 | | thermometer | `[NUMBER]` | Check the specified DECT thermometer. | 133 | | socketpower | `[NUMBER]` | Check the specified DECT socket. | 134 | | socketenergy | `[NUMBER]` | Check the specified DECT socket. | 135 | | socketswitch | `[NUMBER]` | Check the specified DECT socket. | 136 | > **Note**: 137 | > 138 | > You can specify the index with a double point and the index number after the function name e.g. `thermometer:3`. 139 | 140 | _Example:_ 141 | 142 | ``` 143 | $ ./check_tr64_fritz -P password -f uptime 144 | OK - Uptime 29990 seconds (0d 8h 19m 50s) | uptime=2999 145 | 146 | $ ./check_tr64_fritz -P password -f status:cable 147 | WARNING - Connecting | status=1 148 | 149 | $ ./check_tr64_fritz -P password -f thermometer:3 150 | OK - Comet DECT 03.68 - Wohnzimmer CONNECTED 21.5 °C | thermometer_current_state=0 thermometer_current_temp=21.5 warn=0 crit=0 151 | ``` 152 | 153 | > **Note**: 154 | > 155 | > Please also read the seperate documentation about the [Smart Home index](doc/01-smarthome.md) 156 | 157 | ## CheckCommand 158 | 159 | You can use the following CheckCommand definition for your Icinga 2 160 | configuration. 161 | 162 | ``` 163 | object CheckCommand "check_tr64_fritz" { 164 | command = [ PluginDir + "/check_tr64_fritz" ] 165 | 166 | arguments = { 167 | "-h" = "$fritz_host$" 168 | "-p" = "$fritz_port$" 169 | "-u" = "$fritz_username$" 170 | "-P" = "$fritz_password$" 171 | "-f" = "$fritz_function$" 172 | "-w" = "$fritz_warning$" 173 | "-c" = "$fritz_critical$" 174 | } 175 | 176 | vars.fritz_host = "$address$" 177 | vars.fritz_port = "49443" 178 | vars.fritz_username = "dslf-config" 179 | vars.fritz_function = "status" 180 | } 181 | ``` 182 | 183 | You can find more information about a CheckCommand definition inside the [offical 184 | Icinga 2 documentation](https://www.icinga.com/docs/icinga2/latest/doc/09-object-types/#checkcommand). 185 | 186 | ## Security 187 | 188 | __Authentication__ 189 | 190 | You can use an independently account for the authentication against the Fritz!Box. 191 | 192 | 1. Login to your Fritz!Box 193 | 2. Navigate to _System_ -> _Fritz!Box-Benutzer_ 194 | 195 | Here you can add a new user to your Fritz!Box. The user needs at least the following permissions to work properly. 196 | 197 | * _FRITZ!Box Einstellungen__ 198 | * _Sprachnachrichten, Faxnachrichten, FRITZ!App Fon und Anrufliste_ 199 | * _Smart Home_ 200 | 201 | __Script__ 202 | 203 | The `check_tr64_script` use SSL to communicate with the Fritz!Box. Therefore you 204 | need to find out your SSL port for the TR-064 protocol. Please use the script 205 | `getSecurityPort` to find out the port that is used by your Fritz!Box. 206 | 207 | > **Note**: 208 | > 209 | > The script `getSecurityPort` don't use the SSL protocol to communitcate with 210 | > the Fritz!Box. The information about the used port for TR-064 over SSL is 211 | > available without authentication against the Fritz!Box. 212 | 213 | __Icinga Web 2__ 214 | 215 | You must specify your Fritz!Box password inside your Icinga 2 configuration to 216 | monitor your Fritz!Box, therefore ensure that you are hiding the custom password 217 | attribute in Icinga Web 2. 218 | 219 | 1. Log in to Icinga Web 2. 220 | 2. Go to `Configuration` -> `Modules` -> `monitoring` -> `Security`. 221 | 3. Ensure that your custom password attribute is protected (defaults are `*pw*,*pass*,community`). If you named your custom variable `fritz_password` it will be protected by the default entry `*pass*`. 222 | 4. Check it by going to one of your Fritz!Box service and check if the password is display with ``***``. 223 | 224 | ## Contributors 225 | 226 | - [mcktr](https://github.com/mcktr) 227 | 228 | Thanks to all contributors! 229 | 230 | - [cxcv](https://github.com/cxcv) for fixing a bug with [performance data output](https://github.com/mcktr/check_tr64_fritz/pull/23) 231 | - [uclara](https://github.com/uclara) for proposing to add [adjustable warning/critical values for the functions down-/upstream](https://github.com/mcktr/check_tr64_fritz/issues/40) 232 | - [matthenning](https://github.com/matthenning) for reporting and helping resolving a [bug on Fritz!Box cable models](https://github.com/mcktr/check_tr64_fritz/issues/30) 233 | 234 | 235 | ## Thanks 236 | 237 | - [FRITZ!Box mit Nagios überwachen](http://blog.gmeiners.net/2013/09/fritzbox-mit-nagios-uberwachen.html) 238 | - [Fritz!Box and TR-064](http://heise.de/-2550500) 239 | 240 | ## Development 241 | 242 | Fork the project to your GitHub account, commit your changes and send a pull request. For developing on 243 | this project it is advantageous to have a Fritz!Box at your place to test your changes. 244 | 245 | Before we start to fetching and parsing the TR-064 data we need to know which data our 246 | Fritz!Box provides. We can either fetch a list of this directly from the Fritz!Box or 247 | we can also look into the documentation from the manufacturer AVM. It is good to do both, 248 | make sure that the data we want to fetch is supported by AVM and our Fritz!Box actually 249 | provides it. 250 | 251 | You can fetch the list directly from the Fritz!Box, go to 252 | `http://:49000/tr64desc.xml` to fetch this list. 253 | You will get a XML file that contains many entries and it looks like the following. 254 | 255 | ``` 256 | [...] 257 | 258 | serviceType>urn:dslforum-org:service:DeviceInfo:1 259 | serviceId>urn:DeviceInfo-com:serviceId:DeviceInfo1 260 | controlURL>/upnp/control/deviceinfo 261 | eventSubURL>/upnp/control/deviceinfo 262 | SCPDURL>/deviceinfoSCPD.xml 263 | 264 | [...] 265 | ``` 266 | 267 | | Name | Description | 268 | | --- | --- | 269 | | serviceType | Service category which we want to call | 270 | | controlURL | URL we need to call, when fetching information from the choosen category | 271 | 272 | You can find the manufacturer documentation [here](https://avm.de/service/schnittstellen/). 273 | Have a look into the PDF files and search for a __action__ that provides your needed data. 274 | 275 | To finally create our TR-064 request we need three information beforehand. 276 | 277 | 1. The _serviceType_ e.g. `DeviceInfo` 278 | 2. The _controlURL_ e.g. `deviceinfo` (Only the last part after the slash.) 279 | 3. The _action_ e.g. 'GetInfo' (Look into the manufacturer documentation to find those.) 280 | 281 | Inside the `devel` directory you can find a bash script, that allows you to fetch the raw TR-064 data (basically in XML 282 | format). 283 | 284 | __fetch_tr64_data.sh__ 285 | 286 | This script fetches and output the raw TR-064 data. 287 | 288 | __Arugments__ 289 | 290 | | Name | Description | 291 | | --- | --- | 292 | | -h | Hostname/IP Adress of your Fritz!Box. | 293 | | -p | The port number for TR-064 over SSL. | 294 | | -u | Username. | 295 | | -P | Password. | 296 | | -U | _controlURL_. | 297 | | -s | _serviceType_. | 298 | | -a | _action_. | 299 | | -x | Index. | 300 | 301 | _Example:_ 302 | 303 | ``` 304 | ./fetch_tr64_data.sh -P [PASSWORD] -U deviceinfo -s DeviceInfo -a GetInfo 305 | 306 | 307 | fritz.box 308 | 49443 309 | dslf-config 310 | [PASSWORD] 311 | deviceinfo 312 | DeviceInfo 313 | GetInfo 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | AVM 322 | 00040E 323 | FRITZ!Box 7490 324 | FRITZ!Box 7490 113.06.92 325 | FRITZ!Box 326 | [SERIALNO.] 327 | 113.06.92 328 | FRITZ!Box 7490 329 | 1.0 330 | [CODE] 331 | 97384 332 | 333 | [LOG] 334 | 335 | 336 | 337 | 338 | ``` 339 | 340 | Now you can see the raw TR-064 and see if your needed information is in there. If yes you can now extend the check plugin script and parsing the output to output the result in a proper format. 341 | -------------------------------------------------------------------------------- /check_tr64_fritz: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | VERSION="2.1" 4 | 5 | PLUGIN_OK=0 6 | PLUGIN_WARNING=1 7 | PLUGIN_CRITICAL=2 8 | PLUGIN_ERROR=2 9 | PLUGIN_UNKNOWN=3 10 | 11 | find_xml_value() 12 | { 13 | xml=$1 14 | value=$2 15 | 16 | echo "${xml}" | sed -ne "/<${value}>/s#\s*<[^>]*>\s*##gp" 17 | } 18 | 19 | check_number() 20 | { 21 | VAR=$1 22 | 23 | if [[ ! "${VAR}" =~ ^[0-9]+$ ]]; then 24 | echo "UNKNOWN - Could not parse output" 25 | exit ${PLUGIN_UNKNOWN} 26 | fi 27 | } 28 | 29 | check_greater() 30 | { 31 | value=$1 32 | warn=$2 33 | crit=$3 34 | msg=$4 35 | perfdata=$5 36 | 37 | if [[ ${warn} == 0 || ${crit} == 0 ]]; then 38 | echo "OK - ${msg} | ${perfdata}=${value};;;;" 39 | exit ${PLUGIN_OK} 40 | elif (( $(echo "${value} > ${crit}" | bc -l) )); then 41 | echo "CRITICAL - ${msg} | ${perfdata}=${value};${warn};${crit};;" 42 | exit ${PLUGIN_CRITICAL} 43 | elif (( $(echo "${value} > ${warn}" | bc -l) )); then 44 | echo "WARNING - ${msg} | ${perfdata}=${value};${warn};${crit};;" 45 | exit ${PLUGIN_WARNING} 46 | else 47 | echo "OK - ${msg} | ${perfdata}=${value};${warn};${crit};;" 48 | exit ${PLUGIN_OK} 49 | fi 50 | } 51 | 52 | check_lower() 53 | { 54 | value=$1 55 | warn=$2 56 | crit=$3 57 | msg=$4 58 | perfdata=$5 59 | 60 | if [[ ${warn} == 0 || ${crit} == 0 ]]; then 61 | echo "OK - ${msg} | ${perfdata}=${value};;;;" 62 | exit ${PLUGIN_OK} 63 | elif (( $(echo "${value} < ${crit}" | bc -l) )); then 64 | echo "CRITICAL - ${msg} | ${perfdata}=${value};${warn};${crit};;" 65 | exit ${PLUGIN_CRITICAL} 66 | elif (( $(echo "${value} < ${warn}" | bc -l) )); then 67 | echo "WARNING - ${msg} | ${perfdata}=${value};${warn};${crit};;" 68 | exit ${PLUGIN_WARNING} 69 | else 70 | echo "OK - ${msg} | ${perfdata}=${value};${warn};${crit};;" 71 | exit ${PLUGIN_OK} 72 | fi 73 | } 74 | 75 | 76 | version() 77 | { 78 | echo "check_tr64_fritz" 79 | echo " Version ${VERSION}" 80 | echo "" 81 | } 82 | 83 | usage() 84 | { 85 | echo "usage: check_tr64_fritz -h -p -u -P -f -w -c " 86 | echo "" 87 | echo " -h: IP-Adress or hostname from the Fritz!Box" 88 | echo " default = fritz.box" 89 | echo "" 90 | echo " -p: SSL-Port from the Fritz!Box" 91 | echo " default = 49443" 92 | echo "" 93 | echo " -u: Login Username for the Fritz!Box" 94 | echo " default = dslf-config" 95 | echo "" 96 | echo " -P: Login Password for the Fritz!Box" 97 | echo "" 98 | echo " -f: Function to check" 99 | echo "" 100 | echo " -w: value where the warning state come into effect" 101 | echo " default = -1 / returns every time an OK state" 102 | echo "" 103 | echo " -c: value where the critical state come into effect" 104 | echo " default = -1 / return every time an OK state" 105 | echo "" 106 | echo " -v: print version and usage page" 107 | echo "" 108 | echo "Functions:" 109 | echo "" 110 | echo " status = Connection Status" 111 | echo "" 112 | echo " linkuptime = WAN link uptime" 113 | echo "" 114 | echo " uptime = device uptime" 115 | echo "" 116 | echo " downstream = useable downstream rate" 117 | echo " output in Mbit/s" 118 | echo "" 119 | echo " upstream = useable upstream rate" 120 | echo " output in Mbit/s" 121 | echo "" 122 | echo " downstreamrate = current downstream rate" 123 | echo " output in Mbit/s" 124 | echo "" 125 | echo " upstreamrate = current upstream rate" 126 | echo " output in Mbit/s" 127 | echo "" 128 | echo " update = get the update state" 129 | echo "" 130 | echo " thermometer: = Smart Home thermometer status" 131 | echo " output of the current temperature" 132 | echo "" 133 | echo " socketpower: = Smart Home socket power" 134 | echo " output of the current power usage in watts" 135 | echo "" 136 | echo " socketenergy: = Smart Home socket total consumption" 137 | echo " output of the total consumption over the last year in kWh" 138 | echo "" 139 | echo " socketswitch: = Smart Home socket switch status" 140 | echo " output of the switch status" 141 | echo "" 142 | echo "DEBUG" 143 | echo "" 144 | echo " -d: prints debug information" 145 | exit ${PLUGIN_UNKNOWN} 146 | } 147 | 148 | HOSTNAME="fritz.box" 149 | PORT="49443" 150 | USERNAME="dslf-config" 151 | functionAndIndex="status" 152 | WARN=0 153 | CRIT=0 154 | DEBUG=0 155 | INDEX=0 156 | 157 | while getopts h:p:u:P:f:w:c:dv OPTNAME; do 158 | case "${OPTNAME}" in 159 | h) 160 | HOSTNAME="${OPTARG}" 161 | ;; 162 | p) 163 | PORT="${OPTARG}" 164 | ;; 165 | u) 166 | USERNAME="${OPTARG}" 167 | ;; 168 | P) 169 | PASSWORD="${OPTARG}" 170 | ;; 171 | f) 172 | functionAndIndex="${OPTARG}" 173 | ;; 174 | w) 175 | WARN="${OPTARG}" 176 | ;; 177 | c) 178 | CRIT="${OPTARG}" 179 | ;; 180 | d) 181 | DEBUG=1 182 | ;; 183 | v) 184 | version 185 | usage 186 | ;; 187 | *) 188 | usage 189 | ;; 190 | esac 191 | done 192 | 193 | FUNCTION=$( echo "${functionAndIndex}" | cut -d ':' -f 1 ) 194 | INDEX=$( echo "${functionAndIndex}" | cut -d ':' -f 2 ) 195 | 196 | case ${FUNCTION} in 197 | "status" | "linkuptime") 198 | url='wanpppconn1' 199 | service='WANPPPConnection' 200 | 201 | if [ ${INDEX} == "cable" ]; then 202 | url='wanipconnection1' 203 | service='WanIPConnection' 204 | elif [ ${INDEX} == "pppoe" ]; then 205 | url='wanpppconn1' 206 | service='WANPPPConnection' 207 | fi 208 | 209 | action='GetInfo' 210 | 211 | ;; 212 | "downstreamrate" | "upstreamrate" | "downstream" | "upstream") 213 | url='wancommonifconfig1' 214 | service='WANCommonInterfaceConfig' 215 | action='X_AVM-DE_GetOnlineMonitor' 216 | xmlVar='0' 217 | ;; 218 | "update") 219 | url='userif' 220 | service='UserInterface' 221 | action='GetInfo' 222 | ;; 223 | "uptime") 224 | url='deviceinfo' 225 | service='DeviceInfo' 226 | action='GetInfo' 227 | ;; 228 | "thermometer" | "socketpower" | "socketenergy" | "socketswitch") 229 | url='x_homeauto' 230 | service='X_AVM-DE_Homeauto' 231 | action='GetGenericDeviceInfos' 232 | xmlVar="${INDEX}" 233 | ;; 234 | esac 235 | 236 | queryResult=$(curl "https://${HOSTNAME}:${PORT}/upnp/control/${url}" \ 237 | -k \ 238 | -s \ 239 | -u "${USERNAME}":"${PASSWORD}" \ 240 | --anyauth \ 241 | -H "Content-Type: text/xml; charset='utf-8'" \ 242 | -H "SOAPACTION: urn:dslforum-org:service:${service}:1#${action}" \ 243 | -d " ${xmlVar} " 244 | ) 245 | 246 | if [[ "${queryResult}" == *"401 Unauthorized"* ]]; then 247 | echo "ERROR - Wrong Password" 248 | exit ${PLUGIN_ERROR} 249 | fi 250 | 251 | if [ ${DEBUG} -eq 1 ]; then 252 | echo "${queryResult}" 253 | fi 254 | 255 | case ${FUNCTION} in 256 | "status") 257 | STATUS=$(find_xml_value "${queryResult}" "NewConnectionStatus") 258 | 259 | if [ -z "${STATUS}" ]; then 260 | echo "UNKNOWN - Could not get a response | 'status'=${PLUGIN_UNKNOWN};;;;" 261 | exit ${PLUGIN_UNKNOWN} 262 | fi 263 | 264 | case ${STATUS} in 265 | "Connected") 266 | echo "OK - ${STATUS} | 'status'=${PLUGIN_OK};;;;" 267 | exit ${PLUGIN_OK} 268 | ;; 269 | "Connecting" | "Authenticating") 270 | echo "WARNING - ${STATUS} | 'status'=${PLUGIN_WARNING};;;;" 271 | exit ${PLUGIN_WARNING} 272 | ;; 273 | *) 274 | echo "ERROR - ${STATUS} | 'status'=${PLUGIN_ERROR};;;;" 275 | exit ${PLUGIN_ERROR} 276 | ;; 277 | esac 278 | ;; 279 | "linkuptime") 280 | LINKUPTIME=$(find_xml_value "${queryResult}" "NewUptime") 281 | 282 | check_number "${LINKUPTIME}" 283 | 284 | days=$(( ${LINKUPTIME} / 86400 )) 285 | hours=$(( (${LINKUPTIME} / 3600) - (${days} * 24) )) 286 | minutes=$(( (${LINKUPTIME} / 60) - (${days} * 1440) - (${hours} * 60) )) 287 | seconds=$(( ${LINKUPTIME} % 60 )) 288 | 289 | echo "OK - Link Uptime ${LINKUPTIME} seconds (${days}d ${hours}h ${minutes}m ${seconds}s) | 'linkuptime'=${LINKUPTIME}s;;;;" 290 | 291 | exit ${PLUGIN_OK} 292 | 293 | ;; 294 | "downstreamrate") 295 | LIST_DS_BYTE=$(find_xml_value "${queryResult}" "Newds_current_bps") 296 | 297 | curr_ds_byte=$(echo "${LIST_DS_BYTE}" | cut -d ',' -f 1) 298 | 299 | check_number "${curr_ds_byte}" 300 | 301 | ds_rate_mbit=$(echo "scale=2; ${curr_ds_byte}*8/1000000" | bc | sed -r 's/^(-?)\./\10./') 302 | MSG="Current Downstream ${ds_rate_mbit} Mbit/s" 303 | 304 | check_greater ${ds_rate_mbit} ${WARN} ${CRIT} "${MSG}" "'current_downstream'" 305 | 306 | ;; 307 | "upstreamrate") 308 | LIST_US_BYTE=$(find_xml_value "${queryResult}" "Newus_current_bps") 309 | 310 | curr_us_byte=$(echo "${LIST_US_BYTE}" | cut -d ',' -f 1) 311 | 312 | check_number "${curr_us_byte}" 313 | 314 | us_rate_mbit=$(echo "scale=2; ${curr_us_byte}*8/1000000" | bc | sed -r 's/^(-?)\./\10./') 315 | MSG="Current Upstream ${us_rate_mbit} Mbit/s" 316 | 317 | check_greater ${us_rate_mbit} ${WARN} ${CRIT} "${MSG}" "'current_upstream'" 318 | 319 | ;; 320 | "downstream") 321 | DS_BYTE=$(find_xml_value "${queryResult}" "Newmax_ds") 322 | 323 | check_number "${DS_BYTE}" 324 | 325 | DOWNSTREAM=$((${DS_BYTE}*8/1000000)) 326 | MSG="Downstream ${DOWNSTREAM} Mbit/s" 327 | 328 | check_lower ${DOWNSTREAM} ${WARN} ${CRIT} "${MSG}" "'downstream_rate'" 329 | 330 | ;; 331 | "upstream") 332 | US_BYTE=$(find_xml_value "${queryResult}" "Newmax_us") 333 | 334 | check_number "${US_BYTE}" 335 | 336 | UPSTREAM=$((${US_BYTE}*8/1000000)) 337 | MSG="Upstream ${UPSTREAM} Mbit/s" 338 | 339 | check_lower ${UPSTREAM} ${WARN} ${CRIT} "${MSG}" "'upstream_rate'" 340 | 341 | ;; 342 | "update") 343 | UPDATE=$(find_xml_value "${queryResult}" "NewUpgradeAvailable") 344 | 345 | if [[ ${UPDATE} == 0 ]]; then 346 | echo "OK - No Upgrade available | 'update_pending'=${UPDATE};;;;" 347 | exit ${PLUGIN_OK} 348 | fi 349 | 350 | echo "CRITICAL - Upgrade available | 'update_pending'=${UPDATE};;;;" 351 | exit ${PLUGIN_CRITICAL} 352 | 353 | ;; 354 | "uptime") 355 | UPTIME=$(find_xml_value "${queryResult}" "NewUpTime") 356 | 357 | check_number "${UPTIME}" 358 | 359 | days=$(( ${UPTIME} / 86400 )) 360 | hours=$(( (${UPTIME} / 3600) - (${days} * 24) )) 361 | minutes=$(( (${UPTIME} / 60) - (${days} * 1440) - (${hours} * 60) )) 362 | seconds=$(( ${UPTIME} % 60 )) 363 | 364 | echo "OK - Uptime ${UPTIME} seconds (${days}d ${hours}h ${minutes}m ${seconds}s) | 'uptime'=${UPTIME}s;;;;" 365 | 366 | exit ${PLUGIN_OK} 367 | 368 | ;; 369 | "thermometer") 370 | 371 | if [ "$(find_xml_value "${queryResult}" "errorCode")" = "820" ]; then 372 | echo "UNKNOWN - Not able to fetch current thermometer temperature | 'thermometer_current_state'=${PLUGIN_UNKNOWN};;;;" 373 | exit ${PLUGIN_UNKNOWN} 374 | fi 375 | 376 | if [ "$(find_xml_value "${queryResult}" "errorCode")" = "713" ]; then 377 | echo "UNKNOWN - Specified device index invalid" 378 | exit ${PLUGIN_UNKNOWN} 379 | fi 380 | 381 | deviceTempFeature=$(find_xml_value "${queryResult}" "NewTemperatureIsEnabled") 382 | deviceFirmwareVersion=$(find_xml_value "${queryResult}" "NewFirmwareVersion") 383 | deviceProductName=$(find_xml_value "${queryResult}" "NewProductName") 384 | deviceName=$(find_xml_value "${queryResult}" "NewDeviceName") 385 | devicePresent=$(find_xml_value "${queryResult}" "NewPresent") 386 | deviceCurrentTemp=$(find_xml_value "${queryResult}" "NewTemperatureCelsius") 387 | 388 | currentTemp=$( echo "scale=1; ${deviceCurrentTemp}/10" | bc ) 389 | 390 | case ${devicePresent} in 391 | "CONNECTED") 392 | if [ "${deviceTempFeature}" != "ENABLED" ]; then 393 | echo "UNKNOWN - Temperature is not enabled on this device | 'thermometer_current_state'=${PLUGIN_UNKNOWN};;;;" 394 | exit ${PLUGIN_UNKNOWN} 395 | fi 396 | 397 | text="${deviceProductName} ${deviceFirmwareVersion} - ${deviceName} ${devicePresent} ${currentTemp} °C" 398 | 399 | check_lower ${currentTemp} ${WARN} ${CRIT} "${text}" "'thermometer_current_state'=${PLUGIN_OK};;;; 'thermometer_current_temp'" 400 | ;; 401 | "UNKNOWN") 402 | echo "UNKNOWN - ${deviceProductName} ${deviceFirmwareVersion} - ${deviceName} ${devicePresent} | 'thermometer_current_state'=${PLUGIN_UNKNOWN};;;;" 403 | exit ${PLUGIN_UNKNOWN} 404 | ;; 405 | *) 406 | echo "CRITICAL - ${deviceProductName} ${deviceFirmwareVersion} - ${deviceName} ${devicePresent} | 'thermometer_current_state'=${PLUGIN_CRITICAL};;;;" 407 | exit ${PLUGIN_CRITICAL} 408 | ;; 409 | esac 410 | ;; 411 | "socketpower") 412 | 413 | if [ "$(find_xml_value "${queryResult}" "errorCode")" = "820" ]; then 414 | echo "UNKNOWN - Not able to fetch current socket status" 415 | exit ${PLUGIN_UNKNOWN} 416 | fi 417 | 418 | if [ "$(find_xml_value "${queryResult}" "errorCode")" = "713" ]; then 419 | echo "UNKNOWN - Specified device index invalid" 420 | exit ${PLUGIN_UNKNOWN} 421 | fi 422 | 423 | deviceMultimeterFeature=$(find_xml_value "${queryResult}" "NewMultimeterIsEnabled") 424 | deviceFirmwareVersion=$(find_xml_value "${queryResult}" "NewFirmwareVersion") 425 | deviceProductName=$(find_xml_value "${queryResult}" "NewProductName") 426 | deviceName=$(find_xml_value "${queryResult}" "NewDeviceName") 427 | devicePresent=$(find_xml_value "${queryResult}" "NewPresent") 428 | deviceMultimeterPower=$(find_xml_value "${queryResult}" "NewMultimeterPower") 429 | 430 | currentPower=$( echo "scale=2; ${deviceMultimeterPower}/100" | bc ) 431 | 432 | case ${devicePresent} in 433 | "CONNECTED") 434 | if [ "${deviceMultimeterFeature}" != "ENABLED" ]; then 435 | echo "UNKNOWN - Device with index ${INDEX} is not a socket" 436 | exit ${PLUGIN_UNKNOWN} 437 | fi 438 | 439 | text="${deviceProductName} ${deviceFirmwareVersion} - ${deviceName} ${devicePresent} ${currentPower} W" 440 | 441 | check_greater ${currentPower} ${WARN} ${CRIT} "${text}" "'socket_current_power'" 442 | ;; 443 | "UNKNOWN") 444 | echo "UNKNOWN - ${deviceProductName} ${deviceFirmwareVersion} - ${deviceName} ${devicePresent}" 445 | exit ${PLUGIN_UNKNOWN} 446 | ;; 447 | *) 448 | echo "CRITICAL - ${deviceProductName} ${deviceFirmwareVersion} - ${deviceName} ${devicePresent}" 449 | exit ${PLUGIN_CRITICAL} 450 | ;; 451 | esac 452 | ;; 453 | "socketenergy") 454 | 455 | if [ "$(find_xml_value "${queryResult}" "errorCode")" = "820" ]; then 456 | echo "UNKNOWN - Not able to fetch current socket status" 457 | exit ${PLUGIN_UNKNOWN} 458 | fi 459 | 460 | if [ "$(find_xml_value "${queryResult}" "errorCode")" = "713" ]; then 461 | echo "UNKNOWN - Specified device index invalid" 462 | exit ${PLUGIN_UNKNOWN} 463 | fi 464 | 465 | deviceMultimeterFeature=$(find_xml_value "${queryResult}" "NewMultimeterIsEnabled") 466 | deviceFirmwareVersion=$(find_xml_value "${queryResult}" "NewFirmwareVersion") 467 | deviceProductName=$(find_xml_value "${queryResult}" "NewProductName") 468 | deviceName=$(find_xml_value "${queryResult}" "NewDeviceName") 469 | devicePresent=$(find_xml_value "${queryResult}" "NewPresent") 470 | deviceMultimeterEnergy=$(find_xml_value "${queryResult}" "NewMultimeterEnergy") 471 | 472 | currentEnergy=$( echo "scale=2; ${deviceMultimeterEnergy}/1000" | bc ) 473 | 474 | case ${devicePresent} in 475 | "CONNECTED") 476 | if [ "${deviceMultimeterFeature}" != "ENABLED" ]; then 477 | echo "UNKNOWN - Device with index ${INDEX} is not a socket" 478 | exit ${PLUGIN_UNKNOWN} 479 | fi 480 | 481 | text="${deviceProductName} ${deviceFirmwareVersion} - ${deviceName} ${devicePresent} ${currentEnergy} kWh" 482 | 483 | check_greater ${currentEnergy} ${WARN} ${CRIT} "${text}" "'socket_total_consumption'" 484 | ;; 485 | "UNKNOWN") 486 | echo "UNKNOWN - ${deviceProductName} ${deviceFirmwareVersion} - ${deviceName} ${devicePresent}" 487 | exit ${PLUGIN_UNKNOWN} 488 | ;; 489 | *) 490 | echo "CRITICAL - ${deviceProductName} ${deviceFirmwareVersion} - ${deviceName} ${devicePresent}" 491 | exit ${PLUGIN_CRITICAL} 492 | ;; 493 | esac 494 | ;; 495 | "socketswitch") 496 | 497 | if [ "$(find_xml_value "${queryResult}" "errorCode")" = "820" ]; then 498 | echo "UNKNOWN - Not able to fetch current socket status" 499 | exit ${PLUGIN_UNKNOWN} 500 | fi 501 | 502 | if [ "$(find_xml_value "${queryResult}" "errorCode")" = "713" ]; then 503 | echo "UNKNOWN - Specified device index invalid" 504 | exit ${PLUGIN_UNKNOWN} 505 | fi 506 | 507 | deviceMultimeterFeature=$(find_xml_value "${queryResult}" "NewMultimeterIsEnabled") 508 | deviceFirmwareVersion=$(find_xml_value "${queryResult}" "NewFirmwareVersion") 509 | deviceProductName=$(find_xml_value "${queryResult}" "NewProductName") 510 | deviceName=$(find_xml_value "${queryResult}" "NewDeviceName") 511 | devicePresent=$(find_xml_value "${queryResult}" "NewPresent") 512 | deviceSocketSwitch=$(find_xml_value "${queryResult}" "NewSwitchState") 513 | 514 | case ${devicePresent} in 515 | "CONNECTED") 516 | if [ "${deviceMultimeterFeature}" != "ENABLED" ]; then 517 | echo "UNKNOWN - Device with index ${INDEX} is not a socket" 518 | exit ${PLUGIN_UNKNOWN} 519 | fi 520 | 521 | interpretOffAsCritical="false" 522 | switchStateInt=0 523 | 524 | if [ "${deviceSocketSwitch}" == "ON" ]; then 525 | switchStateInt=1 526 | fi 527 | 528 | if (( $(echo "${WARN} >= 1" | bc -l) )); then 529 | interpretOffAsCritical="true" 530 | fi 531 | 532 | if (( $(echo "${CRIT} >= 1" | bc -l) )); then 533 | interpretOffAsCritical="true" 534 | fi 535 | 536 | if [ "${deviceSocketSwitch}" == "OFF" ] && [ "${interpretOffAsCritical}" == "true" ]; then 537 | echo "CRITICAL - ${deviceProductName} ${deviceFirmwareVersion} - ${deviceName} ${devicePresent} Switch ${deviceSocketSwitch} | 'socket_switch_state'=${switchStateInt};;;;" 538 | exit ${PLUGIN_CRITICAL} 539 | fi 540 | 541 | echo "OK - ${deviceProductName} ${deviceFirmwareVersion} - ${deviceName} ${devicePresent} Switch ${deviceSocketSwitch} | 'socket_switch_state'=${switchStateInt};;;;" 542 | exit ${PLUGIN_OK} 543 | ;; 544 | "UNKNOWN") 545 | echo "UNKNOWN - ${deviceProductName} ${deviceFirmwareVersion} - ${deviceName} ${devicePresent}" 546 | exit ${PLUGIN_UNKNOWN} 547 | ;; 548 | *) 549 | echo "CRITICAL - ${deviceProductName} ${deviceFirmwareVersion} - ${deviceName} ${devicePresent}" 550 | exit ${PLUGIN_CRITICAL} 551 | ;; 552 | esac 553 | ;; 554 | *) 555 | echo "UNKNOWN - Unknown function" 556 | exit ${PLUGIN_UNKNOWN} 557 | ;; 558 | esac 559 | -------------------------------------------------------------------------------- /devel/fetch_tr64_data.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | HOSTNAME="fritz.box" 4 | PORT="49443" 5 | USERNAME="dslf-config" 6 | 7 | while getopts h:p:u:P:U:s:a:x: OPTNAME; do 8 | case "${OPTNAME}" in 9 | h) 10 | HOSTNAME="${OPTARG}" 11 | ;; 12 | p) 13 | PORT="${OPTARG}" 14 | ;; 15 | u) 16 | USERNAME="${OPTARG}" 17 | ;; 18 | P) 19 | PASSWORD="${OPTARG}" 20 | ;; 21 | U) 22 | url="${OPTARG}" 23 | ;; 24 | s) 25 | service="${OPTARG}" 26 | ;; 27 | a) 28 | action="${OPTARG}" 29 | ;; 30 | x) 31 | xmlVar="${OPTARG}" 32 | ;; 33 | *) 34 | echo "fetch_tr64_data.sh -h -p -u -P -U -s -a -x " 35 | exit 0 36 | ;; 37 | esac 38 | done 39 | 40 | echo "" 41 | echo "" 42 | echo "${HOSTNAME}" 43 | echo "${PORT}" 44 | echo "${USERNAME}" 45 | echo "${PASSWORD}" 46 | echo "${url}" 47 | echo "${service}" 48 | echo "${action}" 49 | echo "${xmlVar}" 50 | echo "" 51 | echo "" 52 | 53 | queryResult=$(curl "https://${HOSTNAME}:${PORT}/upnp/control/${url}" \ 54 | -k \ 55 | -s \ 56 | -u "${USERNAME}:${PASSWORD}" \ 57 | --anyauth \ 58 | -H "Content-Type: text/xml; charset='utf-8'" \ 59 | -H "SOAPACTION: urn:dslforum-org:service:${service}:1#${action}" \ 60 | -d " ${xmlVar} " 61 | ) 62 | 63 | echo "${queryResult}" 64 | -------------------------------------------------------------------------------- /doc/01-smarthome.md: -------------------------------------------------------------------------------- 1 | ### Smart Home device data 2 | 3 | Functions that collect data from smart home devices (such as the thermometers) 4 | don't respond with live data, e.g. smart home device went offline and you 5 | will still get an OK response. This is caused by the communication between the 6 | Fritz!Box and the smart home devices, they exchange data every ~15 minutes, 7 | therefore the smart home functions can not show the live data. 8 | 9 | ### Get the index for Smart Home devices 10 | 11 | You can fetch the index number for your smart home device from your Fritz!Box 12 | web interface. Log in to your Fritz!Box web interface and navigate to `Heimnetz` 13 | -> `Smart Home`. 14 | 15 | ![Fritz!Box Web-Interface Smart Home](images/image_fritzbox_smarthome_index.png) 16 | 17 | The index numbers are set by a descending order and always start with `0`. In the example screenshot you will 18 | have the following index numbers. 19 | 20 | | Name | Index number | 21 | | --- | --- | 22 | | Büro | 0 | 23 | | Badezimmer | 1 | 24 | | Küche | 2 | 25 | | Wohnzimmer | 3 | 26 | | Schlafzimmer | 4 | 27 | -------------------------------------------------------------------------------- /doc/github_doc_fritzbox_services.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcktr/check_tr64_fritz/a9a7f9fa7686654ff388905c58cba72cef488bf0/doc/github_doc_fritzbox_services.png -------------------------------------------------------------------------------- /doc/images/image_fritzbox_smarthome_index.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcktr/check_tr64_fritz/a9a7f9fa7686654ff388905c58cba72cef488bf0/doc/images/image_fritzbox_smarthome_index.png -------------------------------------------------------------------------------- /getSecurityPort: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | find_xml_value() 4 | { 5 | xml=$1 6 | value=$2 7 | 8 | echo "${xml}" | sed -ne "/<${value}>/s#\s*<[^>]*>\s*##gp" 9 | } 10 | 11 | usage() 12 | { 13 | echo "getSecurityPort " 14 | echo " = IP of your Fritz!Box" 15 | } 16 | 17 | HOSTNAME=$1 18 | 19 | if [ -z ${HOSTNAME} ]; then 20 | usage 21 | exit 0 22 | fi 23 | 24 | queryResult=$(curl "http://${HOSTNAME}:49000/upnp/control/deviceinfo" \ 25 | -s \ 26 | -H "Content-Type: text/xml; charset='utf-8'" \ 27 | -H "SOAPACTION: urn:dslforum-org:service:DeviceInfo:1#GetSecurityPort" \ 28 | -d " ") 29 | 30 | securityPort=$(find_xml_value "${queryResult}" "NewSecurityPort") 31 | 32 | echo "Your Fritz!Box Security Port (for TR-064 over SSL) is: ${securityPort}" 33 | 34 | exit 0 35 | --------------------------------------------------------------------------------