chore: initial import from KNEL/PFVCluster@041d311 [#769]
Split per O&M lane work order. Full history: KNEL/PFVCluster. shellcheck debt fixed in librenms-agent (quoting, arithmetic, backticks); fixes upstream ntp-server.sh bug: input_wakeups reported PACKETSENDFAILURES instead of INPUTWAKEUPS. mysql.sh (PHP-in-.sh) exempt per house rule. https://projects.knownelement.com/issues/769#note-4152
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
# Refs only — real values live in ~/.creds (0600), never in repos.
|
||||||
|
# Example: this repo's CLIs read env files at runtime, e.g.
|
||||||
|
# docker run --rm --env-file ~/.creds/redmine.env ...
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# ShellCheck configuration for PFVCluster
|
||||||
|
# (used when running `shellcheck` directly; tests/shellcheck.sh applies the
|
||||||
|
# same disables via -e for consistent results under Docker)
|
||||||
|
#
|
||||||
|
# These checks are DISABLED because they flag intentional conventions of this
|
||||||
|
# codebase, not bugs:
|
||||||
|
#
|
||||||
|
# SC1090 / SC1091 — cannot follow dynamically-computed `source` paths. The KNEL
|
||||||
|
# framework (vendor/) and test harness source helpers via computed include
|
||||||
|
# dirs, which shellcheck cannot resolve statically.
|
||||||
|
# SC2029 — ssh orchestration (tests/remote.sh and perf/k8s/dns scripts)
|
||||||
|
# deliberately builds and expands the remote command on the CLIENT side before
|
||||||
|
# sending it. That is the whole point of the single-chokepoint remote pattern.
|
||||||
|
disable=SC1090,SC1091,SC2029
|
||||||
|
|
||||||
|
# Treat external-sourced files as bash (matches #!/usr/bin/env bash framework).
|
||||||
|
external-sources=true
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# AGENTS.md — monitoring
|
||||||
|
|
||||||
|
Point of truth for fleet-wide agent policy: the workspace AGENTS.md in KNEL/PFVCluster (loaded globally). This file holds repo-specific notes only.
|
||||||
|
|
||||||
|
- Ticket gate: `echo '#NNN' > .crush/active-ticket` before any modification; reference [\#343] + [#769].
|
||||||
|
- Remote access: SSH chokepoints only — tests/remote.sh (PFVCluster)monitoring; DNS names only, never IP literals.
|
||||||
|
- Docs: Discourse topic https://community.turnsys.com/t/323 — keep README pointer current.
|
||||||
|
- shellcheck zero-warning (incl. info) via `bash tests/shellcheck.sh`.
|
||||||
@@ -0,0 +1,235 @@
|
|||||||
|
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 19 November 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||||
|
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU Affero General Public License is a free, copyleft license for software and other kinds of works, specifically designed to ensure cooperation with the community in the case of network server software.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users.
|
||||||
|
|
||||||
|
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 them 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.
|
||||||
|
|
||||||
|
Developers that use our General Public Licenses protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License which gives you legal permission to copy, distribute and/or modify the software.
|
||||||
|
|
||||||
|
A secondary benefit of defending all users' freedom is that improvements made in alternate versions of the program, if they receive widespread use, become available for other developers to incorporate. Many developers of free software are heartened and encouraged by the resulting cooperation. However, in the case of software used on network servers, this result may fail to come about. The GNU General Public License permits making a modified version and letting the public access it on a server without ever releasing its source code to the public.
|
||||||
|
|
||||||
|
The GNU Affero General Public License is designed specifically to ensure that, in such cases, the modified source code becomes available to the community. It requires the operator of a network server to provide the source code of the modified version running there to the users of that server. Therefore, public use of a modified version, on a publicly accessible server, gives the public access to the source code of the modified version.
|
||||||
|
|
||||||
|
An older license, called the Affero General Public License and published by Affero, was designed to accomplish similar goals. This is a different license, not a version of the Affero GPL, but Affero has released a new version of the Affero GPL which permits relicensing under this license.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
You may convey 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; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
"Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If 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 convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, if you modify the Program, your modified version must prominently offer all users interacting with it remotely through a computer network (if your version supports such interaction) an opportunity to receive the Corresponding Source of your version by providing access to the Corresponding Source from a network server at no charge, through some standard or customary means of facilitating copying of software. This Corresponding Source shall include the Corresponding Source for any work covered by version 3 of the GNU General Public License that is incorporated pursuant to the following paragraph.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the work with which it is combined will remain governed by version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of the GNU Affero 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 that a certain numbered version of the GNU Affero General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU Affero General Public License, you may choose any version ever published by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future versions of the GNU Affero General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 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.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
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 state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
FetchApply
|
||||||
|
Copyright (C) 2024 VpTechnicalOperations
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If your software can interact with users remotely through a computer network, you should also make sure that it provides a way for users to get its source. For example, if your program is a web application, its interface could display a "Source" link that leads users to an archive of the code. There are many ways you could offer source, and different solutions will be better for different programs; see section 13 for the specific requirements.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU AGPL, see <http://www.gnu.org/licenses/>.
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
# Makefile — convenience dispatch to scripts/.
|
||||||
|
#
|
||||||
|
# Not required. The scripts in scripts/ are the real entry points and work
|
||||||
|
# standalone. This file just gives you short verbs if you're at a terminal.
|
||||||
|
#
|
||||||
|
# In Mode 2 (Hermes/OWUI/MCP), agents call the scripts directly or via API —
|
||||||
|
# they don't need this file.
|
||||||
|
|
||||||
|
# Project-specific overrides for check-rules.sh
|
||||||
|
export PROJECT_DOC_EXEMPT ?= AGENTS.md STATUS.md WORKING.md README.md ADOPTING.md LICENSE .env.example questions-v1.md BASELINE-PROMPT.md PATTERNS.md
|
||||||
|
export PROJECT_DISCOURSE_HOST ?= community.turnsys.com
|
||||||
|
|
||||||
|
.PHONY: setup validate fast lint test garden up down status clean help
|
||||||
|
|
||||||
|
help: ## Show available targets
|
||||||
|
@grep -E '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) | awk 'BEGIN{FS=":.*?## "}{printf " \033[36m%-12s\033[0m %s\n", $$1, $$2}'
|
||||||
|
|
||||||
|
setup: ## Install git hooks
|
||||||
|
@bash scripts/setup-hooks.sh
|
||||||
|
|
||||||
|
validate: ## Full rule audit (includes tests)
|
||||||
|
@bash scripts/check-rules.sh
|
||||||
|
|
||||||
|
fast: ## Fast rule audit (pre-commit equivalent)
|
||||||
|
@bash scripts/check-rules.sh --fast
|
||||||
|
|
||||||
|
lint: ## Lint shell scripts (shellcheck via docker)
|
||||||
|
@docker run --rm -v "$$(pwd):/mnt" koalaman/shellcheck:stable \
|
||||||
|
$$(find . -path ./.git -prune -o -path ./.tmp -prune -o -path ./vendor -prune -o -path ./node_modules -prune -o \( -name '*.sh' -o -name '*.bash' \) -print | sed 's|^\./|/mnt/|') || true
|
||||||
|
|
||||||
|
test: ## Run the test suite (override per project)
|
||||||
|
@bash scripts/test.sh
|
||||||
|
|
||||||
|
garden: ## Doc-sprawl / Discourse-migration report
|
||||||
|
@bash scripts/garden.sh
|
||||||
|
|
||||||
|
up: ## Bring up the docker-compose stack
|
||||||
|
@bash scripts/up.sh
|
||||||
|
|
||||||
|
down: ## Bring down the docker-compose stack
|
||||||
|
@bash scripts/down.sh
|
||||||
|
|
||||||
|
status: ## Show repo status snapshot
|
||||||
|
@echo "== branch =="; git branch --show-current 2>/dev/null || echo "(no branch)"
|
||||||
|
@echo "== last commit =="; git log --oneline -1 2>/dev/null || true
|
||||||
|
@echo "== working tree =="; git status --short 2>/dev/null || echo "(not a git repo)"
|
||||||
|
@echo "== STATUS.md head =="; sed -n '1,12p' STATUS.md 2>/dev/null || echo "(no STATUS.md)"
|
||||||
|
|
||||||
|
clean: ## Remove build/test artifacts (override per project)
|
||||||
|
@echo "make clean: nothing to clean — override this in your project's Makefile."
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
# monitoring
|
||||||
|
|
||||||
|
> **Docs live on Discourse — this repo is the executable source of truth.**
|
||||||
|
> **Topic:** https://community.turnsys.com/t/323
|
||||||
|
> **Redmine:** https://projects.knownelement.com/issues/343 · **Split from** KNEL/PFVCluster@041d311 per [#769](https://projects.knownelement.com/issues/769)
|
||||||
|
|
||||||
|
OAM monitoring stack: LibreNMS, oxidized, smokeping, netdisco, unpoller, weathermap; librenms-agent (check_mk + snmp-extend). Prometheus/Alertmanager/Grafana/Kuma buildout per [\#773]. Coverage matrix governs boundaries [\#343].
|
||||||
|
|
||||||
|
## Layout
|
||||||
|
- `scripts/` — rule engine + hooks (see `bash scripts/check-rules.sh --fast`)
|
||||||
|
- (imported content at repo root, mirroring its PFVCluster path layout)
|
||||||
|
|
||||||
|
## Provenance
|
||||||
|
Code imported from KNEL/PFVCluster (041d311); full git history retained in PFVCluster. Enforcement layer copied per ADOPTING.md. IaC consumers: KNEL/KNELIAC references this repo.
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
# STATUS.md
|
||||||
|
|
||||||
|
> Operations status lives on Discourse: https://community.turnsys.com/t/297
|
||||||
|
> This file is a pointer stub. Active ticket: [#769](https://projects.knownelement.com/issues/769) (repo split).
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Check_MK LibreNMS Agent Socket
|
||||||
|
|
||||||
|
[Socket]
|
||||||
|
ListenStream=6556
|
||||||
|
Accept=yes
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=sockets.target
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Check_MK LibreNMS Agent Service
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=/usr/bin/check_mk_agent
|
||||||
|
StandardOutput=socket
|
||||||
@@ -0,0 +1,659 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# +------------------------------------------------------------------+
|
||||||
|
# | ____ _ _ __ __ _ __ |
|
||||||
|
# | / ___| |__ ___ ___| | __ | \/ | |/ / |
|
||||||
|
# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
|
||||||
|
# | | |___| | | | __/ (__| < | | | | . \ |
|
||||||
|
# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
|
||||||
|
# | |
|
||||||
|
# | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
|
||||||
|
# +------------------------------------------------------------------+
|
||||||
|
#
|
||||||
|
# This file is part of Check_MK.
|
||||||
|
# The official homepage is at http://mathias-kettner.de/check_mk.
|
||||||
|
#
|
||||||
|
# check_mk 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 in version 2. check_mk is distributed
|
||||||
|
# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
|
||||||
|
# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||||
|
# PARTICULAR PURPOSE. See the GNU General Public License for more de-
|
||||||
|
# ails. You should have received a copy of the GNU General Public
|
||||||
|
# License along with GNU Make; see the file COPYING. If not, write
|
||||||
|
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||||
|
# Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
|
# Remove locale settings to eliminate localized outputs where possible
|
||||||
|
export LC_ALL=C
|
||||||
|
unset LANG
|
||||||
|
|
||||||
|
export MK_LIBDIR="/usr/lib/check_mk_agent"
|
||||||
|
export MK_CONFDIR="/etc/check_mk"
|
||||||
|
export MK_VARDIR="/var/lib/check_mk_agent"
|
||||||
|
|
||||||
|
# Provide information about the remote host. That helps when data
|
||||||
|
# is being sent only once to each remote host.
|
||||||
|
if [ "$REMOTE_HOST" ] ; then
|
||||||
|
export REMOTE=$REMOTE_HOST
|
||||||
|
elif [ "$SSH_CLIENT" ] ; then
|
||||||
|
export REMOTE=${SSH_CLIENT%% *}
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Make sure, locally installed binaries are found
|
||||||
|
PATH=$PATH:/usr/local/bin
|
||||||
|
|
||||||
|
# All executables in PLUGINSDIR will simply be executed and their
|
||||||
|
# ouput appended to the output of the agent. Plugins define their own
|
||||||
|
# sections and must output headers with '<<<' and '>>>'
|
||||||
|
PLUGINSDIR=$MK_LIBDIR/plugins
|
||||||
|
|
||||||
|
# All executables in LOCALDIR will by executabled and their
|
||||||
|
# output inserted into the section <<<local>>>. Please
|
||||||
|
# refer to online documentation for details about local checks.
|
||||||
|
LOCALDIR=$MK_LIBDIR/local
|
||||||
|
|
||||||
|
# All files in SPOOLDIR will simply appended to the agent
|
||||||
|
# output if they are not outdated (see below)
|
||||||
|
SPOOLDIR=$MK_VARDIR/spool
|
||||||
|
|
||||||
|
# close standard input (for security reasons) and stderr
|
||||||
|
if [ "$1" = -d ]
|
||||||
|
then
|
||||||
|
set -xv
|
||||||
|
else
|
||||||
|
exec </dev/null 2>/dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Runs a command asynchronous by use of a cache file
|
||||||
|
function run_cached () {
|
||||||
|
local section=
|
||||||
|
if [ "$1" = -s ] ; then local section="echo '<<<$2>>>' ; " ; shift ; fi
|
||||||
|
local NAME=$1
|
||||||
|
local MAXAGE=$2
|
||||||
|
shift 2
|
||||||
|
local CMDLINE="$section$@"
|
||||||
|
|
||||||
|
if [ ! -d $MK_VARDIR/cache ]; then mkdir -p $MK_VARDIR/cache ; fi
|
||||||
|
CACHEFILE="$MK_VARDIR/cache/$NAME.cache"
|
||||||
|
|
||||||
|
# Check if the creation of the cache takes suspiciously long and return
|
||||||
|
# nothing if the age (access time) of $CACHEFILE.new is twice the MAXAGE
|
||||||
|
local NOW=$(date +%s)
|
||||||
|
if [ -e "$CACHEFILE.new" ] ; then
|
||||||
|
local CF_ATIME=$(stat -c %X "$CACHEFILE.new")
|
||||||
|
if [ $((NOW - CF_ATIME)) -ge $((MAXAGE * 2)) ] ; then
|
||||||
|
# Kill the process still accessing that file in case
|
||||||
|
# it is still running. This avoids overlapping processes!
|
||||||
|
fuser -k -9 "$CACHEFILE.new" >/dev/null 2>&1
|
||||||
|
rm -f "$CACHEFILE.new"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if cache file exists and is recent enough
|
||||||
|
if [ -s "$CACHEFILE" ] ; then
|
||||||
|
local MTIME=$(stat -c %Y "$CACHEFILE")
|
||||||
|
if [ $((NOW - MTIME)) -le $MAXAGE ] ; then local USE_CACHEFILE=1 ; fi
|
||||||
|
# Output the file in any case, even if it is
|
||||||
|
# outdated. The new file will not yet be available
|
||||||
|
cat "$CACHEFILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Cache file outdated and new job not yet running? Start it
|
||||||
|
if [ -z "$USE_CACHEFILE" -a ! -e "$CACHEFILE.new" ] ; then
|
||||||
|
echo "set -o noclobber ; exec > \"$CACHEFILE.new\" || exit 1 ; $CMDLINE && mv \"$CACHEFILE.new\" \"$CACHEFILE\" || rm -f \"$CACHEFILE\" \"$CACHEFILE.new\"" | nohup bash >/dev/null 2>&1 &
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Make run_cached available for subshells (plugins, local checks, etc.)
|
||||||
|
export -f run_cached
|
||||||
|
|
||||||
|
echo '<<<check_mk>>>'
|
||||||
|
echo Version: 1.2.6b5
|
||||||
|
echo AgentOS: linux
|
||||||
|
echo AgentDirectory: $MK_CONFDIR
|
||||||
|
echo DataDirectory: $MK_VARDIR
|
||||||
|
echo SpoolDirectory: $SPOOLDIR
|
||||||
|
echo PluginsDirectory: $PLUGINSDIR
|
||||||
|
echo LocalDirectory: $LOCALDIR
|
||||||
|
|
||||||
|
# If we are called via xinetd, try to find only_from configuration
|
||||||
|
if [ -n "$REMOTE_HOST" ]
|
||||||
|
then
|
||||||
|
echo -n 'OnlyFrom: '
|
||||||
|
echo $(sed -n '/^service[[:space:]]*check_mk/,/}/s/^[[:space:]]*only_from[[:space:]]*=[[:space:]]*\(.*\)/\1/p' /etc/xinetd.d/* | head -n1)
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Print out Partitions / Filesystems. (-P gives non-wrapped POSIXed output)
|
||||||
|
# Heads up: NFS-mounts are generally supressed to avoid agent hangs.
|
||||||
|
# If hard NFS mounts are configured or you have too large nfs retry/timeout
|
||||||
|
# settings, accessing those mounts from the agent would leave you with
|
||||||
|
# thousands of agent processes and, ultimately, a dead monitored system.
|
||||||
|
# These should generally be monitored on the NFS server, not on the clients.
|
||||||
|
|
||||||
|
echo '<<<df>>>'
|
||||||
|
# The exclusion list is getting a bit of a problem. -l should hide any remote FS but seems
|
||||||
|
# to be all but working.
|
||||||
|
excludefs="-x smbfs -x cifs -x iso9660 -x udf -x nfsv4 -x nfs -x mvfs -x zfs"
|
||||||
|
df -PTlk $excludefs | sed 1d
|
||||||
|
|
||||||
|
# df inodes information
|
||||||
|
echo '<<<df>>>'
|
||||||
|
echo '[df_inodes_start]'
|
||||||
|
df -PTli $excludefs | sed 1d
|
||||||
|
echo '[df_inodes_end]'
|
||||||
|
|
||||||
|
# Filesystem usage for ZFS
|
||||||
|
if type zfs > /dev/null 2>&1 ; then
|
||||||
|
echo '<<<zfsget>>>'
|
||||||
|
zfs get -Hp name,quota,used,avail,mountpoint,type -t filesystem,volume || \
|
||||||
|
zfs get -Hp name,quota,used,avail,mountpoint,type
|
||||||
|
echo '[df]'
|
||||||
|
df -PTlk -t zfs | sed 1d
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check NFS mounts by accessing them with stat -f (System
|
||||||
|
# call statfs()). If this lasts more then 2 seconds we
|
||||||
|
# consider it as hanging. We need waitmax.
|
||||||
|
if type waitmax >/dev/null
|
||||||
|
then
|
||||||
|
STAT_VERSION=$(stat --version | head -1 | cut -d" " -f4)
|
||||||
|
STAT_BROKE="5.3.0"
|
||||||
|
|
||||||
|
echo '<<<nfsmounts>>>'
|
||||||
|
sed -n '/ nfs4\? /s/[^ ]* \([^ ]*\) .*/\1/p' < /proc/mounts |
|
||||||
|
sed 's/\\040/ /g' |
|
||||||
|
while read MP
|
||||||
|
do
|
||||||
|
if [ $STAT_VERSION != $STAT_BROKE ]; then
|
||||||
|
waitmax -s 9 2 stat -f -c "$MP ok %b %f %a %s" "$MP" || \
|
||||||
|
echo "$MP hanging 0 0 0 0"
|
||||||
|
else
|
||||||
|
waitmax -s 9 2 stat -f -c "$MP ok %b %f %a %s" "$MP" && \
|
||||||
|
printf '\n'|| echo "$MP hanging 0 0 0 0"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo '<<<cifsmounts>>>'
|
||||||
|
sed -n '/ cifs\? /s/[^ ]* \([^ ]*\) .*/\1/p' < /proc/mounts |
|
||||||
|
sed 's/\\040/ /g' |
|
||||||
|
while read MP
|
||||||
|
do
|
||||||
|
if [ $STAT_VERSION != $STAT_BROKE ]; then
|
||||||
|
waitmax -s 9 2 stat -f -c "$MP ok %b %f %a %s" "$MP" || \
|
||||||
|
echo "$MP hanging 0 0 0 0"
|
||||||
|
else
|
||||||
|
waitmax -s 9 2 stat -f -c "$MP ok %b %f %a %s" "$MP" && \
|
||||||
|
printf '\n'|| echo "$MP hanging 0 0 0 0"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check mount options. Filesystems may switch to 'ro' in case
|
||||||
|
# of a read error.
|
||||||
|
echo '<<<mounts>>>'
|
||||||
|
grep ^/dev < /proc/mounts
|
||||||
|
|
||||||
|
# processes including username, without kernel processes
|
||||||
|
echo '<<<ps>>>'
|
||||||
|
ps ax -o user,vsz,rss,cputime,pid,command --columns 10000 | sed -e 1d -e 's/ *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) */(\1,\2,\3,\4,\5) /'
|
||||||
|
|
||||||
|
# Memory usage
|
||||||
|
echo '<<<mem>>>'
|
||||||
|
egrep -v '^Swap:|^Mem:|total:' < /proc/meminfo
|
||||||
|
|
||||||
|
# Load and number of processes
|
||||||
|
echo '<<<cpu>>>'
|
||||||
|
echo "$(cat /proc/loadavg) $(grep -E '^CPU|^processor' < /proc/cpuinfo | wc -l)"
|
||||||
|
|
||||||
|
# Uptime
|
||||||
|
echo '<<<uptime>>>'
|
||||||
|
cat /proc/uptime
|
||||||
|
|
||||||
|
|
||||||
|
# New variant: Information about speed and state in one section
|
||||||
|
echo '<<<lnx_if:sep(58)>>>'
|
||||||
|
sed 1,2d /proc/net/dev
|
||||||
|
if type ethtool > /dev/null
|
||||||
|
then
|
||||||
|
for eth in $(sed -e 1,2d < /proc/net/dev | cut -d':' -f1 | sort)
|
||||||
|
do
|
||||||
|
echo "[$eth]"
|
||||||
|
ethtool $eth | egrep '(Speed|Duplex|Link detected|Auto-negotiation):'
|
||||||
|
echo -en "\tAddress: " ; cat /sys/class/net/$eth/address ; echo
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Current state of bonding interfaces
|
||||||
|
if [ -e /proc/net/bonding ] ; then
|
||||||
|
echo '<<<lnx_bonding:sep(58)>>>'
|
||||||
|
pushd /proc/net/bonding > /dev/null ; head -v -n 1000 * ; popd
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Same for Open vSwitch bonding
|
||||||
|
if type ovs-appctl > /dev/null ; then
|
||||||
|
echo '<<<ovs_bonding:sep(58)>>>'
|
||||||
|
for bond in $(ovs-appctl bond/list | sed -e 1d | cut -f2) ; do
|
||||||
|
echo "[$bond]"
|
||||||
|
ovs-appctl bond/show $bond
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Number of TCP connections in the various states
|
||||||
|
echo '<<<tcp_conn_stats>>>'
|
||||||
|
# waitmax 10 netstat -nt | awk ' /^tcp/ { c[$6]++; } END { for (x in c) { print x, c[x]; } }'
|
||||||
|
# New implementation: netstat is very slow for large TCP tables
|
||||||
|
cat /proc/net/tcp /proc/net/tcp6 2>/dev/null | awk ' /:/ { c[$4]++; } END { for (x in c) { print x, c[x]; } }'
|
||||||
|
|
||||||
|
# Linux Multipathing
|
||||||
|
if type multipath >/dev/null ; then
|
||||||
|
echo '<<<multipath>>>'
|
||||||
|
multipath -l
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Performancecounter Platten
|
||||||
|
echo '<<<diskstat>>>'
|
||||||
|
date +%s
|
||||||
|
egrep ' (x?[shv]d[a-z]*|cciss/c[0-9]+d[0-9]+|emcpower[a-z]+|dm-[0-9]+|VxVM.*|mmcblk.*) ' < /proc/diskstats
|
||||||
|
if type dmsetup >/dev/null ; then
|
||||||
|
echo '[dmsetup_info]'
|
||||||
|
dmsetup info -c --noheadings --separator ' ' -o name,devno,vg_name,lv_name
|
||||||
|
fi
|
||||||
|
if [ -d /dev/vx/dsk ] ; then
|
||||||
|
echo '[vx_dsk]'
|
||||||
|
stat -c "%t %T %n" /dev/vx/dsk/*/*
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Performancecounter Kernel
|
||||||
|
echo '<<<kernel>>>'
|
||||||
|
date +%s
|
||||||
|
cat /proc/vmstat /proc/stat
|
||||||
|
|
||||||
|
# Hardware sensors via IPMI (need ipmitool)
|
||||||
|
if type ipmitool > /dev/null
|
||||||
|
then
|
||||||
|
run_cached -s ipmi 300 "ipmitool sensor list | grep -v 'command failed' | sed -e 's/ *| */|/g' -e 's/ /_/g' -e 's/_*"'$'"//' -e 's/|/ /g' | egrep -v '^[^ ]+ na ' | grep -v ' discrete '"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# IPMI data via ipmi-sensors (of freeipmi). Please make sure, that if you
|
||||||
|
# have installed freeipmi that IPMI is really support by your hardware.
|
||||||
|
if type ipmi-sensors >/dev/null
|
||||||
|
then
|
||||||
|
echo '<<<ipmi_sensors>>>'
|
||||||
|
# Newer ipmi-sensors version have new output format; Legacy format can be used
|
||||||
|
if ipmi-sensors --help | grep -q legacy-output; then
|
||||||
|
IPMI_FORMAT="--legacy-output"
|
||||||
|
else
|
||||||
|
IPMI_FORMAT=""
|
||||||
|
fi
|
||||||
|
# At least with ipmi-sensoirs 0.7.16 this group is Power_Unit instead of "Power Unit"
|
||||||
|
run_cached -s ipmi_sensors 300 "for class in Temperature Power_Unit Fan
|
||||||
|
do
|
||||||
|
ipmi-sensors $IPMI_FORMAT --sdr-cache-directory /var/cache -g "$class" | sed -e 's/ /_/g' -e 's/:_\?/ /g' -e 's@ \([^(]*\)_(\([^)]*\))@ \2_\1@'
|
||||||
|
# In case of a timeout immediately leave loop.
|
||||||
|
if [ $? = 255 ] ; then break ; fi
|
||||||
|
done"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# RAID status of Linux software RAID
|
||||||
|
echo '<<<md>>>'
|
||||||
|
cat /proc/mdstat
|
||||||
|
|
||||||
|
# RAID status of Linux RAID via device mapper
|
||||||
|
if type dmraid >/dev/null && DMSTATUS=$(dmraid -r)
|
||||||
|
then
|
||||||
|
echo '<<<dmraid>>>'
|
||||||
|
|
||||||
|
# Output name and status
|
||||||
|
dmraid -s | grep -e ^name -e ^status
|
||||||
|
|
||||||
|
# Output disk names of the RAID disks
|
||||||
|
DISKS=$(echo "$DMSTATUS" | cut -f1 -d\:)
|
||||||
|
|
||||||
|
for disk in $DISKS ; do
|
||||||
|
device=$(cat /sys/block/$(basename $disk)/device/model )
|
||||||
|
status=$(echo "$DMSTATUS" | grep ^${disk})
|
||||||
|
echo "$status Model: $device"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# RAID status of LSI controllers via cfggen
|
||||||
|
if type cfggen > /dev/null ; then
|
||||||
|
echo '<<<lsi>>>'
|
||||||
|
cfggen 0 DISPLAY | egrep '(Target ID|State|Volume ID|Status of volume)[[:space:]]*:' | sed -e 's/ *//g' -e 's/:/ /'
|
||||||
|
fi
|
||||||
|
|
||||||
|
# RAID status of LSI MegaRAID controller via MegaCli. You can download that tool from:
|
||||||
|
# http://www.lsi.com/downloads/Public/MegaRAID%20Common%20Files/8.02.16_MegaCLI.zip
|
||||||
|
if type MegaCli >/dev/null ; then
|
||||||
|
MegaCli_bin="MegaCli"
|
||||||
|
elif type MegaCli64 >/dev/null ; then
|
||||||
|
MegaCli_bin="MegaCli64"
|
||||||
|
elif type megacli >/dev/null ; then
|
||||||
|
MegaCli_bin="megacli"
|
||||||
|
else
|
||||||
|
MegaCli_bin="unknown"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$MegaCli_bin" != "unknown" ]; then
|
||||||
|
echo '<<<megaraid_pdisks>>>'
|
||||||
|
for part in $($MegaCli_bin -EncInfo -aALL -NoLog < /dev/null \
|
||||||
|
| sed -rn 's/:/ /g; s/[[:space:]]+/ /g; s/^ //; s/ $//; s/Number of enclosures on adapter ([0-9]+).*/adapter \1/g; /^(Enclosure|Device ID|adapter) [0-9]+$/ p'); do
|
||||||
|
[ $part = adapter ] && echo ""
|
||||||
|
[ $part = 'Enclosure' ] && echo -ne "\ndev2enc"
|
||||||
|
echo -n " $part"
|
||||||
|
done
|
||||||
|
echo
|
||||||
|
$MegaCli_bin -PDList -aALL -NoLog < /dev/null | egrep 'Enclosure|Raw Size|Slot Number|Device Id|Firmware state|Inquiry|Adapter'
|
||||||
|
echo '<<<megaraid_ldisks>>>'
|
||||||
|
$MegaCli_bin -LDInfo -Lall -aALL -NoLog < /dev/null | egrep 'Size|State|Number|Adapter|Virtual'
|
||||||
|
echo '<<<megaraid_bbu>>>'
|
||||||
|
$MegaCli_bin -AdpBbuCmd -GetBbuStatus -aALL -NoLog < /dev/null | grep -v Exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
# RAID status of 3WARE disk controller (by Radoslaw Bak)
|
||||||
|
if type tw_cli > /dev/null ; then
|
||||||
|
for C in $(tw_cli show | awk 'NR < 4 { next } { print $1 }'); do
|
||||||
|
echo '<<<3ware_info>>>'
|
||||||
|
tw_cli /$C show all | egrep 'Model =|Firmware|Serial'
|
||||||
|
echo '<<<3ware_disks>>>'
|
||||||
|
tw_cli /$C show drivestatus | egrep 'p[0-9]' | sed "s/^/$C\//"
|
||||||
|
echo '<<<3ware_units>>>'
|
||||||
|
tw_cli /$C show unitstatus | egrep 'u[0-9]' | sed "s/^/$C\//"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# RAID controllers from areca (Taiwan)
|
||||||
|
# cli64 can be found at ftp://ftp.areca.com.tw/RaidCards/AP_Drivers/Linux/CLI/
|
||||||
|
if type cli64 >/dev/null ; then
|
||||||
|
run_cached -s arc_raid_status 300 "cli64 rsf info | tail -n +3 | head -n -2"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# VirtualBox Guests. Section must always been output. Otherwise the
|
||||||
|
# check would not be executed in case no guest additions are installed.
|
||||||
|
# And that is something the check wants to detect
|
||||||
|
echo '<<<vbox_guest>>>'
|
||||||
|
if type VBoxControl >/dev/null 2>&1 ; then
|
||||||
|
VBoxControl -nologo guestproperty enumerate | cut -d, -f1,2
|
||||||
|
[ ${PIPESTATUS[0]} = 0 ] || echo "ERROR"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# OpenVPN Clients. Currently we assume that the configuration # is in
|
||||||
|
# /etc/openvpn. We might find a safer way to find the configuration later.
|
||||||
|
if [ -e /etc/openvpn/openvpn-status.log ] ; then
|
||||||
|
echo '<<<openvpn_clients:sep(44)>>>'
|
||||||
|
sed -n -e '/CLIENT LIST/,/ROUTING TABLE/p' < /etc/openvpn/openvpn-status.log | sed -e 1,3d -e '$d'
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Time synchronization with NTP
|
||||||
|
if type ntpq > /dev/null 2>&1 ; then
|
||||||
|
# remove heading, make first column space separated
|
||||||
|
run_cached -s ntp 30 "waitmax 5 ntpq -np | sed -e 1,2d -e 's/^\(.\)/\1 /' -e 's/^ /%/'"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Time synchronization with Chrony
|
||||||
|
if type chronyc > /dev/null 2>&1 ; then
|
||||||
|
# Force successful exit code. Otherwise section will be missing if daemon not running
|
||||||
|
run_cached -s chrony 30 "waitmax 5 chronyc tracking || true"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if type nvidia-settings >/dev/null && [ -S /tmp/.X11-unix/X0 ]
|
||||||
|
then
|
||||||
|
echo '<<<nvidia>>>'
|
||||||
|
for var in GPUErrors GPUCoreTemp
|
||||||
|
do
|
||||||
|
DISPLAY=:0 waitmax 2 nvidia-settings -t -q $var | sed "s/^/$var: /"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -e /proc/drbd ]; then
|
||||||
|
echo '<<<drbd>>>'
|
||||||
|
cat /proc/drbd
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Status of CUPS printer queues
|
||||||
|
if type lpstat > /dev/null 2>&1; then
|
||||||
|
if pgrep cups > /dev/null 2>&1; then
|
||||||
|
echo '<<<cups_queues>>>'
|
||||||
|
CPRINTCONF=/etc/cups/printers.conf
|
||||||
|
if [ -r "$CPRINTCONF" ] ; then
|
||||||
|
LOCAL_PRINTERS=$(grep -E "<(Default)?Printer .*>" $CPRINTCONF | awk '{print $2}' | sed -e 's/>//')
|
||||||
|
lpstat -p | while read LINE
|
||||||
|
do
|
||||||
|
PRINTER=$(echo $LINE | awk '{print $2}')
|
||||||
|
if echo "$LOCAL_PRINTERS" | grep -q "$PRINTER"; then
|
||||||
|
echo $LINE
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
echo '---'
|
||||||
|
lpstat -o | while read LINE
|
||||||
|
do
|
||||||
|
PRINTER=${LINE%%-*}
|
||||||
|
if echo "$LOCAL_PRINTERS" | grep -q "$PRINTER"; then
|
||||||
|
echo $LINE
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
else
|
||||||
|
lpstat -p
|
||||||
|
echo '---'
|
||||||
|
lpstat -o | sort
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Heartbeat monitoring
|
||||||
|
# Different handling for heartbeat clusters with and without CRM
|
||||||
|
# for the resource state
|
||||||
|
if [ -S /var/run/heartbeat/crm/cib_ro -o -S /var/run/crm/cib_ro ] || pgrep crmd > /dev/null 2>&1; then
|
||||||
|
echo '<<<heartbeat_crm>>>'
|
||||||
|
crm_mon -1 -r | grep -v ^$ | sed 's/^ //; /^\sResource Group:/,$ s/^\s//; s/^\s/_/g'
|
||||||
|
fi
|
||||||
|
if type cl_status > /dev/null 2>&1; then
|
||||||
|
echo '<<<heartbeat_rscstatus>>>'
|
||||||
|
cl_status rscstatus
|
||||||
|
|
||||||
|
echo '<<<heartbeat_nodes>>>'
|
||||||
|
for NODE in $(cl_status listnodes); do
|
||||||
|
if [ $NODE != $(echo $HOSTNAME | tr 'A-Z' 'a-z') ]; then
|
||||||
|
STATUS=$(cl_status nodestatus $NODE)
|
||||||
|
echo -n "$NODE $STATUS"
|
||||||
|
for LINK in $(cl_status listhblinks $NODE 2>/dev/null); do
|
||||||
|
echo -n " $LINK $(cl_status hblinkstatus $NODE $LINK)"
|
||||||
|
done
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Postfix mailqueue monitoring
|
||||||
|
#
|
||||||
|
# Only handle mailq when postfix user is present. The mailq command is also
|
||||||
|
# available when postfix is not installed. But it produces different outputs
|
||||||
|
# which are not handled by the check at the moment. So try to filter out the
|
||||||
|
# systems not using postfix by searching for the postfix user.a
|
||||||
|
#
|
||||||
|
# Cannot take the whole outout. This could produce several MB of agent output
|
||||||
|
# on blocking queues.
|
||||||
|
# Only handle the last 6 lines (includes the summary line at the bottom and
|
||||||
|
# the last message in the queue. The last message is not used at the moment
|
||||||
|
# but it could be used to get the timestamp of the last message.
|
||||||
|
if type postconf >/dev/null ; then
|
||||||
|
echo '<<<postfix_mailq>>>'
|
||||||
|
postfix_queue_dir=$(postconf -h queue_directory)
|
||||||
|
postfix_count=$(find $postfix_queue_dir/deferred -type f | wc -l)
|
||||||
|
postfix_size=$(du -ks $postfix_queue_dir/deferred | awk '{print $1 }')
|
||||||
|
if [ $postfix_count -gt 0 ]
|
||||||
|
then
|
||||||
|
echo -- $postfix_size Kbytes in $postfix_count Requests.
|
||||||
|
else
|
||||||
|
echo Mail queue is empty
|
||||||
|
fi
|
||||||
|
elif [ -x /usr/sbin/ssmtp ] ; then
|
||||||
|
echo '<<<postfix_mailq>>>'
|
||||||
|
mailq 2>&1 | sed 's/^[^:]*: \(.*\)/\1/' | tail -n 6
|
||||||
|
fi
|
||||||
|
|
||||||
|
#Check status of qmail mailqueue
|
||||||
|
if type qmail-qstat >/dev/null
|
||||||
|
then
|
||||||
|
echo "<<<qmail_stats>>>"
|
||||||
|
qmail-qstat
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check status of OMD sites
|
||||||
|
if type omd >/dev/null
|
||||||
|
then
|
||||||
|
run_cached -s omd_status 60 "omd status --bare --auto"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Welcome the ZFS check on Linux
|
||||||
|
# We do not endorse running ZFS on linux if your vendor doesnt support it ;)
|
||||||
|
# check zpool status
|
||||||
|
if type zpool >/dev/null; then
|
||||||
|
echo "<<<zpool_status>>>"
|
||||||
|
zpool status -x
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Fileinfo-Check: put patterns for files into /etc/check_mk/fileinfo.cfg
|
||||||
|
if [ -r "$MK_CONFDIR/fileinfo.cfg" ] ; then
|
||||||
|
echo '<<<fileinfo:sep(124)>>>'
|
||||||
|
date +%s
|
||||||
|
stat -c "%n|%s|%Y" $(cat "$MK_CONFDIR/fileinfo.cfg")
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get stats about OMD monitoring cores running on this machine.
|
||||||
|
# Since cd is a shell builtin the check does not affect the performance
|
||||||
|
# on non-OMD machines.
|
||||||
|
if cd /omd/sites
|
||||||
|
then
|
||||||
|
echo '<<<livestatus_status:sep(59)>>>'
|
||||||
|
for site in *
|
||||||
|
do
|
||||||
|
if [ -S "/omd/sites/$site/tmp/run/live" ] ; then
|
||||||
|
echo "[$site]"
|
||||||
|
echo -e "GET status" | waitmax 3 /omd/sites/$site/bin/unixcat /omd/sites/$site/tmp/run/live
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get statistics about monitored jobs. Below the job directory there
|
||||||
|
# is a sub directory per user that ran a job. That directory must be
|
||||||
|
# owned by the user so that a symlink or hardlink attack for reading
|
||||||
|
# arbitrary files can be avoided.
|
||||||
|
if pushd $MK_VARDIR/job >/dev/null; then
|
||||||
|
echo '<<<job>>>'
|
||||||
|
for username in *
|
||||||
|
do
|
||||||
|
if [ -d "$username" ] && cd "$username" ; then
|
||||||
|
su "$username" -c "head -n -0 -v *"
|
||||||
|
cd ..
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
popd > /dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Gather thermal information provided e.g. by acpi
|
||||||
|
# At the moment only supporting thermal sensors
|
||||||
|
if ls /sys/class/thermal/thermal_zone* >/dev/null 2>&1; then
|
||||||
|
echo '<<<lnx_thermal>>>'
|
||||||
|
for F in /sys/class/thermal/thermal_zone*; do
|
||||||
|
echo -n "${F##*/} "
|
||||||
|
if [ ! -e $F/mode ] ; then echo -n "- " ; fi
|
||||||
|
cat $F/{mode,type,temp,trip_point_*} | tr \\n " "
|
||||||
|
echo
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Libelle Business Shadow
|
||||||
|
if type trd >/dev/null; then
|
||||||
|
echo "<<<libelle_business_shadow:sep(58)>>>"
|
||||||
|
trd -s
|
||||||
|
fi
|
||||||
|
|
||||||
|
# MK's Remote Plugin Executor
|
||||||
|
if [ -e "$MK_CONFDIR/mrpe.cfg" ]
|
||||||
|
then
|
||||||
|
echo '<<<mrpe>>>'
|
||||||
|
grep -Ev '^[[:space:]]*($|#)' "$MK_CONFDIR/mrpe.cfg" | \
|
||||||
|
while read descr cmdline
|
||||||
|
do
|
||||||
|
PLUGIN=${cmdline%% *}
|
||||||
|
OUTPUT=$(eval "$cmdline")
|
||||||
|
echo -n "(${PLUGIN##*/}) $descr $? $OUTPUT" | tr \\n \\1
|
||||||
|
echo
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Local checks
|
||||||
|
echo '<<<local>>>'
|
||||||
|
if cd $LOCALDIR ; then
|
||||||
|
for skript in $(ls) ; do
|
||||||
|
if [ -f "$skript" -a -x "$skript" ] ; then
|
||||||
|
./$skript
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
# Call some plugins only every X'th minute
|
||||||
|
for skript in [1-9]*/* ; do
|
||||||
|
if [ -x "$skript" ] ; then
|
||||||
|
run_cached local_${skript//\//\\} ${skript%/*} "$skript"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Plugins
|
||||||
|
if cd $PLUGINSDIR ; then
|
||||||
|
for skript in $(ls) ; do
|
||||||
|
if [ -f "$skript" -a -x "$skript" ] ; then
|
||||||
|
./$skript
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
# Call some plugins only every Xth minute
|
||||||
|
for skript in [1-9]*/* ; do
|
||||||
|
if [ -x "$skript" ] ; then
|
||||||
|
run_cached plugins_${skript//\//\\} ${skript%/*} "$skript"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Agent output snippets created by cronjobs, etc.
|
||||||
|
if [ -d "$SPOOLDIR" ]
|
||||||
|
then
|
||||||
|
pushd "$SPOOLDIR" > /dev/null
|
||||||
|
now=$(date +%s)
|
||||||
|
|
||||||
|
for file in *
|
||||||
|
do
|
||||||
|
# output every file in this directory. If the file is prefixed
|
||||||
|
# with a number, then that number is the maximum age of the
|
||||||
|
# file in seconds. If the file is older than that, it is ignored.
|
||||||
|
maxage=""
|
||||||
|
part="$file"
|
||||||
|
|
||||||
|
# Each away all digits from the front of the filename and
|
||||||
|
# collect them in the variable maxage.
|
||||||
|
while [ "${part/#[0-9]/}" != "$part" ]
|
||||||
|
do
|
||||||
|
maxage=$maxage${part:0:1}
|
||||||
|
part=${part:1}
|
||||||
|
done
|
||||||
|
|
||||||
|
# If there is at least one digit, than we honor that.
|
||||||
|
if [ "$maxage" ] ; then
|
||||||
|
mtime=$(stat -c %Y "$file")
|
||||||
|
if [ $((now - mtime)) -gt $maxage ] ; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Output the file
|
||||||
|
cat "$file"
|
||||||
|
done
|
||||||
|
popd > /dev/null
|
||||||
|
fi
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Detects which OS and if it is Linux then it will detect which Linux Distribution.
|
||||||
|
|
||||||
|
OS=`uname -s`
|
||||||
|
REV=`uname -r`
|
||||||
|
MACH=`uname -m`
|
||||||
|
|
||||||
|
if [ "${OS}" = "SunOS" ] ; then
|
||||||
|
OS=Solaris
|
||||||
|
ARCH=`uname -p`
|
||||||
|
OSSTR="${OS} ${REV}(${ARCH} `uname -v`)"
|
||||||
|
|
||||||
|
elif [ "${OS}" = "AIX" ] ; then
|
||||||
|
OSSTR="${OS} `oslevel` (`oslevel -r`)"
|
||||||
|
|
||||||
|
elif [ "${OS}" = "Linux" ] ; then
|
||||||
|
KERNEL=`uname -r`
|
||||||
|
|
||||||
|
if [ -f /etc/fedora-release ]; then
|
||||||
|
DIST=$(cat /etc/fedora-release | awk '{print $1}')
|
||||||
|
REV=`cat /etc/fedora-release | sed s/.*release\ // | sed s/\ .*//`
|
||||||
|
|
||||||
|
elif [ -f /etc/redhat-release ] ; then
|
||||||
|
DIST=$(cat /etc/redhat-release | awk '{print $1}')
|
||||||
|
if [ "${DIST}" = "CentOS" ]; then
|
||||||
|
DIST="CentOS"
|
||||||
|
elif [ "${DIST}" = "Mandriva" ]; then
|
||||||
|
DIST="Mandriva"
|
||||||
|
PSEUDONAME=`cat /etc/mandriva-release | sed s/.*\(// | sed s/\)//`
|
||||||
|
REV=`cat /etc/mandriva-release | sed s/.*release\ // | sed s/\ .*//`
|
||||||
|
elif [ -f /etc/oracle-release ]; then
|
||||||
|
DIST="Oracle"
|
||||||
|
else
|
||||||
|
DIST="RedHat"
|
||||||
|
fi
|
||||||
|
|
||||||
|
PSEUDONAME=`cat /etc/redhat-release | sed s/.*\(// | sed s/\)//`
|
||||||
|
REV=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//`
|
||||||
|
|
||||||
|
elif [ -f /etc/mandrake-release ] ; then
|
||||||
|
DIST='Mandrake'
|
||||||
|
PSEUDONAME=`cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//`
|
||||||
|
REV=`cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//`
|
||||||
|
|
||||||
|
elif [ -f /etc/devuan_version ] ; then
|
||||||
|
DIST="Devuan `cat /etc/devuan_version`"
|
||||||
|
REV=""
|
||||||
|
|
||||||
|
elif [ -f /etc/debian_version ] ; then
|
||||||
|
DIST="Debian `cat /etc/debian_version`"
|
||||||
|
REV=""
|
||||||
|
ID=`lsb_release -i | awk -F ':' '{print $2}' | sed 's/ //g'`
|
||||||
|
if [ "${ID}" = "Raspbian" ] ; then
|
||||||
|
DIST="Raspbian `cat /etc/debian_version`"
|
||||||
|
fi
|
||||||
|
|
||||||
|
elif [ -f /etc/gentoo-release ] ; then
|
||||||
|
DIST="Gentoo"
|
||||||
|
REV=$(tr -d '[[:alpha:]]' </etc/gentoo-release | tr -d " ")
|
||||||
|
|
||||||
|
elif [ -f /etc/arch-release ] ; then
|
||||||
|
DIST="Arch Linux"
|
||||||
|
REV="" # Omit version since Arch Linux uses rolling releases
|
||||||
|
IGNORE_LSB=1 # /etc/lsb-release would overwrite $REV with "rolling"
|
||||||
|
|
||||||
|
elif [ -f /etc/os-release ] ; then
|
||||||
|
DIST=$(grep '^NAME=' /etc/os-release | cut -d= -f2- | tr -d '"')
|
||||||
|
REV=$(grep '^VERSION_ID=' /etc/os-release | cut -d= -f2- | tr -d '"')
|
||||||
|
|
||||||
|
elif [ -f /etc/openwrt_version ] ; then
|
||||||
|
DIST="OpenWrt"
|
||||||
|
REV=$(cat /etc/openwrt_version)
|
||||||
|
|
||||||
|
elif [ -f /etc/pld-release ] ; then
|
||||||
|
DIST=$(cat /etc/pld-release)
|
||||||
|
REV=""
|
||||||
|
|
||||||
|
elif [ -f /etc/SuSE-release ] ; then
|
||||||
|
DIST=$(echo SLES $(grep VERSION /etc/SuSE-release | cut -d = -f 2 | tr -d " "))
|
||||||
|
REV=$(echo SP$(grep PATCHLEVEL /etc/SuSE-release | cut -d = -f 2 | tr -d " "))
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f /etc/lsb-release -a "${IGNORE_LSB}" != 1 ] ; then
|
||||||
|
LSB_DIST=$(lsb_release -si)
|
||||||
|
LSB_REV=$(lsb_release -sr)
|
||||||
|
if [ "$LSB_DIST" != "" ] ; then
|
||||||
|
DIST=$LSB_DIST
|
||||||
|
fi
|
||||||
|
if [ "$LSB_REV" != "" ] ; then
|
||||||
|
REV=$LSB_REV
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "`uname -a | awk '{print $(NF)}'`" = "DD-WRT" ] ; then
|
||||||
|
DIST="dd-wrt"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "${REV}" ]
|
||||||
|
then
|
||||||
|
OSSTR="${DIST} ${REV}"
|
||||||
|
else
|
||||||
|
OSSTR="${DIST}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
elif [ "${OS}" = "Darwin" ] ; then
|
||||||
|
if [ -f /usr/bin/sw_vers ] ; then
|
||||||
|
OSSTR=`/usr/bin/sw_vers|grep -v Build|sed 's/^.*:.//'| tr "\n" ' '`
|
||||||
|
fi
|
||||||
|
|
||||||
|
elif [ "${OS}" = "FreeBSD" ] ; then
|
||||||
|
OSSTR=`/usr/bin/uname -mior`
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ${OSSTR}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
echo '<<<dmi>>>'
|
||||||
|
|
||||||
|
# requires dmidecode
|
||||||
|
for FIELD in bios-vendor bios-version bios-release-date system-manufacturer system-product-name system-version system-serial-number system-uuid baseboard-manufacturer baseboard-product-name baseboard-version baseboard-serial-number baseboard-asset-tag chassis-manufacturer chassis-type chassis-version chassis-serial-number chassis-asset-tag processor-family processor-manufacturer processor-version processor-frequency
|
||||||
|
do
|
||||||
|
echo $FIELD="$(dmidecode -s $FIELD | grep -v '^#')"
|
||||||
|
done
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Cache the file for 30 minutes
|
||||||
|
# If you want to override this, put the command in cron.
|
||||||
|
# We cache because it is a 1sec delay, which is painful for the poller
|
||||||
|
if [ -x /usr/bin/dpkg-query ]; then
|
||||||
|
DATE=$(date +%s)
|
||||||
|
FILE=/var/cache/librenms/agent-local-dpkg
|
||||||
|
|
||||||
|
[ -d /var/cache/librenms ] || mkdir -p /var/cache/librenms
|
||||||
|
|
||||||
|
if [ ! -e "$FILE" ]; then
|
||||||
|
dpkg-query -W --showformat='${Status} ${Package} ${Version} ${Architecture} ${Installed-Size}\n'|grep " installed "|cut -d\ -f4- > "$FILE"
|
||||||
|
fi
|
||||||
|
FILEMTIME=$(stat -c %Y "$FILE")
|
||||||
|
FILEAGE=$((DATE - FILEMTIME))
|
||||||
|
if [ "$FILEAGE" -gt 1800 ]; then
|
||||||
|
dpkg-query -W --showformat='${Status} ${Package} ${Version} ${Architecture} ${Installed-Size}\n'|grep " installed "|cut -d\ -f4- > "$FILE"
|
||||||
|
fi
|
||||||
|
echo "<<<dpkg>>>"
|
||||||
|
cat "$FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,34 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Please make sure the paths below are correct.
|
||||||
|
# Alternatively you can put them in $0.conf, meaning if you've named
|
||||||
|
# this script ntp-client then it must go in ntp-client.conf .
|
||||||
|
#
|
||||||
|
# NTPQV output version of "ntpq -c rv"
|
||||||
|
# Version 4 is the most common and up to date version.
|
||||||
|
#
|
||||||
|
# If you are unsure, which to set, run this script and make sure that
|
||||||
|
# the JSON output variables match that in "ntpq -c rv".
|
||||||
|
#
|
||||||
|
################################################################
|
||||||
|
# Don't change anything unless you know what are you doing #
|
||||||
|
################################################################
|
||||||
|
BIN_NTPQ='/usr/bin/env ntpq'
|
||||||
|
BIN_GREP='/usr/bin/env grep'
|
||||||
|
BIN_AWK='/usr/bin/env awk'
|
||||||
|
|
||||||
|
CONFIG=$0".conf"
|
||||||
|
if [ -f "$CONFIG" ]; then
|
||||||
|
# shellcheck disable=SC1090
|
||||||
|
. "$CONFIG"
|
||||||
|
fi
|
||||||
|
|
||||||
|
NTP_OFFSET=$($BIN_NTPQ -c rv | $BIN_GREP "offset" | $BIN_AWK -Foffset= '{print $2}' | $BIN_AWK -F, '{print $1}')
|
||||||
|
NTP_FREQUENCY=$($BIN_NTPQ -c rv | $BIN_GREP "frequency" | $BIN_AWK -Ffrequency= '{print $2}' | $BIN_AWK -F, '{print $1}')
|
||||||
|
NTP_SYS_JITTER=$($BIN_NTPQ -c rv | $BIN_GREP "sys_jitter" | $BIN_AWK -Fsys_jitter= '{print $2}' | $BIN_AWK -F, '{print $1}')
|
||||||
|
NTP_CLK_JITTER=$($BIN_NTPQ -c rv | $BIN_GREP "clk_jitter" | $BIN_AWK -Fclk_jitter= '{print $2}' | $BIN_AWK -F, '{print $1}')
|
||||||
|
NTP_WANDER=$($BIN_NTPQ -c rv | $BIN_GREP "clk_wander" | $BIN_AWK -Fclk_wander= '{print $2}' | $BIN_AWK -F, '{print $1}')
|
||||||
|
NTP_VERSION=$($BIN_NTPQ -c rv | $BIN_GREP "version" | $BIN_AWK -F'ntpd ' '{print $2}' | $BIN_AWK -F. '{print $1}')
|
||||||
|
|
||||||
|
echo '{"data":{"offset":"'"$NTP_OFFSET"'","frequency":"'"$NTP_FREQUENCY"'","sys_jitter":"'"$NTP_SYS_JITTER"'","clk_jitter":"'"$NTP_CLK_JITTER"'","clk_wander":"'"$NTP_WANDER"'"},"version":"'"$NTP_VERSION"'","error":"0","errorString":""}'
|
||||||
|
|
||||||
|
exit 0
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Please make sure the paths below are correct.
|
||||||
|
# shellcheck disable=SC2016 # AWK program strings — $BIN_AWK indirection hides awk from shellcheck
|
||||||
|
# Alternatively you can put them in $0.conf, meaning if you've named
|
||||||
|
# this script ntp-client.sh then it must go in ntp-client.sh.conf .
|
||||||
|
#
|
||||||
|
# NTPQV output version of "ntpq -c rv"
|
||||||
|
# p1 DD-WRT and some other outdated linux distros
|
||||||
|
# p11 FreeBSD 11 and any linux distro that is up to date
|
||||||
|
#
|
||||||
|
# If you are unsure, which to set, run this script and make sure that
|
||||||
|
# the JSON output variables match that in "ntpq -c rv".
|
||||||
|
#
|
||||||
|
BIN_NTPD='/usr/bin/env ntpd'
|
||||||
|
BIN_NTPQ='/usr/bin/env ntpq'
|
||||||
|
BIN_NTPDC='/usr/bin/env ntpdc'
|
||||||
|
BIN_GREP='/usr/bin/env grep'
|
||||||
|
BIN_TR='/usr/bin/env tr'
|
||||||
|
BIN_CUT='/usr/bin/env cut'
|
||||||
|
BIN_SED="/usr/bin/env sed"
|
||||||
|
BIN_AWK='/usr/bin/env awk'
|
||||||
|
NTPQV="p11"
|
||||||
|
################################################################
|
||||||
|
# Don't change anything unless you know what are you doing #
|
||||||
|
################################################################
|
||||||
|
CONFIG="$0.conf"
|
||||||
|
if [ -f "$CONFIG" ]; then
|
||||||
|
. "$CONFIG"
|
||||||
|
fi
|
||||||
|
VERSION=1
|
||||||
|
|
||||||
|
STRATUM=$("$BIN_NTPQ" -c rv | "$BIN_GREP" -Eow "stratum=[0-9]+" | "$BIN_CUT" -d "=" -f 2)
|
||||||
|
|
||||||
|
# parse the ntpq info that requires version specific info
|
||||||
|
NTPQ_RAW=$("$BIN_NTPQ" -c rv | "$BIN_GREP" jitter | "$BIN_SED" 's/[[:alpha:]=,_]/ /g')
|
||||||
|
if [ "$NTPQV" = "p11" ]; then
|
||||||
|
OFFSET=$(echo "$NTPQ_RAW" | "$BIN_AWK" -F ' ' '{print $3}')
|
||||||
|
FREQUENCY=$(echo "$NTPQ_RAW" | "$BIN_AWK" -F ' ' '{print $4}')
|
||||||
|
SYS_JITTER=$(echo "$NTPQ_RAW" | "$BIN_AWK" -F ' ' '{print $5}')
|
||||||
|
CLK_JITTER=$(echo "$NTPQ_RAW" | "$BIN_AWK" -F ' ' '{print $6}')
|
||||||
|
CLK_WANDER=$(echo "$NTPQ_RAW" | "$BIN_AWK" -F ' ' '{print $7}')
|
||||||
|
fi
|
||||||
|
if [ "$NTPQV" = "p1" ]; then
|
||||||
|
OFFSET=$(echo "$NTPQ_RAW" | "$BIN_AWK" -F ' ' '{print $2}')
|
||||||
|
FREQUENCY=$(echo "$NTPQ_RAW" | "$BIN_AWK" -F ' ' '{print $3}')
|
||||||
|
SYS_JITTER=$(echo "$NTPQ_RAW" | "$BIN_AWK" -F ' ' '{print $4}')
|
||||||
|
CLK_JITTER=$(echo "$NTPQ_RAW" | "$BIN_AWK" -F ' ' '{print $5}')
|
||||||
|
CLK_WANDER=$(echo "$NTPQ_RAW" | "$BIN_AWK" -F ' ' '{print $6}')
|
||||||
|
fi
|
||||||
|
|
||||||
|
VER=$("$BIN_NTPD" --version)
|
||||||
|
if [ "$VER" = '4.2.6p5' ]; then
|
||||||
|
USECMD="$BIN_NTPDC -c iostats"
|
||||||
|
else
|
||||||
|
USECMD="$BIN_NTPQ -c iostats localhost"
|
||||||
|
fi
|
||||||
|
CMD2=$($USECMD | "$BIN_TR" -d ' ' | "$BIN_CUT" -d : -f 2 | "$BIN_TR" '\n' ' ')
|
||||||
|
|
||||||
|
TIMESINCERESET=$(echo "$CMD2" | "$BIN_AWK" -F ' ' '{print $1}')
|
||||||
|
RECEIVEDBUFFERS=$(echo "$CMD2" | "$BIN_AWK" -F ' ' '{print $2}')
|
||||||
|
FREERECEIVEBUFFERS=$(echo "$CMD2" | "$BIN_AWK" -F ' ' '{print $3}')
|
||||||
|
USEDRECEIVEBUFFERS=$(echo "$CMD2" | "$BIN_AWK" -F ' ' '{print $4}')
|
||||||
|
LOWWATERREFILLS=$(echo "$CMD2" | "$BIN_AWK" -F ' ' '{print $5}')
|
||||||
|
DROPPEDPACKETS=$(echo "$CMD2" | "$BIN_AWK" -F ' ' '{print $6}')
|
||||||
|
IGNOREDPACKETS=$(echo "$CMD2" | "$BIN_AWK" -F ' ' '{print $7}')
|
||||||
|
RECEIVEDPACKETS=$(echo "$CMD2" | "$BIN_AWK" -F ' ' '{print $8}')
|
||||||
|
PACKETSSENT=$(echo "$CMD2" | "$BIN_AWK" -F ' ' '{print $9}')
|
||||||
|
PACKETSENDFAILURES=$(echo "$CMD2" | "$BIN_AWK" -F ' ' '{print $10}')
|
||||||
|
INPUTWAKEUPS=$(echo "$CMD2" | "$BIN_AWK" -F ' ' '{print $11}')
|
||||||
|
USEFULINPUTWAKEUPS=$(echo "$CMD2" | "$BIN_AWK" -F ' ' '{print $12}')
|
||||||
|
|
||||||
|
echo '{"data":{"offset":"'"$OFFSET"\
|
||||||
|
'","frequency":"'"$FREQUENCY"\
|
||||||
|
'","sys_jitter":"'"$SYS_JITTER"\
|
||||||
|
'","clk_jitter":"'"$CLK_JITTER"\
|
||||||
|
'","clk_wander":"'"$CLK_WANDER"\
|
||||||
|
'","stratum":"'"$STRATUM"\
|
||||||
|
'","time_since_reset":"'"$TIMESINCERESET"\
|
||||||
|
'","receive_buffers":"'"$RECEIVEDBUFFERS"\
|
||||||
|
'","free_receive_buffers":"'"$FREERECEIVEBUFFERS"\
|
||||||
|
'","used_receive_buffers":"'"$USEDRECEIVEBUFFERS"\
|
||||||
|
'","low_water_refills":"'"$LOWWATERREFILLS"\
|
||||||
|
'","dropped_packets":"'"$DROPPEDPACKETS"\
|
||||||
|
'","ignored_packets":"'"$IGNOREDPACKETS"\
|
||||||
|
'","received_packets":"'"$RECEIVEDPACKETS"\
|
||||||
|
'","packets_sent":"'"$PACKETSSENT"\
|
||||||
|
'","packet_send_failures":"'"$PACKETSENDFAILURES"\
|
||||||
|
'","input_wakeups":"'"$INPUTWAKEUPS"\
|
||||||
|
'","useful_input_wakeups":"'"$USEFULINPUTWAKEUPS"\
|
||||||
|
'"},"error":"0","errorString":"","version":"'"$VERSION"'"}'
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
################################################################
|
||||||
|
# copy this script to /etc/snmp/ and make it executable: #
|
||||||
|
# chmod +x /etc/snmp/os-updates.sh #
|
||||||
|
# ------------------------------------------------------------ #
|
||||||
|
# edit your snmpd.conf and include: #
|
||||||
|
# extend osupdate /opt/os-updates.sh #
|
||||||
|
#--------------------------------------------------------------#
|
||||||
|
# restart snmpd and activate the app for desired host #
|
||||||
|
#--------------------------------------------------------------#
|
||||||
|
# please make sure you have the path/binaries below #
|
||||||
|
################################################################
|
||||||
|
BIN_WC='/usr/bin/wc'
|
||||||
|
BIN_GREP='/bin/grep'
|
||||||
|
CMD_GREP='-c'
|
||||||
|
CMD_WC='-l'
|
||||||
|
BIN_ZYPPER='/usr/bin/zypper'
|
||||||
|
CMD_ZYPPER='-q lu'
|
||||||
|
BIN_YUM='/usr/bin/yum'
|
||||||
|
CMD_YUM='-q check-update'
|
||||||
|
BIN_DNF='/usr/bin/dnf'
|
||||||
|
CMD_DNF='-q check-update'
|
||||||
|
BIN_APT='/usr/bin/apt-get'
|
||||||
|
CMD_APT='-qq -s upgrade'
|
||||||
|
BIN_PACMAN='/usr/bin/pacman'
|
||||||
|
CMD_PACMAN='-Sup'
|
||||||
|
|
||||||
|
################################################################
|
||||||
|
# Don't change anything unless you know what are you doing #
|
||||||
|
################################################################
|
||||||
|
if [ -f "$BIN_ZYPPER" ]; then
|
||||||
|
# OpenSUSE
|
||||||
|
# shellcheck disable=SC2086 # CMD_* are intentionally-split option strings
|
||||||
|
UPDATES=$("$BIN_ZYPPER" $CMD_ZYPPER | "$BIN_WC" $CMD_WC)
|
||||||
|
if [ "$UPDATES" -ge 2 ]; then
|
||||||
|
echo $((UPDATES-2));
|
||||||
|
else
|
||||||
|
echo "0";
|
||||||
|
fi
|
||||||
|
elif [ -f "$BIN_DNF" ]; then
|
||||||
|
# Fedora
|
||||||
|
# shellcheck disable=SC2086 # CMD_* are intentionally-split option strings
|
||||||
|
UPDATES=$("$BIN_DNF" $CMD_DNF | "$BIN_WC" $CMD_WC)
|
||||||
|
if [ "$UPDATES" -ge 1 ]; then
|
||||||
|
echo $((UPDATES-1));
|
||||||
|
else
|
||||||
|
echo "0";
|
||||||
|
fi
|
||||||
|
elif [ -f "$BIN_PACMAN" ]; then
|
||||||
|
# Arch
|
||||||
|
# shellcheck disable=SC2086 # CMD_* are intentionally-split option strings
|
||||||
|
UPDATES=$("$BIN_PACMAN" $CMD_PACMAN | "$BIN_WC" $CMD_WC)
|
||||||
|
if [ "$UPDATES" -ge 1 ]; then
|
||||||
|
echo $((UPDATES-1));
|
||||||
|
else
|
||||||
|
echo "0";
|
||||||
|
fi
|
||||||
|
elif [ -f "$BIN_YUM" ]; then
|
||||||
|
# CentOS / Redhat
|
||||||
|
# shellcheck disable=SC2086 # CMD_* are intentionally-split option strings
|
||||||
|
UPDATES=$("$BIN_YUM" $CMD_YUM | "$BIN_WC" $CMD_WC)
|
||||||
|
if [ "$UPDATES" -ge 1 ]; then
|
||||||
|
echo $((UPDATES-1));
|
||||||
|
else
|
||||||
|
echo "0";
|
||||||
|
fi
|
||||||
|
elif [ -f "$BIN_APT" ]; then
|
||||||
|
# Debian / Devuan / Ubuntu
|
||||||
|
# shellcheck disable=SC2086 # CMD_* are intentionally-split option strings
|
||||||
|
UPDATES=$("$BIN_APT" $CMD_APT | "$BIN_GREP" $CMD_GREP 'Inst')
|
||||||
|
if [ "$UPDATES" -ge 1 ]; then
|
||||||
|
echo "$UPDATES";
|
||||||
|
else
|
||||||
|
echo "0";
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "0";
|
||||||
|
fi
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#Written by Valec 2006. Steal and share.
|
||||||
|
#Get postfix queue lengths
|
||||||
|
|
||||||
|
#extend mailq /opt/observer/scripts/getmailq.sh
|
||||||
|
|
||||||
|
QUEUES="incoming active deferred hold"
|
||||||
|
|
||||||
|
for i in $QUEUES; do
|
||||||
|
COUNT=$(qshape "$i" | grep TOTAL | awk '{print $2}')
|
||||||
|
printf "$COUNT\n"
|
||||||
|
done
|
||||||
@@ -0,0 +1,548 @@
|
|||||||
|
#!/usr/bin/env perl
|
||||||
|
|
||||||
|
# add this to your snmpd.conf file as below
|
||||||
|
# extend postfixdetailed /etc/snmp/postfixdetailed
|
||||||
|
|
||||||
|
# The cache file to use.
|
||||||
|
my $cache='/var/cache/postfixdetailed';
|
||||||
|
|
||||||
|
# the location of pflogsumm
|
||||||
|
my $pflogsumm='/usr/bin/env pflogsumm';
|
||||||
|
|
||||||
|
#totals
|
||||||
|
# 847 received = received
|
||||||
|
# 852 delivered = delivered
|
||||||
|
# 0 forwarded = forwarded
|
||||||
|
# 3 deferred (67 deferrals)= deferred
|
||||||
|
# 0 bounced = bounced
|
||||||
|
# 593 rejected (41%) = rejected
|
||||||
|
# 0 reject warnings = rejectw
|
||||||
|
# 0 held = held
|
||||||
|
# 0 discarded (0%) = discarded
|
||||||
|
|
||||||
|
# 16899k bytes received = bytesr
|
||||||
|
# 18009k bytes delivered = bytesd
|
||||||
|
# 415 senders = senders
|
||||||
|
# 266 sending hosts/domains = sendinghd
|
||||||
|
# 15 recipients = recipients
|
||||||
|
# 9 recipient hosts/domains = recipienthd
|
||||||
|
|
||||||
|
######message deferral detail
|
||||||
|
#Connection refused = deferralcr
|
||||||
|
#Host is down = deferralhid
|
||||||
|
|
||||||
|
########message reject detail
|
||||||
|
#Client host rejected = chr
|
||||||
|
#Helo command rejected: need fully-qualified hostname = hcrnfqh
|
||||||
|
#Sender address rejected: Domain not found = sardnf
|
||||||
|
#Sender address rejected: not owned by user = sarnobu
|
||||||
|
#blocked using = bu
|
||||||
|
#Recipient address rejected: User unknown = raruu
|
||||||
|
#Helo command rejected: Invalid name = hcrin
|
||||||
|
#Sender address rejected: need fully-qualified address = sarnfqa
|
||||||
|
#Recipient address rejected: Domain not found = rardnf
|
||||||
|
#Recipient address rejected: need fully-qualified address = rarnfqa
|
||||||
|
#Improper use of SMTP command pipelining = iuscp
|
||||||
|
#Message size exceeds fixed limit = msefl
|
||||||
|
#Server configuration error = sce
|
||||||
|
#Server configuration problem = scp
|
||||||
|
#unknown reject reason = urr
|
||||||
|
|
||||||
|
my $old='';
|
||||||
|
|
||||||
|
#reads in the old data if it exists
|
||||||
|
if ( -f $cache ){
|
||||||
|
open(my $fh, "<", $cache) or die "Can't open '".$cache."'";
|
||||||
|
# if this is over 2048, something is most likely wrong
|
||||||
|
read($fh , $old , 2048);
|
||||||
|
close($fh);
|
||||||
|
}
|
||||||
|
|
||||||
|
my ( $received,
|
||||||
|
$delivered,
|
||||||
|
$forwarded,
|
||||||
|
$deferred,
|
||||||
|
$bounced,
|
||||||
|
$rejected,
|
||||||
|
$rejectw,
|
||||||
|
$held,
|
||||||
|
$discarded,
|
||||||
|
$bytesr,
|
||||||
|
$bytesd,
|
||||||
|
$senders,
|
||||||
|
$sendinghd,
|
||||||
|
$recipients,
|
||||||
|
$recipienthd,
|
||||||
|
$deferralcr,
|
||||||
|
$deferralhid,
|
||||||
|
$chr,
|
||||||
|
$hcrnfqh,
|
||||||
|
$sardnf,
|
||||||
|
$sarnobu,
|
||||||
|
$bu,
|
||||||
|
$raruu,
|
||||||
|
$hcrin,
|
||||||
|
$sarnfqa,
|
||||||
|
$rardnf,
|
||||||
|
$rarnfqa,
|
||||||
|
$iuscp,
|
||||||
|
$sce,
|
||||||
|
$scp,
|
||||||
|
$urr,
|
||||||
|
$msefl) = split ( /\n/, $old );
|
||||||
|
|
||||||
|
if ( ! defined( $received ) ){ $received=0; }
|
||||||
|
if ( ! defined( $delivered ) ){ $delivered=0; }
|
||||||
|
if ( ! defined( $forwarded ) ){ $forwarded=0; }
|
||||||
|
if ( ! defined( $deferred ) ){ $deferred=0; }
|
||||||
|
if ( ! defined( $bounced ) ){ $bounced=0; }
|
||||||
|
if ( ! defined( $rejected ) ){ $rejected=0; }
|
||||||
|
if ( ! defined( $rejectw ) ){ $rejectw=0; }
|
||||||
|
if ( ! defined( $held ) ){ $held=0; }
|
||||||
|
if ( ! defined( $discarded ) ){ $discarded=0; }
|
||||||
|
if ( ! defined( $bytesr ) ){ $bytesr=0; }
|
||||||
|
if ( ! defined( $bytesd ) ){ $bytesd=0; }
|
||||||
|
if ( ! defined( $senders ) ){ $senders=0; }
|
||||||
|
if ( ! defined( $sendinghd ) ){ $sendinghd=0; }
|
||||||
|
if ( ! defined( $recipients ) ){ $recipients=0; }
|
||||||
|
if ( ! defined( $recipienthd ) ){ $recipienthd=0; }
|
||||||
|
if ( ! defined( $deferralcr ) ){ $deferralcr=0; }
|
||||||
|
if ( ! defined( $deferralhid ) ){ $deferralhid=0; }
|
||||||
|
if ( ! defined( $chr ) ){ $chr=0; }
|
||||||
|
if ( ! defined( $hcrnfqh ) ){ $hcrnfqh=0; }
|
||||||
|
if ( ! defined( $sardnf ) ){ $sardnf=0; }
|
||||||
|
if ( ! defined( $sarnobu ) ){ $sarnobu=0; }
|
||||||
|
if ( ! defined( $bu ) ){ $bu=0; }
|
||||||
|
if ( ! defined( $raruu ) ){ $raruu=0; }
|
||||||
|
if ( ! defined( $hcrin ) ){ $hcrin=0; }
|
||||||
|
if ( ! defined( $sarnfqa ) ){ $sarnfqa=0; }
|
||||||
|
if ( ! defined( $rardnf ) ){ $rardnf=0; }
|
||||||
|
if ( ! defined( $rarnfqa ) ){ $rarnfqa=0; }
|
||||||
|
if ( ! defined( $iuscp ) ){ $iuscp=0; }
|
||||||
|
if ( ! defined( $msefl ) ){ $msefl=0; }
|
||||||
|
if ( ! defined( $sce ) ){ $sce=0; }
|
||||||
|
if ( ! defined( $scp ) ){ $scp=0; }
|
||||||
|
if ( ! defined( $urr ) ){ $urr=0; }
|
||||||
|
|
||||||
|
#init current variables
|
||||||
|
my $receivedC=0;
|
||||||
|
my $deliveredC=0;
|
||||||
|
my $forwardedC=0;
|
||||||
|
my $deferredC=0;
|
||||||
|
my $bouncedC=0;
|
||||||
|
my $rejectedC=0;
|
||||||
|
my $rejectwC=0;
|
||||||
|
my $heldC=0;
|
||||||
|
my $discardedC=0;
|
||||||
|
my $bytesrC=0;
|
||||||
|
my $bytesdC=0;
|
||||||
|
my $sendersC=0;
|
||||||
|
my $sendinghdC=0;
|
||||||
|
my $recipientsC=0;
|
||||||
|
my $recipienthdC=0;
|
||||||
|
my $deferralcrC=0;
|
||||||
|
my $deferralhidC=0;
|
||||||
|
my $hcrnfqhC=0;
|
||||||
|
my $sardnfC=0;
|
||||||
|
my $sarnobuC=0;
|
||||||
|
my $buC=0;
|
||||||
|
my $raruuC=0;
|
||||||
|
my $hcrinC=0;
|
||||||
|
my $sarnfqaC=0;
|
||||||
|
my $rardnfC=0;
|
||||||
|
my $rarnfqaC=0;
|
||||||
|
my $iuscpC=0;
|
||||||
|
my $mseflC=0;
|
||||||
|
my $sceC=0;
|
||||||
|
my $scpC=0;
|
||||||
|
my $urrC=0;
|
||||||
|
|
||||||
|
sub newValue{
|
||||||
|
my $old=$_[0];
|
||||||
|
my $new=$_[1];
|
||||||
|
|
||||||
|
#if new is undefined, just default to 0... this should never happen
|
||||||
|
if ( !defined( $new ) ){
|
||||||
|
warn('New not defined');
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#sets it to 0 if old is not defined
|
||||||
|
if ( !defined( $old ) ){
|
||||||
|
warn('Old not defined');
|
||||||
|
$old=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#make sure they are both numberic and if not set to zero
|
||||||
|
if( $old !~ /^[0123456789]*$/ ){
|
||||||
|
warn('Old not numeric');
|
||||||
|
$old=0;
|
||||||
|
}
|
||||||
|
if( $new !~ /^[0123456789]*$/ ){
|
||||||
|
warn('New not numeric');
|
||||||
|
$new=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#log rotation happened
|
||||||
|
if ( $old > $new ){
|
||||||
|
return $new;
|
||||||
|
};
|
||||||
|
|
||||||
|
return $new - $old;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
my $output=`$pflogsumm /var/log/maillog`;
|
||||||
|
|
||||||
|
#holds RBL values till the end when it is compared to the old one
|
||||||
|
my $buNew=0;
|
||||||
|
|
||||||
|
|
||||||
|
#holds client host rejected values till the end when it is compared to the old one
|
||||||
|
my $chrNew=0;
|
||||||
|
|
||||||
|
# holds recipient address rejected values till the end when it is compared to the old one
|
||||||
|
my $raruuNew=0;
|
||||||
|
|
||||||
|
#holds the current values for checking later
|
||||||
|
my $current='';
|
||||||
|
|
||||||
|
my @outputA=split( /\n/, $output );
|
||||||
|
my $int=0;
|
||||||
|
while ( defined( $outputA[$int] ) ){
|
||||||
|
my $line=$outputA[$int];
|
||||||
|
|
||||||
|
$line=~s/^ *//;
|
||||||
|
$line=~s/ +/ /g;
|
||||||
|
$line=~s/\)$//;
|
||||||
|
|
||||||
|
my $handled=0;
|
||||||
|
|
||||||
|
#received line
|
||||||
|
if ( ( $line =~ /[0123456789] received$/ ) && ( ! $handled ) ){
|
||||||
|
$line=~s/ .*//;
|
||||||
|
$receivedC=$line;
|
||||||
|
$received=newValue( $received, $line );
|
||||||
|
$handled=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#delivered line
|
||||||
|
if ( ( $line =~ /[0123456789] delivered$/ ) && ( ! $handled ) ){
|
||||||
|
$line=~s/ .*//;
|
||||||
|
$deliveredC=$line;
|
||||||
|
$delivered=newValue( $delivered, $line );
|
||||||
|
$handled=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#forward line
|
||||||
|
if ( ( $line =~ /[0123456789] forwarded$/ ) && ( ! $handled ) ){
|
||||||
|
$line=~s/ .*//;
|
||||||
|
$forwardedC=$line;
|
||||||
|
$forwarded=newValue( $forwarded, $line );
|
||||||
|
$handled=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#defereed line
|
||||||
|
if ( ( $line =~ /[0123456789] deferred \(/ ) && ( ! $handled ) ){
|
||||||
|
$line=~s/ .*//;
|
||||||
|
$deferredC=$line;
|
||||||
|
$deferred=newValue( $deferred, $line );
|
||||||
|
$handled=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#bounced line
|
||||||
|
if ( ( $line =~ /[0123456789] bounced$/ ) && ( ! $handled ) ){
|
||||||
|
$line=~s/ .*//;
|
||||||
|
$bouncedC=$line;
|
||||||
|
$bounced=newValue( $bounced, $line );
|
||||||
|
$handled=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#rejected line
|
||||||
|
if ( ( $line =~ /[0123456789] rejected \(/ ) && ( ! $handled ) ){
|
||||||
|
$line=~s/ .*//;
|
||||||
|
$rejectedC=$line;
|
||||||
|
$rejected=newValue( $rejected, $line );
|
||||||
|
$handled=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#reject warning line
|
||||||
|
if ( ( $line =~ /[0123456789] reject warnings/ ) && ( ! $handled ) ){
|
||||||
|
$line=~s/ .*//;
|
||||||
|
$rejectwC=$line;
|
||||||
|
$rejectw=newValue( $rejectw, $line );
|
||||||
|
$handled=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#held line
|
||||||
|
if ( ( $line =~ /[0123456789] held$/ ) && ( ! $handled ) ){
|
||||||
|
$line=~s/ .*//;
|
||||||
|
$heldC=$line;
|
||||||
|
$held=newValue( $held, $line );
|
||||||
|
$handled=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#discarded line
|
||||||
|
if ( ( $line =~ /[0123456789] discarded \(/ ) && ( ! $handled ) ){
|
||||||
|
$line=~s/ .*//;
|
||||||
|
$discardedC=$line;
|
||||||
|
$discarded=newValue( $discarded, $line );
|
||||||
|
$handled=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#bytes received line
|
||||||
|
if ( ( $line =~ /[0123456789kM] bytes received$/ ) && ( ! $handled ) ){
|
||||||
|
$line=~s/ .*//;
|
||||||
|
$line=~s/k/000/;
|
||||||
|
$line=~s/M/000000/;
|
||||||
|
$bytesrC=$line;
|
||||||
|
$bytesr=newValue( $bytesr, $line );
|
||||||
|
$handled=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#bytes delivered line
|
||||||
|
if ( ( $line =~ /[0123456789kM] bytes delivered$/ ) && ( ! $handled ) ){
|
||||||
|
$line=~s/ .*//;
|
||||||
|
$line=~s/k/000/;
|
||||||
|
$line=~s/M/000000/;
|
||||||
|
$bytesdC=$line;
|
||||||
|
$bytesd=newValue( $bytesd, $line );
|
||||||
|
$handled=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#senders line
|
||||||
|
if ( ( $line =~ /[0123456789] senders$/ ) && ( ! $handled ) ){
|
||||||
|
$line=~s/ .*//;
|
||||||
|
$sendersC=$line;
|
||||||
|
$senders=newValue( $senders, $line );
|
||||||
|
$handled=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#sendering hosts/domains line
|
||||||
|
if ( ( $line =~ /[0123456789] sending hosts\/domains$/ ) && ( ! $handled ) ){
|
||||||
|
$line=~s/ .*//;
|
||||||
|
$sendinghdC=$line;
|
||||||
|
$sendinghd=newValue( $sendinghd, $line );
|
||||||
|
$handled=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#recipients line
|
||||||
|
if ( ( $line =~ /[0123456789] recipients$/ ) && ( ! $handled ) ){
|
||||||
|
$line=~s/ .*//;
|
||||||
|
$recipientsC=$line;
|
||||||
|
$recipients=newValue( $recipients, $line );
|
||||||
|
$handled=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#recipients line
|
||||||
|
if ( ( $line =~ /[0123456789] recipient hosts\/domains$/ ) && ( ! $handled ) ){
|
||||||
|
$line=~s/ .*//;
|
||||||
|
$recipienthdC=$line;
|
||||||
|
$recipienthd=newValue( $recipienthd, $line );
|
||||||
|
$handled=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
# deferrals connectios refused
|
||||||
|
if ( ( $line =~ /[0123456789] 25\: Connection refused$/ ) && ( ! $handled ) ){
|
||||||
|
$line=~s/ .*//;
|
||||||
|
$deferralcrC=$line;
|
||||||
|
$deferralcr=newValue( $deferralcr, $line );
|
||||||
|
$handled=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
# deferrals Host is down
|
||||||
|
if ( ( $line =~ /Host is down$/ ) && ( ! $handled ) ){
|
||||||
|
$line=~s/ .*//;
|
||||||
|
$deferralcrC=$line;
|
||||||
|
$deferralhidC=$line;
|
||||||
|
$deferralhid=newValue( $deferralhid, $line );
|
||||||
|
$handled=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Client host rejected
|
||||||
|
if ( ( $line =~ /Client host rejected/ ) && ( ! $handled ) ){
|
||||||
|
$line=~s/.*\: //g;
|
||||||
|
$chrNew=$chrNew + $line;
|
||||||
|
$handled=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#Helo command rejected: need fully-qualified hostname
|
||||||
|
if ( ( $line =~ /Helo command rejected\: need fully\-qualified hostname/ ) && ( ! $handled ) ){
|
||||||
|
$line=~s/.*\: //g;
|
||||||
|
$hcrnfqhC=$line;
|
||||||
|
$hcrnfqh=newValue( $hcrnfqh, $line );
|
||||||
|
$handled=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#Sender address rejected: Domain not found
|
||||||
|
if ( ( $line =~ /Sender address rejected\: Domain not found/ ) && ( ! $handled ) ){
|
||||||
|
$line=~s/.*\: //g;
|
||||||
|
$sardnfC=$line;
|
||||||
|
$sardnf=newValue( $sardnf, $line );
|
||||||
|
$handled=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#Sender address rejected: not owned by user
|
||||||
|
if ( ( $line =~ /Sender address rejected\: not owned by user/ ) && ( ! $handled ) ){
|
||||||
|
$line=~s/.*\: //g;
|
||||||
|
$sarnobuC=$line;
|
||||||
|
$sarnobu=newValue( $sarnobu, $line );
|
||||||
|
$handled=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#blocked using
|
||||||
|
# These lines are RBLs so there will be more than one.
|
||||||
|
# Use $buNew to add them all up.
|
||||||
|
if ( ( $line =~ /blocked using/ ) && ( ! $handled ) ){
|
||||||
|
$line=~s/.*\: //g;
|
||||||
|
$buNew=$buNew + $line;
|
||||||
|
$handled=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#Recipient address rejected: User unknown
|
||||||
|
if ( ( $line =~ /Recipient address rejected\: User unknown/ ) && ( ! $handled ) ){
|
||||||
|
$line=~s/.*\: //g;
|
||||||
|
$raruuNew=$raruuNew + $line;
|
||||||
|
$handled=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#Helo command rejected: Invalid name
|
||||||
|
if ( ( $line =~ /Helo command rejected\: Invalid name/ ) && ( ! $handled ) ){
|
||||||
|
$line=~s/.*\: //g;
|
||||||
|
$hcrinC=$line;
|
||||||
|
$hcrin=newValue( $hcrin, $line );
|
||||||
|
}
|
||||||
|
|
||||||
|
#Sender address rejected: need fully-qualified address
|
||||||
|
if ( ( $line =~ /Sender address rejected\: need fully-qualified address/ ) && ( ! $handled ) ){
|
||||||
|
$line=~s/.*\: //g;
|
||||||
|
$sarnfqaC=$line;
|
||||||
|
$sarnfqa=newValue( $sarnfqa, $line );
|
||||||
|
}
|
||||||
|
|
||||||
|
#Recipient address rejected: Domain not found
|
||||||
|
if ( ( $line =~ /Recipient address rejected\: Domain not found/ ) && ( ! $handled ) ){
|
||||||
|
$line=~s/.*\: //g;
|
||||||
|
$rardnfC=$line;
|
||||||
|
$rardnf=newValue( $rardnf, $line );
|
||||||
|
}
|
||||||
|
|
||||||
|
#Improper use of SMTP command pipelining
|
||||||
|
if ( ( $line =~ /Improper use of SMTP command pipelining/ ) && ( ! $handled ) ){
|
||||||
|
$line=~s/.*\: //g;
|
||||||
|
$iuscpC=$line;
|
||||||
|
$iuscp=newValue( $iuscp, $line );
|
||||||
|
}
|
||||||
|
|
||||||
|
#Message size exceeds fixed limit
|
||||||
|
if ( ( $line =~ /Message size exceeds fixed limit/ ) && ( ! $handled ) ){
|
||||||
|
$line=~s/.*\: //g;
|
||||||
|
$mseflC=$line;
|
||||||
|
$msefl=newValue( $msefl, $line );
|
||||||
|
}
|
||||||
|
|
||||||
|
#Server configuration error
|
||||||
|
if ( ( $line =~ /Server configuration error/ ) && ( ! $handled ) ){
|
||||||
|
$line=~s/.*\: //g;
|
||||||
|
$sceC=$line;
|
||||||
|
$sce=newValue( $sce, $line );
|
||||||
|
}
|
||||||
|
|
||||||
|
#Server configuration problem
|
||||||
|
if ( ( $line =~ /Server configuration problem/ ) && ( ! $handled ) ){
|
||||||
|
$line=~s/.*\: //g;
|
||||||
|
$scpC=$line;
|
||||||
|
$scp=newValue( $scp, $line );
|
||||||
|
}
|
||||||
|
|
||||||
|
#unknown reject reason
|
||||||
|
if ( ( $line =~ /unknown reject reason/ ) && ( ! $handled ) ){
|
||||||
|
$line=~s/.*\: //g;
|
||||||
|
$urrC=$line;
|
||||||
|
$urr=newValue( $urr, $line );
|
||||||
|
}
|
||||||
|
|
||||||
|
$int++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# final client host rejected total
|
||||||
|
$chr=newValue( $chr, $chrNew );
|
||||||
|
|
||||||
|
# final RBL total
|
||||||
|
$bu=newValue( $bu, $buNew );
|
||||||
|
|
||||||
|
# final recipient address rejected total
|
||||||
|
$raruu=newValue( $raruu, $raruuNew );
|
||||||
|
|
||||||
|
my $data=$received."\n".
|
||||||
|
$delivered."\n".
|
||||||
|
$forwarded."\n".
|
||||||
|
$deferred."\n".
|
||||||
|
$bounced."\n".
|
||||||
|
$rejected."\n".
|
||||||
|
$rejectw."\n".
|
||||||
|
$held."\n".
|
||||||
|
$discarded."\n".
|
||||||
|
$bytesr."\n".
|
||||||
|
$bytesd."\n".
|
||||||
|
$senders."\n".
|
||||||
|
$sendinghd."\n".
|
||||||
|
$recipients."\n".
|
||||||
|
$recipienthd."\n".
|
||||||
|
$deferralcr."\n".
|
||||||
|
$deferralhid."\n".
|
||||||
|
$chr."\n".
|
||||||
|
$hcrnfqh."\n".
|
||||||
|
$sardnf."\n".
|
||||||
|
$sarnobu."\n".
|
||||||
|
$bu."\n".
|
||||||
|
$raruu."\n".
|
||||||
|
$hcrin."\n".
|
||||||
|
$sarnfqa."\n".
|
||||||
|
$rardnf."\n".
|
||||||
|
$rarnfqa."\n".
|
||||||
|
$iuscp."\n".
|
||||||
|
$sce."\n".
|
||||||
|
$scp."\n".
|
||||||
|
$urr."\n".
|
||||||
|
$msefl."\n";
|
||||||
|
|
||||||
|
print $data;
|
||||||
|
|
||||||
|
my $current=$receivedC."\n".
|
||||||
|
$deliveredC."\n".
|
||||||
|
$forwardedC."\n".
|
||||||
|
$deferredC."\n".
|
||||||
|
$bouncedC."\n".
|
||||||
|
$rejectedC."\n".
|
||||||
|
$rejectwC."\n".
|
||||||
|
$heldC."\n".
|
||||||
|
$discardedC."\n".
|
||||||
|
$bytesrC."\n".
|
||||||
|
$bytesdC."\n".
|
||||||
|
$sendersC."\n".
|
||||||
|
$sendinghdC."\n".
|
||||||
|
$recipientsC."\n".
|
||||||
|
$recipienthdC."\n".
|
||||||
|
$deferralcrC."\n".
|
||||||
|
$deferralhidC."\n".
|
||||||
|
$chrNew."\n".
|
||||||
|
$hcrnfqhC."\n".
|
||||||
|
$sardnfC."\n".
|
||||||
|
$sarnobuC."\n".
|
||||||
|
$buNew."\n".
|
||||||
|
$raruuNew."\n".
|
||||||
|
$hcrinC."\n".
|
||||||
|
$sarnfqaC."\n".
|
||||||
|
$rardnfC."\n".
|
||||||
|
$rarnfqaC."\n".
|
||||||
|
$iuscpC."\n".
|
||||||
|
$sceC."\n".
|
||||||
|
$scpC."\n".
|
||||||
|
$urrC."\n".
|
||||||
|
$mseflC."\n";
|
||||||
|
|
||||||
|
open(my $fh, ">", $cache) or die "Can't open '".$cache."'";
|
||||||
|
print $fh $current;
|
||||||
|
close($fh);
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#######################################
|
||||||
|
# please read DOCS to succesfully get #
|
||||||
|
# raspberry sensors into your host #
|
||||||
|
#######################################
|
||||||
|
picmd='/usr/bin/vcgencmd'
|
||||||
|
pised='/bin/sed'
|
||||||
|
getTemp='measure_temp'
|
||||||
|
getVoltsCore='measure_volts core'
|
||||||
|
getVoltsRamC='measure_volts sdram_c'
|
||||||
|
getVoltsRamI='measure_volts sdram_i'
|
||||||
|
getVoltsRamP='measure_volts sdram_p'
|
||||||
|
getFreqArm='measure_clock arm'
|
||||||
|
getFreqCore='measure_clock core'
|
||||||
|
getStatusH264='codec_enabled H264'
|
||||||
|
getStatusMPG2='codec_enabled MPG2'
|
||||||
|
getStatusWVC1='codec_enabled WVC1'
|
||||||
|
getStatusMPG4='codec_enabled MPG4'
|
||||||
|
getStatusMJPG='codec_enabled MJPG'
|
||||||
|
getStatusWMV9='codec_enabled WMV9'
|
||||||
|
|
||||||
|
$picmd $getTemp | $pised 's|[^0-9.]||g'
|
||||||
|
$picmd "$getVoltsCore" | $pised 's|[^0-9.]||g'
|
||||||
|
$picmd "$getVoltsRamC" | $pised 's|[^0-9.]||g'
|
||||||
|
$picmd "$getVoltsRamI" | $pised 's|[^0-9.]||g'
|
||||||
|
$picmd "$getVoltsRamP" | $pised 's|[^0-9.]||g'
|
||||||
|
$picmd "$getFreqArm" | $pised 's/frequency([0-9]*)=//g'
|
||||||
|
$picmd "$getFreqCore" | $pised 's/frequency([0-9]*)=//g'
|
||||||
|
$picmd "$getStatusH264" | $pised 's/H264=//g'
|
||||||
|
$picmd "$getStatusMPG2" | $pised 's/MPG2=//g'
|
||||||
|
$picmd "$getStatusWVC1" | $pised 's/WVC1=//g'
|
||||||
|
$picmd "$getStatusMPG4" | $pised 's/MPG4=//g'
|
||||||
|
$picmd "$getStatusMJPG" | $pised 's/MJPG=//g'
|
||||||
|
$picmd "$getStatusWMV9" | $pised 's/WMV9=//g'
|
||||||
|
$picmd "$getStatusH264" | $pised 's/enabled/2/g'
|
||||||
|
$picmd "$getStatusMPG2" | $pised 's/enabled/2/g'
|
||||||
|
$picmd "$getStatusWVC1" | $pised 's/enabled/2/g'
|
||||||
|
$picmd "$getStatusMPG4" | $pised 's/enabled/2/g'
|
||||||
|
$picmd "$getStatusMJPG" | $pised 's/enabled/2/g'
|
||||||
|
$picmd "$getStatusWMV9" | $pised 's/enabled/2/g'
|
||||||
|
$picmd "$getStatusH264" | $pised 's/disabled/1/g'
|
||||||
|
$picmd "$getStatusMPG2" | $pised 's/disabled/1/g'
|
||||||
|
$picmd "$getStatusWVC1" | $pised 's/disabled/1/g'
|
||||||
|
$picmd "$getStatusMPG4" | $pised 's/disabled/1/g'
|
||||||
|
$picmd "$getStatusMJPG" | $pised 's/disabled/1/g'
|
||||||
|
$picmd "$getStatusWMV9" | $pised 's/disabled/1/g'
|
||||||
@@ -0,0 +1,929 @@
|
|||||||
|
#!/usr/bin/env perl
|
||||||
|
#Copyright (c) 2024, Zane C. Bowers-Hadley
|
||||||
|
#All rights reserved.
|
||||||
|
#
|
||||||
|
#Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
#are permitted provided that the following conditions are met:
|
||||||
|
#
|
||||||
|
# * Redistributions of source code must retain the above copyright notice,
|
||||||
|
# this list of conditions and the following disclaimer.
|
||||||
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
# this list of conditions and the following disclaimer in the documentation
|
||||||
|
# and/or other materials provided with the distribution.
|
||||||
|
#
|
||||||
|
#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
#ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
#WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
#IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||||
|
#INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
#BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
#DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
#LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||||
|
#OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||||
|
#THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
=for comment
|
||||||
|
|
||||||
|
Add this to snmpd.conf like below.
|
||||||
|
|
||||||
|
extend smart /etc/snmp/smart
|
||||||
|
|
||||||
|
Then add to root's cron tab, if you have more than a few disks.
|
||||||
|
|
||||||
|
*/5 * * * * /etc/snmp/extends/smart -u
|
||||||
|
|
||||||
|
You will also need to create the config file, which defaults to the same path as the script,
|
||||||
|
but with .config appended. So if the script is located at /etc/snmp/smart, the config file
|
||||||
|
will be /etc/snmp/extends/smart.config. Alternatively you can also specific a config via -c.
|
||||||
|
|
||||||
|
Anything starting with a # is comment. The format for variables is $variable=$value. Empty
|
||||||
|
lines are ignored. Spaces and tabes at either the start or end of a line are ignored. Any
|
||||||
|
line with out a matched variable or # are treated as a disk.
|
||||||
|
|
||||||
|
#This is a comment
|
||||||
|
cache=/var/cache/smart
|
||||||
|
smartctl=/usr/local/sbin/smartctl
|
||||||
|
useSN=0
|
||||||
|
ada0
|
||||||
|
da5 /dev/da5 -d sat
|
||||||
|
twl0,0 /dev/twl0 -d 3ware,0
|
||||||
|
twl0,1 /dev/twl0 -d 3ware,1
|
||||||
|
twl0,2 /dev/twl0 -d 3ware,2
|
||||||
|
|
||||||
|
The variables are as below.
|
||||||
|
|
||||||
|
cache = The path to the cache file to use. Default: /var/cache/smart
|
||||||
|
smartctl = The path to use for smartctl. Default: /usr/bin/env smartctl
|
||||||
|
useSN = If set to 1, it will use the disks SN for reporting instead of the device name.
|
||||||
|
1 is the default. 0 will use the device name.
|
||||||
|
|
||||||
|
A disk line is can be as simple as just a disk name under /dev/. Such as in the config above
|
||||||
|
The line "ada0" would resolve to "/dev/ada0" and would be called with no special argument. If
|
||||||
|
a line has a space in it, everything before the space is treated as the disk name and is what
|
||||||
|
used for reporting and everything after that is used as the argument to be passed to smartctl.
|
||||||
|
|
||||||
|
If you want to guess at the configuration, call it with -g and it will print out what it thinks
|
||||||
|
it should be.
|
||||||
|
|
||||||
|
|
||||||
|
Switches:
|
||||||
|
|
||||||
|
-c <config> The config file to use.
|
||||||
|
-u Update
|
||||||
|
-p Pretty print the JSON.
|
||||||
|
-Z GZip+Base64 compress the results.
|
||||||
|
|
||||||
|
-g Guess at the config and print it to STDOUT
|
||||||
|
-C Enable manual checking for guess and cciss.
|
||||||
|
-S Set useSN to 0 when using -g
|
||||||
|
-t <test> Run the specified smart self test on all the devices.
|
||||||
|
-U When calling cciss_vol_status, call it with -u.
|
||||||
|
-G <modes> Guess modes to use. This is a comma seperated list.
|
||||||
|
Default :: scan-open,cciss-vol-status
|
||||||
|
|
||||||
|
Guess Modes:
|
||||||
|
|
||||||
|
- scan :: Use "--scan" with smartctl. "scan-open" will take presidence.
|
||||||
|
|
||||||
|
- scan-open :: Call smartctl with "--scan-open".
|
||||||
|
|
||||||
|
- cciss-vol-status :: Freebsd/Linux specific and if it sees /dev/sg0(on Linux) or
|
||||||
|
/dev/ciss0(on FreebSD) it will attempt to find drives via cciss-vol-status,
|
||||||
|
and then optionally checking for disks via smrtctl if -C is given. Should be noted
|
||||||
|
though that -C will not find drives that are currently missing/failed. If -U is given,
|
||||||
|
cciss_vol_status will be called with -u.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
##
|
||||||
|
## You should not need to touch anything below here.
|
||||||
|
##
|
||||||
|
use warnings;
|
||||||
|
use strict;
|
||||||
|
use Getopt::Std;
|
||||||
|
use JSON;
|
||||||
|
use MIME::Base64;
|
||||||
|
use IO::Compress::Gzip qw(gzip $GzipError);
|
||||||
|
|
||||||
|
my $cache = '/var/cache/smart';
|
||||||
|
my $smartctl = '/usr/bin/env smartctl';
|
||||||
|
my @disks;
|
||||||
|
my $useSN = 1;
|
||||||
|
|
||||||
|
$Getopt::Std::STANDARD_HELP_VERSION = 1;
|
||||||
|
|
||||||
|
sub main::VERSION_MESSAGE {
|
||||||
|
print "SMART SNMP extend 0.3.2\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
sub main::HELP_MESSAGE {
|
||||||
|
&VERSION_MESSAGE;
|
||||||
|
print "\n" . "-u Update '" . $cache . "'\n" . '-g Guess at the config and print it to STDOUT
|
||||||
|
-c <config> The config file to use.
|
||||||
|
-p Pretty print the JSON.
|
||||||
|
-Z GZip+Base64 compress the results.
|
||||||
|
-C Enable manual checking for guess and cciss.
|
||||||
|
-S Set useSN to 0 when using -g
|
||||||
|
-t <test> Run the specified smart self test on all the devices.
|
||||||
|
-U When calling cciss_vol_status, call it with -u.
|
||||||
|
-G <modes> Guess modes to use. This is a comma seperated list.
|
||||||
|
Default :: scan-open,cciss-vol-status
|
||||||
|
|
||||||
|
|
||||||
|
Scan Modes:
|
||||||
|
|
||||||
|
- scan :: Use "--scan" with smartctl. "scan-open" will take presidence.
|
||||||
|
|
||||||
|
- scan-open :: Call smartctl with "--scan-open".
|
||||||
|
|
||||||
|
- cciss-vol-status :: Freebsd/Linux specific and if it sees /dev/sg0(on Linux) or
|
||||||
|
/dev/ciss0(on FreebSD) it will attempt to find drives via cciss-vol-status,
|
||||||
|
and then optionally checking for disks via smrtctl if -C is given. Should be noted
|
||||||
|
though that -C will not find drives that are currently missing/failed. If -U is given,
|
||||||
|
cciss_vol_status will be called with -u.
|
||||||
|
';
|
||||||
|
|
||||||
|
} ## end sub main::HELP_MESSAGE
|
||||||
|
|
||||||
|
#gets the options
|
||||||
|
my %opts = ();
|
||||||
|
getopts( 'ugc:pZhvCSGt:U', \%opts );
|
||||||
|
|
||||||
|
if ( $opts{h} ) {
|
||||||
|
&HELP_MESSAGE;
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
if ( $opts{v} ) {
|
||||||
|
&VERSION_MESSAGE;
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# figure out what scan modes to use if -g specified
|
||||||
|
#
|
||||||
|
my $scan_modes = {
|
||||||
|
'scan-open' => 0,
|
||||||
|
'scan' => 0,
|
||||||
|
'cciss_vol_status' => 0,
|
||||||
|
};
|
||||||
|
if ( $opts{g} ) {
|
||||||
|
if ( !defined( $opts{G} ) ) {
|
||||||
|
$opts{G} = 'scan-open,cciss_vol_status';
|
||||||
|
}
|
||||||
|
$opts{G} =~ s/[\ \t]//g;
|
||||||
|
my @scan_modes_split = split( /,/, $opts{G} );
|
||||||
|
foreach my $mode (@scan_modes_split) {
|
||||||
|
if ( !defined $scan_modes->{$mode} ) {
|
||||||
|
die( '"' . $mode . '" is not a recognized scan mode' );
|
||||||
|
}
|
||||||
|
$scan_modes->{$mode} = 1;
|
||||||
|
}
|
||||||
|
} ## end if ( $opts{g} )
|
||||||
|
|
||||||
|
# configure JSON for later usage
|
||||||
|
# only need to do this if actually running as in -g is not specified
|
||||||
|
my $json;
|
||||||
|
if ( !$opts{g} ) {
|
||||||
|
|
||||||
|
$json = JSON->new->allow_nonref->canonical(1);
|
||||||
|
if ( $opts{p} ) {
|
||||||
|
$json->pretty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# guess if asked
|
||||||
|
#
|
||||||
|
#
|
||||||
|
if ( defined( $opts{g} ) ) {
|
||||||
|
|
||||||
|
#get what path to use for smartctl
|
||||||
|
$smartctl = `which smartctl`;
|
||||||
|
chomp($smartctl);
|
||||||
|
if ( $? != 0 ) {
|
||||||
|
warn("'which smartctl' failed with a exit code of $?");
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#try to touch the default cache location and warn if it can't be done
|
||||||
|
system( 'touch ' . $cache . '>/dev/null' );
|
||||||
|
if ( $? != 0 ) {
|
||||||
|
$cache = '#Could not touch ' . $cache . "You will need to manually set it\n" . "cache=?\n";
|
||||||
|
} else {
|
||||||
|
system( 'rm -f ' . $cache . '>/dev/null' );
|
||||||
|
$cache = 'cache=' . $cache . "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
my $drive_lines = '';
|
||||||
|
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# scan-open and scan guess mode handling
|
||||||
|
#
|
||||||
|
#
|
||||||
|
if ( $scan_modes->{'scan-open'} || $scan_modes->{'scan'} ) {
|
||||||
|
# used for checking if a disk has been found more than once
|
||||||
|
my %found_disks_names;
|
||||||
|
my @argumentsA;
|
||||||
|
|
||||||
|
# use scan-open if it is set, overriding scan if it is also set
|
||||||
|
my $mode = 'scan';
|
||||||
|
if ( $scan_modes->{'scan-open'} ) {
|
||||||
|
$mode = 'scan-open';
|
||||||
|
}
|
||||||
|
|
||||||
|
#have smartctl scan and see if it finds anythings not get found
|
||||||
|
my $scan_output = `$smartctl --$mode`;
|
||||||
|
my @scan_outputA = split( /\n/, $scan_output );
|
||||||
|
|
||||||
|
# remove non-SMART devices sometimes returned
|
||||||
|
@scan_outputA = grep( !/ses[0-9]/, @scan_outputA ); # not a disk, but may or may not have SMART attributes
|
||||||
|
@scan_outputA = grep( !/pass[0-9]/, @scan_outputA ); # very likely a duplicate and a disk under another name
|
||||||
|
@scan_outputA = grep( !/cd[0-9]/, @scan_outputA ); # CD drive
|
||||||
|
if ( $^O eq 'freebsd' ) {
|
||||||
|
@scan_outputA = grep( !/sa[0-9]/, @scan_outputA ); # tape drive
|
||||||
|
@scan_outputA = grep( !/ctl[0-9]/, @scan_outputA ); # CAM target layer
|
||||||
|
} elsif ( $^O eq 'linux' ) {
|
||||||
|
@scan_outputA = grep( !/st[0-9]/, @scan_outputA ); # SCSI tape drive
|
||||||
|
@scan_outputA = grep( !/ht[0-9]/, @scan_outputA ); # ATA tape drive
|
||||||
|
}
|
||||||
|
|
||||||
|
# make the first pass, figuring out what all we have and trimming comments
|
||||||
|
foreach my $arguments (@scan_outputA) {
|
||||||
|
my $name = $arguments;
|
||||||
|
|
||||||
|
$arguments =~ s/ \#.*//; # trim the comment out of the argument
|
||||||
|
$name =~ s/ .*//;
|
||||||
|
$name =~ s/\/dev\///;
|
||||||
|
if ( defined( $found_disks_names{$name} ) ) {
|
||||||
|
$found_disks_names{$name}++;
|
||||||
|
} else {
|
||||||
|
$found_disks_names{$name} = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
push( @argumentsA, $arguments );
|
||||||
|
|
||||||
|
} ## end foreach my $arguments (@scan_outputA)
|
||||||
|
|
||||||
|
# second pass, putting the lines together
|
||||||
|
my %current_disk;
|
||||||
|
foreach my $arguments (@argumentsA) {
|
||||||
|
my $not_virt = 1;
|
||||||
|
|
||||||
|
# check to see if we have a virtual device
|
||||||
|
my @virt_check = split( /\n/, `smartctl -i $arguments 2> /dev/null` );
|
||||||
|
foreach my $virt_check_line (@virt_check) {
|
||||||
|
if ( $virt_check_line =~ /(?i)Product\:.*LOGICAL VOLUME/ ) {
|
||||||
|
$not_virt = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
my $name = $arguments;
|
||||||
|
$name =~ s/ .*//;
|
||||||
|
$name =~ s/\/dev\///;
|
||||||
|
|
||||||
|
# only add it if not a virtual RAID drive
|
||||||
|
# HP RAID virtual disks will show up with very basical but totally useless smart data
|
||||||
|
if ($not_virt) {
|
||||||
|
if ( $found_disks_names{$name} == 0 ) {
|
||||||
|
# If no other devices, just name it after the base device.
|
||||||
|
$drive_lines = $drive_lines . $name . " " . $arguments . "\n";
|
||||||
|
} else {
|
||||||
|
# if more than one, start at zero and increment, apennding comma number to the base device name
|
||||||
|
if ( defined( $current_disk{$name} ) ) {
|
||||||
|
$current_disk{$name}++;
|
||||||
|
} else {
|
||||||
|
$current_disk{$name} = 0;
|
||||||
|
}
|
||||||
|
$drive_lines = $drive_lines . $name . "," . $current_disk{$name} . " " . $arguments . "\n";
|
||||||
|
}
|
||||||
|
} ## end if ($not_virt)
|
||||||
|
|
||||||
|
} ## end foreach my $arguments (@argumentsA)
|
||||||
|
} ## end if ( $scan_modes->{'scan-open'} || $scan_modes...)
|
||||||
|
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# scan mode handler for cciss_vol_status
|
||||||
|
# /dev/sg* devices for cciss on Linux
|
||||||
|
# /dev/ccis* devices for cciss on FreeBSD
|
||||||
|
#
|
||||||
|
#
|
||||||
|
if ( $scan_modes->{'cciss_vol_status'} && ( $^O eq 'linux' || $^O eq 'freebsd' ) ) {
|
||||||
|
my $cciss;
|
||||||
|
if ( $^O eq 'freebsd' ) {
|
||||||
|
$cciss = 'ciss';
|
||||||
|
} elsif ( $^O eq 'linux' ) {
|
||||||
|
$cciss = 'sg';
|
||||||
|
}
|
||||||
|
|
||||||
|
my $uarg = '';
|
||||||
|
if ( $opts{U} ) {
|
||||||
|
$uarg = '-u';
|
||||||
|
}
|
||||||
|
|
||||||
|
# generate the initial device path that will be checked
|
||||||
|
my $sg_int = 0;
|
||||||
|
my $device = '/dev/' . $cciss . $sg_int;
|
||||||
|
|
||||||
|
my $sg_process = 1;
|
||||||
|
if ( -e $device ) {
|
||||||
|
my $output = `which cciss_vol_status 2> /dev/null`;
|
||||||
|
if ( $? != 0 && !$opts{C} ) {
|
||||||
|
$sg_process = 0;
|
||||||
|
$drive_lines
|
||||||
|
= $drive_lines
|
||||||
|
. "# -C not given, but "
|
||||||
|
. $device
|
||||||
|
. " exists and cciss_vol_status is not present\n"
|
||||||
|
. "# in path or 'ccis_vol_status -V "
|
||||||
|
. $device
|
||||||
|
. "' is failing\n";
|
||||||
|
} ## end if ( $? != 0 && !$opts{C} )
|
||||||
|
} ## end if ( -e $device )
|
||||||
|
my $seen_lines = {};
|
||||||
|
my $ignore_lines = {};
|
||||||
|
while ( -e $device && $sg_process ) {
|
||||||
|
my $output = `cciss_vol_status -V $uarg $device 2> /dev/null`;
|
||||||
|
if ( $? != 0 && $output eq '' && !$opts{C} ) {
|
||||||
|
# just empty here as we just want to skip it if it fails and there is no C
|
||||||
|
# warning is above
|
||||||
|
} elsif ( $? != 0 && $output eq '' && $opts{C} ) {
|
||||||
|
my $drive_count = 0;
|
||||||
|
my $continue = 1;
|
||||||
|
while ($continue) {
|
||||||
|
my $output = `$smartctl -i $device -d cciss,$drive_count 2> /dev/null`;
|
||||||
|
if ( $? != 0 ) {
|
||||||
|
$continue = 0;
|
||||||
|
} else {
|
||||||
|
my $add_it = 0;
|
||||||
|
my $id;
|
||||||
|
while ( $output =~ /(?i)Serial Number:(.*)/g ) {
|
||||||
|
$id = $1;
|
||||||
|
$id =~ s/^\s+|\s+$//g;
|
||||||
|
}
|
||||||
|
if ( defined($id) && !defined( $seen_lines->{$id} ) ) {
|
||||||
|
$add_it = 1;
|
||||||
|
$seen_lines->{$id} = 1;
|
||||||
|
}
|
||||||
|
if ( $continue && $add_it ) {
|
||||||
|
$drive_lines
|
||||||
|
= $drive_lines
|
||||||
|
. $cciss . '0-'
|
||||||
|
. $drive_count . ' '
|
||||||
|
. $device
|
||||||
|
. ' -d cciss,'
|
||||||
|
. $drive_count . "\n";
|
||||||
|
}
|
||||||
|
} ## end else [ if ( $? != 0 ) ]
|
||||||
|
$drive_count++;
|
||||||
|
} ## end while ($continue)
|
||||||
|
} else {
|
||||||
|
my $drive_count = 0;
|
||||||
|
# count the connector lines, this will make sure failed are founded as well
|
||||||
|
my $seen_conectors = {};
|
||||||
|
while ( $output =~ /(connector +\d+[IA]\ +box +\d+\ +bay +\d+.*)/g ) {
|
||||||
|
my $cciss_drive_line = $1;
|
||||||
|
my $connector = $cciss_drive_line;
|
||||||
|
$connector =~ s/(.*\ bay +\d+).*/$1/;
|
||||||
|
if ( !defined( $seen_lines->{$cciss_drive_line} )
|
||||||
|
&& !defined( $seen_conectors->{$connector} )
|
||||||
|
&& !defined( $ignore_lines->{$cciss_drive_line} ) )
|
||||||
|
{
|
||||||
|
$seen_lines->{$cciss_drive_line} = 1;
|
||||||
|
$seen_conectors->{$connector} = 1;
|
||||||
|
$drive_count++;
|
||||||
|
} else {
|
||||||
|
# going to be a connector we've already seen
|
||||||
|
# which will happen when it is processing replacement drives
|
||||||
|
# so save this as a device to ignore
|
||||||
|
$ignore_lines->{$cciss_drive_line} = 1;
|
||||||
|
}
|
||||||
|
} ## end while ( $output =~ /(connector +\d+[IA]\ +box +\d+\ +bay +\d+.*)/g)
|
||||||
|
my $drive_int = 0;
|
||||||
|
while ( $drive_int < $drive_count ) {
|
||||||
|
$drive_lines
|
||||||
|
= $drive_lines
|
||||||
|
. $cciss
|
||||||
|
. $sg_int . '-'
|
||||||
|
. $drive_int . ' '
|
||||||
|
. $device
|
||||||
|
. ' -d cciss,'
|
||||||
|
. $drive_int . "\n";
|
||||||
|
|
||||||
|
$drive_int++;
|
||||||
|
} ## end while ( $drive_int < $drive_count )
|
||||||
|
} ## end else [ if ( $? != 0 && $output eq '' && !$opts{C})]
|
||||||
|
|
||||||
|
$sg_int++;
|
||||||
|
$device = '/dev/' . $cciss . $sg_int;
|
||||||
|
} ## end while ( -e $device && $sg_process )
|
||||||
|
} ## end if ( $scan_modes->{'cciss_vol_status'} && ...)
|
||||||
|
|
||||||
|
my $useSN = 1;
|
||||||
|
if ( $opts{S} ) {
|
||||||
|
$useSN = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
print '# scan_modes='
|
||||||
|
. $opts{G}
|
||||||
|
. "\nuseSN="
|
||||||
|
. $useSN . "\n"
|
||||||
|
. 'smartctl='
|
||||||
|
. $smartctl . "\n"
|
||||||
|
. $cache
|
||||||
|
. $drive_lines;
|
||||||
|
|
||||||
|
exit 0;
|
||||||
|
} ## end if ( defined( $opts{g} ) )
|
||||||
|
|
||||||
|
#get which config file to use
|
||||||
|
my $config = $0 . '.config';
|
||||||
|
if ( defined( $opts{c} ) ) {
|
||||||
|
$config = $opts{c};
|
||||||
|
}
|
||||||
|
|
||||||
|
#reads the config file, optionally
|
||||||
|
my $config_file = '';
|
||||||
|
open( my $readfh, "<", $config ) or die "Can't open '" . $config . "'";
|
||||||
|
read( $readfh, $config_file, 1000000 );
|
||||||
|
close($readfh);
|
||||||
|
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# parse the config file and remove comments and empty lines
|
||||||
|
#
|
||||||
|
#
|
||||||
|
my @configA = split( /\n/, $config_file );
|
||||||
|
@configA = grep( !/^$/, @configA );
|
||||||
|
@configA = grep( !/^\#/, @configA );
|
||||||
|
@configA = grep( !/^[\s\t]*$/, @configA );
|
||||||
|
my $configA_int = 0;
|
||||||
|
while ( defined( $configA[$configA_int] ) ) {
|
||||||
|
my $line = $configA[$configA_int];
|
||||||
|
chomp($line);
|
||||||
|
$line =~ s/^[\t\s]+//;
|
||||||
|
$line =~ s/[\t\s]+$//;
|
||||||
|
|
||||||
|
my ( $var, $val ) = split( /=/, $line, 2 );
|
||||||
|
|
||||||
|
my $matched;
|
||||||
|
if ( $var eq 'cache' ) {
|
||||||
|
$cache = $val;
|
||||||
|
$matched = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $var eq 'smartctl' ) {
|
||||||
|
$smartctl = $val;
|
||||||
|
$matched = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $var eq 'useSN' ) {
|
||||||
|
$useSN = $val;
|
||||||
|
$matched = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !defined($val) ) {
|
||||||
|
push( @disks, $line );
|
||||||
|
}
|
||||||
|
|
||||||
|
$configA_int++;
|
||||||
|
} ## end while ( defined( $configA[$configA_int] ) )
|
||||||
|
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# run the specified self test on all disks if asked
|
||||||
|
#
|
||||||
|
#
|
||||||
|
if ( defined( $opts{t} ) ) {
|
||||||
|
|
||||||
|
# make sure we have something that atleast appears sane for the test name
|
||||||
|
my $valid_tesks = {
|
||||||
|
'offline' => 1,
|
||||||
|
'short' => 1,
|
||||||
|
'long' => 1,
|
||||||
|
'conveyance' => 1,
|
||||||
|
'afterselect,on' => 1,
|
||||||
|
};
|
||||||
|
if ( !defined( $valid_tesks->{ $opts{t} } ) && $opts{t} !~ /select,(\d+[\-\+]\d+|next|next\+\d+|redo\+\d+)/ ) {
|
||||||
|
print '"' . $opts{t} . "\" does not appear to be a valid test\n";
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
print "Running the SMART $opts{t} on all devices in the config...\n\n";
|
||||||
|
|
||||||
|
foreach my $line (@disks) {
|
||||||
|
my $disk;
|
||||||
|
my $name;
|
||||||
|
if ( $line =~ /\ / ) {
|
||||||
|
( $name, $disk ) = split( /\ /, $line, 2 );
|
||||||
|
} else {
|
||||||
|
$disk = $line;
|
||||||
|
$name = $line;
|
||||||
|
}
|
||||||
|
if ( $disk !~ /\// ) {
|
||||||
|
$disk = '/dev/' . $disk;
|
||||||
|
}
|
||||||
|
|
||||||
|
print "\n------------------------------------------------------------------\nDoing "
|
||||||
|
. $smartctl . ' -t '
|
||||||
|
. $opts{t} . ' '
|
||||||
|
. $disk
|
||||||
|
. " ...\n\n";
|
||||||
|
print `$smartctl -t $opts{t} $disk` . "\n";
|
||||||
|
|
||||||
|
} ## end foreach my $line (@disks)
|
||||||
|
|
||||||
|
exit 0;
|
||||||
|
} ## end if ( defined( $opts{t} ) )
|
||||||
|
|
||||||
|
#if set to 1, no cache will be written and it will be printed instead
|
||||||
|
my $noWrite = 0;
|
||||||
|
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# if no -u, it means we are being called from snmped
|
||||||
|
#
|
||||||
|
#
|
||||||
|
if ( !defined( $opts{u} ) ) {
|
||||||
|
# if the cache file exists, print it, otherwise assume one is not being used
|
||||||
|
if ( -f $cache ) {
|
||||||
|
my $old = '';
|
||||||
|
open( my $readfh, "<", $cache ) or die "Can't open '" . $cache . "'";
|
||||||
|
read( $readfh, $old, 1000000 );
|
||||||
|
close($readfh);
|
||||||
|
print $old;
|
||||||
|
exit 0;
|
||||||
|
} else {
|
||||||
|
$opts{u} = 1;
|
||||||
|
$noWrite = 1;
|
||||||
|
}
|
||||||
|
} ## end if ( !defined( $opts{u} ) )
|
||||||
|
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Process each disk
|
||||||
|
#
|
||||||
|
#
|
||||||
|
my $to_return = {
|
||||||
|
data => { disks => {}, exit_nonzero => 0, unhealthy => 0, useSN => $useSN },
|
||||||
|
version => 1,
|
||||||
|
error => 0,
|
||||||
|
errorString => '',
|
||||||
|
};
|
||||||
|
foreach my $line (@disks) {
|
||||||
|
my $disk;
|
||||||
|
my $name;
|
||||||
|
if ( $line =~ /\ / ) {
|
||||||
|
( $name, $disk ) = split( /\ /, $line, 2 );
|
||||||
|
} else {
|
||||||
|
$disk = $line;
|
||||||
|
$name = $line;
|
||||||
|
}
|
||||||
|
if ( $disk !~ /\// ) {
|
||||||
|
$disk = '/dev/' . $disk;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $output = `$smartctl -A $disk`;
|
||||||
|
my %IDs = (
|
||||||
|
'5' => 'null',
|
||||||
|
'10' => 'null',
|
||||||
|
'173' => 'null',
|
||||||
|
'177' => 'null',
|
||||||
|
'183' => 'null',
|
||||||
|
'184' => 'null',
|
||||||
|
'187' => 'null',
|
||||||
|
'188' => 'null',
|
||||||
|
'190' => 'null',
|
||||||
|
'194' => 'null',
|
||||||
|
'196' => 'null',
|
||||||
|
'197' => 'null',
|
||||||
|
'198' => 'null',
|
||||||
|
'199' => 'null',
|
||||||
|
'231' => 'null',
|
||||||
|
'232' => 'null',
|
||||||
|
'233' => 'null',
|
||||||
|
'9' => 'null',
|
||||||
|
'disk' => $disk,
|
||||||
|
'serial' => undef,
|
||||||
|
'selftest_log' => undef,
|
||||||
|
'health_pass' => 0,
|
||||||
|
max_temp => 'null',
|
||||||
|
exit => $?,
|
||||||
|
);
|
||||||
|
$IDs{'disk'} =~ s/^\/dev\///;
|
||||||
|
|
||||||
|
# if polling exited non-zero above, no reason running the rest of the checks
|
||||||
|
my $disk_id = $name;
|
||||||
|
if ( $IDs{exit} != 0 ) {
|
||||||
|
$to_return->{data}{exit_nonzero}++;
|
||||||
|
} else {
|
||||||
|
my @outputA;
|
||||||
|
|
||||||
|
if ( $output =~ /NVMe Log/ ) {
|
||||||
|
# we have an NVMe drive with annoyingly different output
|
||||||
|
my %mappings = (
|
||||||
|
'Temperature' => 194,
|
||||||
|
'Power Cycles' => 12,
|
||||||
|
'Power On Hours' => 9,
|
||||||
|
'Percentage Used' => 231,
|
||||||
|
);
|
||||||
|
foreach ( split( /\n/, $output ) ) {
|
||||||
|
if (/:/) {
|
||||||
|
my ( $key, $val ) = split(/:/);
|
||||||
|
$val =~ s/^\s+|\s+$|\D+//g;
|
||||||
|
if ( exists( $mappings{$key} ) ) {
|
||||||
|
if ( $mappings{$key} == 231 ) {
|
||||||
|
$IDs{ $mappings{$key} } = 100 - $val;
|
||||||
|
} else {
|
||||||
|
$IDs{ $mappings{$key} } = $val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} ## end if (/:/)
|
||||||
|
} ## end foreach ( split( /\n/, $output ) )
|
||||||
|
|
||||||
|
} else {
|
||||||
|
@outputA = split( /\n/, $output );
|
||||||
|
my $outputAint = 0;
|
||||||
|
while ( defined( $outputA[$outputAint] ) ) {
|
||||||
|
my $line = $outputA[$outputAint];
|
||||||
|
$line =~ s/^ +//;
|
||||||
|
$line =~ s/ +/ /g;
|
||||||
|
|
||||||
|
if ( $line =~ /^[0123456789]+ / ) {
|
||||||
|
my @lineA = split( /\ /, $line, 10 );
|
||||||
|
my $raw = $lineA[9];
|
||||||
|
my $normalized = $lineA[3];
|
||||||
|
my $id = $lineA[0];
|
||||||
|
|
||||||
|
# Crucial SSD
|
||||||
|
# 202, Percent_Lifetime_Remain, same as 231, SSD Life Left
|
||||||
|
if ( $id == 202
|
||||||
|
&& $line =~ /Percent_Lifetime_Remain/ )
|
||||||
|
{
|
||||||
|
$IDs{231} = $raw;
|
||||||
|
}
|
||||||
|
|
||||||
|
# single int raw values
|
||||||
|
if ( ( $id == 5 )
|
||||||
|
|| ( $id == 10 )
|
||||||
|
|| ( $id == 173 )
|
||||||
|
|| ( $id == 183 )
|
||||||
|
|| ( $id == 184 )
|
||||||
|
|| ( $id == 187 )
|
||||||
|
|| ( $id == 196 )
|
||||||
|
|| ( $id == 197 )
|
||||||
|
|| ( $id == 198 )
|
||||||
|
|| ( $id == 199 ) )
|
||||||
|
{
|
||||||
|
my @rawA = split( /\ /, $raw );
|
||||||
|
$IDs{$id} = $rawA[0];
|
||||||
|
} ## end if ( ( $id == 5 ) || ( $id == 10 ) || ( $id...))
|
||||||
|
|
||||||
|
# single int normalized values
|
||||||
|
if ( ( $id == 177 )
|
||||||
|
|| ( $id == 230 )
|
||||||
|
|| ( $id == 231 )
|
||||||
|
|| ( $id == 232 )
|
||||||
|
|| ( $id == 233 ) )
|
||||||
|
{
|
||||||
|
# annoying non-standard disk
|
||||||
|
# WDC WDS500G2B0A
|
||||||
|
# 230 Media_Wearout_Indicator 0x0032 100 100 --- Old_age Always - 0x002e000a002e
|
||||||
|
# 232 Available_Reservd_Space 0x0033 100 100 004 Pre-fail Always - 100
|
||||||
|
# 233 NAND_GB_Written_TLC 0x0032 100 100 --- Old_age Always - 9816
|
||||||
|
|
||||||
|
if ( $id == 230
|
||||||
|
&& $line =~ /Media_Wearout_Indicator/ )
|
||||||
|
{
|
||||||
|
$IDs{233} = int($normalized);
|
||||||
|
} elsif ( $id == 232
|
||||||
|
&& $line =~ /Available_Reservd_Space/ )
|
||||||
|
{
|
||||||
|
$IDs{232} = int($normalized);
|
||||||
|
} else {
|
||||||
|
# only set 233 if it has not been set yet
|
||||||
|
# if it was set already then the above did it and we don't want
|
||||||
|
# to overwrite it
|
||||||
|
if ( $id == 233 && $IDs{233} eq "null" ) {
|
||||||
|
$IDs{$id} = int($normalized);
|
||||||
|
} elsif ( $id != 233 ) {
|
||||||
|
$IDs{$id} = int($normalized);
|
||||||
|
}
|
||||||
|
} ## end else [ if ( $id == 230 && $line =~ /Media_Wearout_Indicator/)]
|
||||||
|
} ## end if ( ( $id == 177 ) || ( $id == 230 ) || (...))
|
||||||
|
|
||||||
|
# 9, power on hours
|
||||||
|
if ( $id == 9 ) {
|
||||||
|
my @runtime = split( /[\ h]/, $raw );
|
||||||
|
$IDs{$id} = $runtime[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
# 188, Command_Timeout
|
||||||
|
if ( $id == 188 ) {
|
||||||
|
my $total = 0;
|
||||||
|
my @rawA = split( /\ /, $raw );
|
||||||
|
my $rawAint = 0;
|
||||||
|
while ( defined( $rawA[$rawAint] ) ) {
|
||||||
|
$total = $total + $rawA[$rawAint];
|
||||||
|
$rawAint++;
|
||||||
|
}
|
||||||
|
$IDs{$id} = $total;
|
||||||
|
} ## end if ( $id == 188 )
|
||||||
|
|
||||||
|
# 190, airflow temp
|
||||||
|
# 194, temp
|
||||||
|
if ( ( $id == 190 )
|
||||||
|
|| ( $id == 194 ) )
|
||||||
|
{
|
||||||
|
my ($temp) = split( /\ /, $raw );
|
||||||
|
$IDs{$id} = $temp;
|
||||||
|
}
|
||||||
|
} ## end if ( $line =~ /^[0123456789]+ / )
|
||||||
|
|
||||||
|
# SAS Wrapping
|
||||||
|
# Section by Cameron Munroe (munroenet[at]gmail.com)
|
||||||
|
|
||||||
|
# Elements in Grown Defect List.
|
||||||
|
# Marking as 5 Reallocated_Sector_Ct
|
||||||
|
if ( $line =~ "Elements in grown defect list:" ) {
|
||||||
|
|
||||||
|
my @lineA = split( /\ /, $line, 10 );
|
||||||
|
my $raw = $lineA[5];
|
||||||
|
|
||||||
|
# Reallocated Sector Count ID
|
||||||
|
$IDs{5} = $raw;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
# Current Drive Temperature
|
||||||
|
# Marking as 194 Temperature_Celsius
|
||||||
|
if ( $line =~ "Current Drive Temperature:" ) {
|
||||||
|
|
||||||
|
my @lineA = split( /\ /, $line, 10 );
|
||||||
|
my $raw = $lineA[3];
|
||||||
|
|
||||||
|
# Temperature C ID
|
||||||
|
$IDs{194} = $raw;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
# End of SAS Wrapper
|
||||||
|
|
||||||
|
$outputAint++;
|
||||||
|
} ## end while ( defined( $outputA[$outputAint] ) )
|
||||||
|
} ## end else [ if ( $output =~ /NVMe Log/ ) ]
|
||||||
|
|
||||||
|
#get the selftest logs
|
||||||
|
$output = `$smartctl -l selftest $disk`;
|
||||||
|
@outputA = split( /\n/, $output );
|
||||||
|
my @completed = grep( /Completed/, @outputA );
|
||||||
|
$IDs{'completed'} = scalar @completed;
|
||||||
|
my @interrupted = grep( /Interrupted/, @outputA );
|
||||||
|
$IDs{'interrupted'} = scalar @interrupted;
|
||||||
|
my @read_failure = grep( /read failure/, @outputA );
|
||||||
|
$IDs{'read_failure'} = scalar @read_failure;
|
||||||
|
my @read_failure2 = grep( /Failed in segment/, @outputA );
|
||||||
|
$IDs{'read_failure'} = $IDs{'read_failure'} + scalar @read_failure2;
|
||||||
|
my @unknown_failure = grep( /unknown failure/, @outputA );
|
||||||
|
$IDs{'unknown_failure'} = scalar @unknown_failure;
|
||||||
|
my @extended = grep( /\d.*\ ([Ee]xtended|[Ll]ong).*(?![Dd]uration)/, @outputA );
|
||||||
|
$IDs{'extended'} = scalar @extended;
|
||||||
|
my @short = grep( /[Ss]hort/, @outputA );
|
||||||
|
$IDs{'short'} = scalar @short;
|
||||||
|
my @conveyance = grep( /[Cc]onveyance/, @outputA );
|
||||||
|
$IDs{'conveyance'} = scalar @conveyance;
|
||||||
|
my @selective = grep( /[Ss]elective/, @outputA );
|
||||||
|
$IDs{'selective'} = scalar @selective;
|
||||||
|
my @offline = grep( /(\d|[Bb]ackground|[Ff]oreground)+\ +[Oo]ffline/, @outputA );
|
||||||
|
$IDs{'offline'} = scalar @offline;
|
||||||
|
|
||||||
|
# if we have logs, actually grab the log output
|
||||||
|
if ( $IDs{'completed'} > 0
|
||||||
|
|| $IDs{'interrupted'} > 0
|
||||||
|
|| $IDs{'read_failure'} > 0
|
||||||
|
|| $IDs{'extended'} > 0
|
||||||
|
|| $IDs{'short'} > 0
|
||||||
|
|| $IDs{'conveyance'} > 0
|
||||||
|
|| $IDs{'selective'} > 0
|
||||||
|
|| $IDs{'offline'} > 0 )
|
||||||
|
{
|
||||||
|
my @headers = grep( /(Num\ +Test.*LBA| Description .*[Hh]ours)/, @outputA );
|
||||||
|
|
||||||
|
my @log_lines;
|
||||||
|
push( @log_lines, @extended, @short, @conveyance, @selective, @offline );
|
||||||
|
$IDs{'selftest_log'} = join( "\n", @headers, sort(@log_lines) );
|
||||||
|
} ## end if ( $IDs{'completed'} > 0 || $IDs{'interrupted'...})
|
||||||
|
|
||||||
|
# get the drive serial number, if needed
|
||||||
|
$disk_id = $name;
|
||||||
|
$output = `$smartctl -i $disk`;
|
||||||
|
# generally upper case, HP branded drives seem to report with lower case n
|
||||||
|
while ( $output =~ /(?i)Serial Number:(.*)/g ) {
|
||||||
|
$IDs{'serial'} = $1;
|
||||||
|
$IDs{'serial'} =~ s/^\s+|\s+$//g;
|
||||||
|
}
|
||||||
|
if ($useSN) {
|
||||||
|
$disk_id = $IDs{'serial'};
|
||||||
|
}
|
||||||
|
|
||||||
|
while ( $output =~ /(?i)Model Family:(.*)/g ) {
|
||||||
|
$IDs{'model_family'} = $1;
|
||||||
|
$IDs{'model_family'} =~ s/^\s+|\s+$//g;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ( $output =~ /(?i)Device Model:(.*)/g ) {
|
||||||
|
$IDs{'device_model'} = $1;
|
||||||
|
$IDs{'device_model'} =~ s/^\s+|\s+$//g;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ( $output =~ /(?i)Model Number:(.*)/g ) {
|
||||||
|
$IDs{'model_number'} = $1;
|
||||||
|
$IDs{'model_number'} =~ s/^\s+|\s+$//g;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ( $output =~ /(?i)Firmware Version:(.*)/g ) {
|
||||||
|
$IDs{'fw_version'} = $1;
|
||||||
|
$IDs{'fw_version'} =~ s/^\s+|\s+$//g;
|
||||||
|
}
|
||||||
|
|
||||||
|
# mainly HP drives
|
||||||
|
while ( $output =~ /(?i)Vendor:(.*)/g ) {
|
||||||
|
$IDs{'vendor'} = $1;
|
||||||
|
$IDs{'vendor'} =~ s/^\s+|\s+$//g;
|
||||||
|
}
|
||||||
|
|
||||||
|
# mainly HP drives
|
||||||
|
while ( $output =~ /(?i)Product:(.*)/g ) {
|
||||||
|
$IDs{'product'} = $1;
|
||||||
|
$IDs{'product'} =~ s/^\s+|\s+$//g;
|
||||||
|
}
|
||||||
|
|
||||||
|
# mainly HP drives
|
||||||
|
while ( $output =~ /(?i)Revision:(.*)/g ) {
|
||||||
|
$IDs{'revision'} = $1;
|
||||||
|
$IDs{'revision'} =~ s/^\s+|\s+$//g;
|
||||||
|
}
|
||||||
|
|
||||||
|
# figure out what to use for the max temp, if there is one
|
||||||
|
if ( $IDs{'190'} =~ /^\d+$/ ) {
|
||||||
|
$IDs{max_temp} = $IDs{'190'};
|
||||||
|
} elsif ( $IDs{'194'} =~ /^\d+$/ ) {
|
||||||
|
$IDs{max_temp} = $IDs{'194'};
|
||||||
|
}
|
||||||
|
if ( $IDs{'194'} =~ /^\d+$/ && defined( $IDs{max_temp} ) && $IDs{'194'} > $IDs{max_temp} ) {
|
||||||
|
$IDs{max_temp} = $IDs{'194'};
|
||||||
|
}
|
||||||
|
|
||||||
|
$output = `$smartctl -H $disk`;
|
||||||
|
if ( $output =~ /SMART\ overall\-health\ self\-assessment\ test\ result\:\ PASSED/ ) {
|
||||||
|
$IDs{'health_pass'} = 1;
|
||||||
|
} elsif ( $output =~ /SMART\ Health\ Status\:\ OK/ ) {
|
||||||
|
$IDs{'health_pass'} = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !$IDs{'health_pass'} ) {
|
||||||
|
$to_return->{data}{unhealthy}++;
|
||||||
|
}
|
||||||
|
} ## end else [ if ( $IDs{exit} != 0 ) ]
|
||||||
|
|
||||||
|
# only bother to save this if useSN is not being used
|
||||||
|
if ( !$useSN ) {
|
||||||
|
$to_return->{data}{disks}{$disk_id} = \%IDs;
|
||||||
|
} elsif ( $IDs{exit} == 0 && defined($disk_id) ) {
|
||||||
|
$to_return->{data}{disks}{$disk_id} = \%IDs;
|
||||||
|
}
|
||||||
|
|
||||||
|
# smartctl will in some cases exit zero when it can't pull data for cciss
|
||||||
|
# so if we get a zero exit, but no serial then it means something errored
|
||||||
|
# and the device is likely dead
|
||||||
|
if ( $IDs{exit} == 0 && !defined( $IDs{serial} ) ) {
|
||||||
|
$to_return->{data}{unhealthy}++;
|
||||||
|
}
|
||||||
|
} ## end foreach my $line (@disks)
|
||||||
|
|
||||||
|
my $toReturn = $json->encode($to_return);
|
||||||
|
|
||||||
|
if ( !$opts{p} ) {
|
||||||
|
$toReturn = $toReturn . "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $opts{Z} ) {
|
||||||
|
my $toReturnCompressed;
|
||||||
|
gzip \$toReturn => \$toReturnCompressed;
|
||||||
|
my $compressed = encode_base64($toReturnCompressed);
|
||||||
|
$compressed =~ s/\n//g;
|
||||||
|
$compressed = $compressed . "\n";
|
||||||
|
if ( length($compressed) < length($toReturn) ) {
|
||||||
|
$toReturn = $compressed;
|
||||||
|
}
|
||||||
|
} ## end if ( $opts{Z} )
|
||||||
|
|
||||||
|
if ( !$noWrite ) {
|
||||||
|
open( my $writefh, ">", $cache ) or die "Can't open '" . $cache . "'";
|
||||||
|
print $writefh $toReturn;
|
||||||
|
close($writefh);
|
||||||
|
} else {
|
||||||
|
print $toReturn;
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
smartctl=/usr/sbin/smartctl
|
||||||
|
cache=/var/cache/smart
|
||||||
|
sda
|
||||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,45 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
################################################################
|
||||||
|
# Instructions: #
|
||||||
|
# 1. copy this script to /etc/snmp/ and make it executable: #
|
||||||
|
# chmod +x ups-nut.sh #
|
||||||
|
# 2. make sure UPS_NAME below matches the name of your UPS #
|
||||||
|
# 3. edit your snmpd.conf to include this line: #
|
||||||
|
# extend ups-nut /etc/snmp/ups-nut.sh #
|
||||||
|
# 4. restart snmpd on the host #
|
||||||
|
# 5. activate the app for the desired host in LibreNMS #
|
||||||
|
################################################################
|
||||||
|
UPS_NAME="${1:-APCUPS}"
|
||||||
|
|
||||||
|
PATH=$PATH:/usr/bin:/bin
|
||||||
|
TMP=$(upsc "$UPS_NAME" 2>/dev/null)
|
||||||
|
|
||||||
|
for value in "battery\.charge: [0-9.]+" "battery\.(runtime\.)?low: [0-9]+" "battery\.runtime: [0-9]+" "battery\.voltage: [0-9.]+" "battery\.voltage\.nominal: [0-9]+" "input\.voltage\.nominal: [0-9.]+" "input\.voltage: [0-9.]+" "ups\.load: [0-9.]+"
|
||||||
|
do
|
||||||
|
OUT=$(echo "$TMP" | grep -Eo "$value" | awk '{print $2}' | LANG=C sort | head -n 1)
|
||||||
|
if [ -n "$OUT" ]; then
|
||||||
|
echo "$OUT"
|
||||||
|
else
|
||||||
|
echo "Unknown"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
for value in "ups\.status:[A-Z ]{0,}OL" "ups\.status:[A-Z ]{0,}OB" "ups\.status:[A-Z ]{0,}LB" "ups\.status:[A-Z ]{0,}HB" "ups\.status:[A-Z ]{0,}RB" "ups\.status:[A-Z ]{0,}CHRG" "ups\.status:[A-Z ]{0,}DISCHRG" "ups\.status:[A-Z ]{0,}BYPASS" "ups\.status:[A-Z ]{0,}CAL" "ups\.status:[A-Z ]{0,}OFF" "ups\.status:[A-Z ]{0,}OVER" "ups\.status:[A-Z ]{0,}TRIM" "ups\.status:[A-Z ]{0,}BOOST" "ups\.status:[A-Z ]{0,}FSD" "ups\.alarm:[A-Z ]"
|
||||||
|
do
|
||||||
|
UNKNOWN=$(echo "$TMP" | grep -Eo "ups\.status:")
|
||||||
|
if [ -z "$UNKNOWN" ]; then
|
||||||
|
echo "Unknown"
|
||||||
|
else
|
||||||
|
OUT=$(echo "$TMP" | grep -Eo "$value")
|
||||||
|
if [ -n "$OUT" ]; then
|
||||||
|
echo "1"
|
||||||
|
else
|
||||||
|
echo "0"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
UPSTEMP="ups\.temperature: [0-9.]+"
|
||||||
|
OUT=$(echo "$TMP" | grep -Eo "$UPSTEMP" | awk '{print $2}' | LANG=C sort | head -n 1)
|
||||||
|
[ -n "$OUT" ] && echo "$OUT" || echo "Unknown"
|
||||||
|
|
||||||
Executable
+30
@@ -0,0 +1,30 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# garage-pdu-relay: expose APC AP7830 metered output current via snmpd extend.
|
||||||
|
#
|
||||||
|
# Relay pattern (founder ruling 2026-09-02): the garage PDU speaks SNMPv1
|
||||||
|
# only, walks die on its old AOS, and its ACL admits the LibreNMS VM vantage.
|
||||||
|
# This relay runs ON tsys-librenms; HA polls the relay via the fleet snmpd
|
||||||
|
# extend (same rails as drac-extend). Output: "output_amps <x.y>".
|
||||||
|
#
|
||||||
|
# Deploy target: tsys-librenms:/usr/local/bin/garage-pdu-relay ONLY (relay
|
||||||
|
# host — not a per-host agent). snmpd.conf line on the relay host:
|
||||||
|
# extend garagepdu /usr/local/bin/garage-pdu-relay
|
||||||
|
# snmpd ACL must admit the pfv-bms LAN + Tailscale IPs as query sources
|
||||||
|
# (rocommunity kn3lmgmt 192.168.3.12 / 100.67.108.125 as of 2026-09-03).
|
||||||
|
#
|
||||||
|
# Codified 2026-09-03 [#733]: was deployed manually 2026-09-02; hardened
|
||||||
|
# with explicit snmpget timeout/retry so a dark PDU answers in ~2s instead
|
||||||
|
# of ~6s and cannot pile up long-running children under HA's poll cadence.
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
PDU_HOST="${PDU_HOST:-pfv-garage-pdu-1.knel.net}"
|
||||||
|
COMMUNITY="${PDU_COMMUNITY:-kn3lmgmt}"
|
||||||
|
OID=".1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1"
|
||||||
|
|
||||||
|
raw=$(snmpget -v1 -c "$COMMUNITY" -t 2 -r 1 -On -Ov "$PDU_HOST" "$OID" 2>/dev/null \
|
||||||
|
| grep -oE '[0-9]+$') || true
|
||||||
|
if [ -z "${raw:-}" ]; then
|
||||||
|
echo "output_amps unavailable"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
awk -v t="$raw" 'BEGIN { printf "output_amps %.1f\n", t/10 }'
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
# Deploy the LibreNMS check_mk agent on a monitored host.
|
||||||
|
# Ported from KNELServerBuild ProjectCode/Modules/OAM/oam-librenms.sh [#474].
|
||||||
|
# Upstream agent scripts live in ./agent/ (kept verbatim, do not edit).
|
||||||
|
# snmpd sudo rules for the extends live in ./snmp-sudo.conf (install via
|
||||||
|
# sudoers policy separately — see AGENTS.md security-change rules).
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
AGENTS_PATH="$SCRIPT_DIR/agent"
|
||||||
|
|
||||||
|
echo "Setting up librenms agent..."
|
||||||
|
|
||||||
|
cat "$AGENTS_PATH/distro" > /usr/local/bin/distro
|
||||||
|
chmod +x /usr/local/bin/distro
|
||||||
|
|
||||||
|
mkdir -p /usr/lib/check_mk_agent/plugins
|
||||||
|
mkdir -p /usr/lib/check_mk_agent/local
|
||||||
|
|
||||||
|
cat "$AGENTS_PATH/check_mk_agent" > /usr/bin/check_mk_agent
|
||||||
|
chmod +x /usr/bin/check_mk_agent
|
||||||
|
|
||||||
|
cat "$AGENTS_PATH/check_mk@.service" > /etc/systemd/system/check_mk@.service
|
||||||
|
cat "$AGENTS_PATH/check_mk.socket" > /etc/systemd/system/check_mk.socket
|
||||||
|
|
||||||
|
systemctl enable check_mk.socket
|
||||||
|
systemctl start check_mk.socket
|
||||||
|
|
||||||
|
#Modules commented out below, we will roll out on systems that use them, most of the fleet doesn't use those modules
|
||||||
|
|
||||||
|
cat "$AGENTS_PATH/dmi.sh" > /usr/lib/check_mk_agent/local/dmi.sh
|
||||||
|
cat "$AGENTS_PATH/dpkg.sh" > /usr/lib/check_mk_agent/local/dpkg.sh
|
||||||
|
#cat "$AGENTS_PATH/mysql.sh" > /usr/lib/check_mk_agent/local/mysql.sh
|
||||||
|
cat "$AGENTS_PATH/ntp-client" > /usr/lib/check_mk_agent/local/ntp-client
|
||||||
|
#cat "$AGENTS_PATH/ntp-server.sh" > /usr/lib/check_mk_agent/local/ntp-server.sh
|
||||||
|
cat "$AGENTS_PATH/os-updates.sh" > /usr/lib/check_mk_agent/local/os-updates.sh
|
||||||
|
cat "$AGENTS_PATH/postfixdetailed" > /usr/lib/check_mk_agent/local/postfixdetailed
|
||||||
|
cat "$AGENTS_PATH/postfix-queues" > /usr/lib/check_mk_agent/local/postfix-queues
|
||||||
|
#cat "$AGENTS_PATH/smart.sh" > /usr/lib/check_mk_agent/local/smart
|
||||||
|
#cat "$AGENTS_PATH/smart.sh.config" > /usr/lib/check_mk_agent/local/smart.config
|
||||||
|
|
||||||
|
chmod +x /usr/lib/check_mk_agent/local/*
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Debian-snmp ALL = NOPASSWD: /bin/cat
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
# NetDisco deployment configuration [#337]
|
||||||
|
# SNMP community: kn3lmgmt (v2c)
|
||||||
|
|
||||||
|
# Database connection (matched to docker-compose services)
|
||||||
|
database:
|
||||||
|
host: netdisco-postgresql
|
||||||
|
dbname: netdisco
|
||||||
|
user: netdisco
|
||||||
|
pass: netdisco
|
||||||
|
|
||||||
|
# SNMP authentication
|
||||||
|
snmp_auth:
|
||||||
|
- tag: default_v2c
|
||||||
|
community: kn3lmgmt
|
||||||
|
read: true
|
||||||
|
write: false
|
||||||
|
version: 2
|
||||||
|
|
||||||
|
- tag: default_v1
|
||||||
|
community: kn3lmgmt
|
||||||
|
read: true
|
||||||
|
write: false
|
||||||
|
version: 1
|
||||||
|
|
||||||
|
# Job scheduling
|
||||||
|
schedule:
|
||||||
|
discoverall:
|
||||||
|
first: 60
|
||||||
|
every: 3600
|
||||||
|
macwalk:
|
||||||
|
first: 120
|
||||||
|
every: 900
|
||||||
|
arpwalk:
|
||||||
|
first: 150
|
||||||
|
every: 900
|
||||||
|
nbtwalk:
|
||||||
|
first: 180
|
||||||
|
every: 900
|
||||||
|
|
||||||
|
# Node freshness (keep history)
|
||||||
|
node_freshness: 0
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
services:
|
||||||
|
netdisco-postgresql:
|
||||||
|
image: netdisco/netdisco:2.102001-postgresql
|
||||||
|
container_name: oam-netdisco-db
|
||||||
|
environment:
|
||||||
|
- POSTGRES_USER=netdisco
|
||||||
|
- POSTGRES_PASSWORD=netdisco
|
||||||
|
- POSTGRES_DB=netdisco
|
||||||
|
volumes:
|
||||||
|
- /opt/oam/netdisco/pgdata:/var/lib/postgresql/data
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
netdisco-backend:
|
||||||
|
image: netdisco/netdisco:2.102001-backend
|
||||||
|
container_name: oam-netdisco-backend
|
||||||
|
depends_on:
|
||||||
|
- netdisco-postgresql
|
||||||
|
environment:
|
||||||
|
- NETDISCO_DB_HOST=netdisco-postgresql
|
||||||
|
- NETDISCO_DB_NAME=netdisco
|
||||||
|
- NETDISCO_DB_USER=netdisco
|
||||||
|
- NETDISCO_DB_PASS=netdisco
|
||||||
|
- NETDISCO_SNMP_COMMUNITY=kn3lmgmt
|
||||||
|
volumes:
|
||||||
|
- /opt/oam/netdisco/config/deployment.yml:/home/netdisco/environments/deployment.yml
|
||||||
|
- /opt/oam/netdisco/data:/home/netdisco/netdisco-sqlite
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
netdisco-web:
|
||||||
|
image: netdisco/netdisco:2.102001-web
|
||||||
|
container_name: oam-netdisco-web
|
||||||
|
depends_on:
|
||||||
|
- netdisco-postgresql
|
||||||
|
- netdisco-backend
|
||||||
|
environment:
|
||||||
|
- NETDISCO_DB_HOST=netdisco-postgresql
|
||||||
|
- NETDISCO_DB_NAME=netdisco
|
||||||
|
- NETDISCO_DB_USER=netdisco
|
||||||
|
- NETDISCO_DB_PASS=netdisco
|
||||||
|
ports:
|
||||||
|
- "8082:5000"
|
||||||
|
volumes:
|
||||||
|
- /opt/oam/netdisco/config/deployment.yml:/home/netdisco/environments/deployment.yml
|
||||||
|
restart: unless-stopped
|
||||||
@@ -0,0 +1,119 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# Deploy NetDisco on tsys-librenms
|
||||||
|
# Part of OAM platform [#337]
|
||||||
|
# L2 network discovery and mapping via SNMP
|
||||||
|
|
||||||
|
echo "=== Setting up NetDisco ==="
|
||||||
|
|
||||||
|
mkdir -p /opt/oam/netdisco/{config,data,pgdata}
|
||||||
|
|
||||||
|
# Write deployment config
|
||||||
|
cat > /opt/oam/netdisco/config/deployment.yml <<'YMLEOF'
|
||||||
|
# NetDisco deployment configuration [#337]
|
||||||
|
# SNMP community: kn3lmgmt (v2c)
|
||||||
|
|
||||||
|
database:
|
||||||
|
host: netdisco-postgresql
|
||||||
|
dbname: netdisco
|
||||||
|
user: netdisco
|
||||||
|
pass: netdisco
|
||||||
|
|
||||||
|
snmp_auth:
|
||||||
|
- tag: default_v2c
|
||||||
|
community: kn3lmgmt
|
||||||
|
read: true
|
||||||
|
write: false
|
||||||
|
version: 2
|
||||||
|
|
||||||
|
- tag: default_v1
|
||||||
|
community: kn3lmgmt
|
||||||
|
read: true
|
||||||
|
write: false
|
||||||
|
version: 1
|
||||||
|
|
||||||
|
schedule:
|
||||||
|
discoverall:
|
||||||
|
first: 60
|
||||||
|
every: 3600
|
||||||
|
macwalk:
|
||||||
|
first: 120
|
||||||
|
every: 900
|
||||||
|
arpwalk:
|
||||||
|
first: 150
|
||||||
|
every: 900
|
||||||
|
nbtwalk:
|
||||||
|
first: 180
|
||||||
|
every: 900
|
||||||
|
|
||||||
|
node_freshness: 0
|
||||||
|
YMLEOF
|
||||||
|
|
||||||
|
# Write docker-compose
|
||||||
|
cat > /opt/oam/netdisco/docker-compose.yml <<'DCEOF'
|
||||||
|
services:
|
||||||
|
netdisco-postgresql:
|
||||||
|
image: netdisco/netdisco:2.102001-postgresql
|
||||||
|
container_name: oam-netdisco-db
|
||||||
|
environment:
|
||||||
|
- POSTGRES_USER=netdisco
|
||||||
|
- POSTGRES_PASSWORD=netdisco
|
||||||
|
- POSTGRES_DB=netdisco
|
||||||
|
volumes:
|
||||||
|
- /opt/oam/netdisco/pgdata:/var/lib/postgresql/data
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
netdisco-backend:
|
||||||
|
image: netdisco/netdisco:2.102001-backend
|
||||||
|
container_name: oam-netdisco-backend
|
||||||
|
depends_on:
|
||||||
|
- netdisco-postgresql
|
||||||
|
environment:
|
||||||
|
- NETDISCO_DB_HOST=netdisco-postgresql
|
||||||
|
- NETDISCO_DB_NAME=netdisco
|
||||||
|
- NETDISCO_DB_USER=netdisco
|
||||||
|
- NETDISCO_DB_PASS=netdisco
|
||||||
|
volumes:
|
||||||
|
- /opt/oam/netdisco/config/deployment.yml:/home/netdisco/environments/deployment.yml
|
||||||
|
- /opt/oam/netdisco/data:/home/netdisco/netdisco-sqlite
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
netdisco-web:
|
||||||
|
image: netdisco/netdisco:2.102001-web
|
||||||
|
container_name: oam-netdisco-web
|
||||||
|
depends_on:
|
||||||
|
- netdisco-postgresql
|
||||||
|
- netdisco-backend
|
||||||
|
environment:
|
||||||
|
- NETDISCO_DB_HOST=netdisco-postgresql
|
||||||
|
- NETDISCO_DB_NAME=netdisco
|
||||||
|
- NETDISCO_DB_USER=netdisco
|
||||||
|
- NETDISCO_DB_PASS=netdisco
|
||||||
|
ports:
|
||||||
|
- "8082:5000"
|
||||||
|
volumes:
|
||||||
|
- /opt/oam/netdisco/config/deployment.yml:/home/netdisco/environments/deployment.yml
|
||||||
|
restart: unless-stopped
|
||||||
|
DCEOF
|
||||||
|
|
||||||
|
echo "=== Pulling NetDisco images ==="
|
||||||
|
cd /opt/oam/netdisco && docker compose pull 2>&1
|
||||||
|
|
||||||
|
echo "=== Starting NetDisco stack ==="
|
||||||
|
cd /opt/oam/netdisco && docker compose up -d 2>&1
|
||||||
|
|
||||||
|
echo "=== Waiting for PostgreSQL to initialize (30s) ==="
|
||||||
|
sleep 30
|
||||||
|
|
||||||
|
echo "=== Container status ==="
|
||||||
|
docker ps --filter name=oam-netdisco --format "table {{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}"
|
||||||
|
|
||||||
|
echo "=== Adding devices to NetDisco ==="
|
||||||
|
for dev in pfv-r5-core-01.knel.net pfv-r3-tor-mgmt-01.knel.net pfv-r3-tor-stor-01.knel.net pfv-r6-mgmt-01.knel.net; do
|
||||||
|
echo "--- Discovering $dev ---"
|
||||||
|
docker exec oam-netdisco-backend /home/netdisco/bin/netdisco-do discover -d "$dev" 2>&1 | tail -5
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "=== NetDisco web URL: http://tsys-librenms.knel.net:8082 ==="
|
||||||
|
echo "=== Done ==="
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
# tsys-librenms nginx vhost for the OAM docker UIs — deployed 2026-09-03 [#697]
|
||||||
|
# cert: oam-ui.knel.net (SANs: smokeping/netdisco/oxidized/unpoller.knel.net) from fleet CA
|
||||||
|
# IaC codification tracked via #454 (AWX lane); this file is the config SoR copy.
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 443 ssl;
|
||||||
|
server_name smokeping.knel.net;
|
||||||
|
ssl_certificate /etc/nginx/ssl/oam-ui.knel.net.fullchain;
|
||||||
|
ssl_certificate_key /etc/nginx/ssl/oam-ui.knel.net.key;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_pass http://127.0.0.1:8081;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto https;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
server {
|
||||||
|
listen 443 ssl;
|
||||||
|
server_name netdisco.knel.net;
|
||||||
|
ssl_certificate /etc/nginx/ssl/oam-ui.knel.net.fullchain;
|
||||||
|
ssl_certificate_key /etc/nginx/ssl/oam-ui.knel.net.key;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_pass http://127.0.0.1:8082;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto https;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
server {
|
||||||
|
listen 443 ssl;
|
||||||
|
server_name oxidized.knel.net;
|
||||||
|
ssl_certificate /etc/nginx/ssl/oam-ui.knel.net.fullchain;
|
||||||
|
ssl_certificate_key /etc/nginx/ssl/oam-ui.knel.net.key;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_pass http://127.0.0.1:8083;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto https;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
server {
|
||||||
|
listen 443 ssl;
|
||||||
|
server_name unpoller.knel.net;
|
||||||
|
ssl_certificate /etc/nginx/ssl/oam-ui.knel.net.fullchain;
|
||||||
|
ssl_certificate_key /etc/nginx/ssl/oam-ui.knel.net.key;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_pass http://127.0.0.1:8084;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto https;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
---
|
||||||
|
username: 'oxidized'
|
||||||
|
password: 'see ~/.creds/oxidized.env'
|
||||||
|
model: powerconnect
|
||||||
|
interval: 3600
|
||||||
|
use_syslog: false
|
||||||
|
debug: false
|
||||||
|
threads: 30
|
||||||
|
timeout: 20
|
||||||
|
retries: 3
|
||||||
|
prompt: !ruby/regexp /([\w.@-]+[#>]\s?)n/
|
||||||
|
rest: 0.0.0.0:8888
|
||||||
|
next_adds_job: false
|
||||||
|
models: {}
|
||||||
|
pid: /home/oxidized/.config/oxidized/pid
|
||||||
|
log: /home/oxidized/.config/oxidized/logs/log
|
||||||
|
snmp: false
|
||||||
|
groups: {}
|
||||||
|
models: {}
|
||||||
|
resolve_dns: true
|
||||||
|
interval: 3600
|
||||||
|
output:
|
||||||
|
default: git
|
||||||
|
git:
|
||||||
|
user: oxidized
|
||||||
|
email: oxidized@tsys-librenms.knel.net
|
||||||
|
repo: /home/oxidized/.config/oxidized/git-repos
|
||||||
|
source:
|
||||||
|
default: csv
|
||||||
|
csv:
|
||||||
|
file: /home/oxidized/.config/oxidized/router.db
|
||||||
|
delimiter: !ruby/regexp /:/
|
||||||
|
map:
|
||||||
|
name: 0
|
||||||
|
model: 1
|
||||||
|
username: 2
|
||||||
|
password: 3
|
||||||
|
gpg: false
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
services:
|
||||||
|
oxidized:
|
||||||
|
image: oxidized/oxidized:0.30.1
|
||||||
|
container_name: oam-oxidized
|
||||||
|
environment:
|
||||||
|
- OXIDIZED_CONFIG=/home/oxidized/.config/oxidized/config
|
||||||
|
- TZ=America/Chicago
|
||||||
|
volumes:
|
||||||
|
- /opt/oam/oxidized/config:/home/oxidized/.config/oxidized
|
||||||
|
ports:
|
||||||
|
- "8083:8888"
|
||||||
|
restart: unless-stopped
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Oxidized post-push hook: auto-push to Gitea after each config change
|
||||||
|
# Mounted into container at /home/oxidized/.config/oxidized/hooks/checkout/git-push.sh
|
||||||
|
set -euo pipefail
|
||||||
|
cd "$1"
|
||||||
|
export GIT_SSH_COMMAND="ssh -o StrictHostKeyChecking=accept-new -i /home/oxidized/.config/oxidized/.ssh/id_ed25519"
|
||||||
|
git push origin master 2>&1 || true
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
pfv-r5-core-01.knel.net:powerconnect:oxidized:xAlZI3j7m8Bkgf0p
|
||||||
|
pfv-r3-tor-mgmt-01.knel.net:powerconnect:oxidized:xAlZI3j7m8Bkgf0p
|
||||||
|
pfv-r3-tor-stor-01.knel.net:powerconnect:oxidized:xAlZI3j7m8Bkgf0p
|
||||||
|
pfv-r6-mgmt-01.knel.net:powerconnect:oxidized:xAlZI3j7m8Bkgf0p
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# Deploy Oxidized on tsys-librenms
|
||||||
|
# Part of OAM platform [#337]
|
||||||
|
# Network device config backup/versioning
|
||||||
|
|
||||||
|
echo "=== Setting up Oxidized ==="
|
||||||
|
|
||||||
|
mkdir -p /opt/oam/oxidized/{config,git-repos,logs}
|
||||||
|
|
||||||
|
# Config file
|
||||||
|
cat > /opt/oam/oxidized/config/config <<'CFGEOF'
|
||||||
|
---
|
||||||
|
username: 'CHANGE_ME'
|
||||||
|
password: 'CHANGE_ME'
|
||||||
|
model: powerconnect
|
||||||
|
interval: 3600
|
||||||
|
use_syslog: false
|
||||||
|
debug: false
|
||||||
|
threads: 30
|
||||||
|
timeout: 20
|
||||||
|
retries: 3
|
||||||
|
prompt: !ruby/regexp /([\w.@-]+[#>]\s?)n/
|
||||||
|
rest: 0.0.0.0:8888
|
||||||
|
next_adds_job: false
|
||||||
|
pid: /home/oxidized/.config/oxidized/pid
|
||||||
|
log: /home/oxidized/.config/oxidized/logs/log
|
||||||
|
snmp: false
|
||||||
|
resolve_dns: true
|
||||||
|
interval: 3600
|
||||||
|
output:
|
||||||
|
default: git
|
||||||
|
git:
|
||||||
|
user: oxidized
|
||||||
|
email: oxidized@tsys-librenms.knel.net
|
||||||
|
repo: /home/oxidized/.config/oxidized/git-repos
|
||||||
|
source:
|
||||||
|
default: csv
|
||||||
|
csv:
|
||||||
|
file: /home/oxidized/.config/oxidized/router.db
|
||||||
|
delimiter: !ruby/regexp /:/
|
||||||
|
map:
|
||||||
|
name: 0
|
||||||
|
model: 1
|
||||||
|
username: 2
|
||||||
|
password: 3
|
||||||
|
gpg: false
|
||||||
|
CFGEOF
|
||||||
|
|
||||||
|
# Router DB (device list)
|
||||||
|
cat > /opt/oam/oxidized/config/router.db <<'DBEOF'
|
||||||
|
pfv-r5-core-01.knel.net:powerconnect:CHANGE_ME:CHANGE_ME
|
||||||
|
pfv-r3-tor-mgmt-01.knel.net:powerconnect:CHANGE_ME:CHANGE_ME
|
||||||
|
pfv-r3-tor-stor-01.knel.net:powerconnect:CHANGE_ME:CHANGE_ME
|
||||||
|
pfv-r6-mgmt-01.knel.net:powerconnect:CHANGE_ME:CHANGE_ME
|
||||||
|
DBEOF
|
||||||
|
|
||||||
|
# Docker compose
|
||||||
|
cat > /opt/oam/oxidized/docker-compose.yml <<'DCEOF'
|
||||||
|
services:
|
||||||
|
oxidized:
|
||||||
|
image: oxidized/oxidized:0.30.1
|
||||||
|
container_name: oam-oxidized
|
||||||
|
environment:
|
||||||
|
- TZ=America/Chicago
|
||||||
|
volumes:
|
||||||
|
- /opt/oam/oxidized/config:/home/oxidized/.config/oxidized
|
||||||
|
ports:
|
||||||
|
- "8083:8888"
|
||||||
|
restart: unless-stopped
|
||||||
|
DCEOF
|
||||||
|
|
||||||
|
echo "=== Pulling Oxidized image ==="
|
||||||
|
cd /opt/oam/oxidized && timeout 120 docker compose pull 2>&1
|
||||||
|
|
||||||
|
echo "=== Starting Oxidized ==="
|
||||||
|
cd /opt/oam/oxidized && docker compose up -d 2>&1
|
||||||
|
|
||||||
|
echo "=== Status ==="
|
||||||
|
docker ps --filter name=oam-oxidized --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "=== IMPORTANT ==="
|
||||||
|
echo "Oxidized deployed with placeholder credentials (CHANGE_ME)."
|
||||||
|
echo "Update /opt/oam/oxidized/config/router.db with real switch credentials"
|
||||||
|
echo "(username:password per device) to enable config backups."
|
||||||
|
echo "Then restart: cd /opt/oam/oxidized && docker compose restart"
|
||||||
|
echo ""
|
||||||
|
echo "=== Oxidized REST API: http://tsys-librenms.knel.net:8083 ==="
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# Questions — monitoring (round 1)
|
||||||
|
|
||||||
|
Lane-wide questions live in KNEL/PFVCluster `questions-v10.md` (2026-09-03 repo-split round). Repo-specific rounds start here.
|
||||||
Executable
+274
@@ -0,0 +1,274 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# check-rules.sh — project rule audit engine.
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
# bash scripts/check-rules.sh # full audit (verbose, includes slow checks)
|
||||||
|
# bash scripts/check-rules.sh --fast # fast audit (quiet, skips slow checks) — for pre-commit
|
||||||
|
# bash scripts/check-rules.sh --quiet # full audit, only prints failures
|
||||||
|
#
|
||||||
|
# Exit code: 0 = all rules pass (warnings are non-fatal), 1 = one or more FAILED.
|
||||||
|
#
|
||||||
|
# This is a generalized version of the rules engine proven in the
|
||||||
|
# RCEO-PersonalAssistant project. Add project-specific checks by appending
|
||||||
|
# `check "<desc>" "<pass|warn|fail>"` calls below.
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
# shellcheck disable=SC1091
|
||||||
|
source "$HERE/lib/common.sh"
|
||||||
|
REPO_ROOT="$(repo_root)"
|
||||||
|
cd "$REPO_ROOT"
|
||||||
|
|
||||||
|
# --- argument parsing ---
|
||||||
|
RULE_FAST=false
|
||||||
|
RULE_VERBOSE=true
|
||||||
|
for arg in "$@"; do
|
||||||
|
case "$arg" in
|
||||||
|
--fast) RULE_FAST=true; RULE_VERBOSE=false ;;
|
||||||
|
--quiet) RULE_VERBOSE=false ;;
|
||||||
|
*) die "check-rules.sh: unknown argument '$arg'" ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
export RULE_FAST RULE_VERBOSE
|
||||||
|
|
||||||
|
init_counters
|
||||||
|
$RULE_VERBOSE && echo "=== Project Rule Audit ==="
|
||||||
|
|
||||||
|
TODAY="$(date +%Y-%m-%d)"
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# 1. Shellcheck — every .sh/.bash must pass (zero warnings, incl. info-level).
|
||||||
|
# Runs in Docker so the host stays clean (no native shellcheck required).
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
$RULE_VERBOSE && log_step "Shell scripts (shellcheck)"
|
||||||
|
mapfile -d '' SH_FILES < <(find . -path ./.git -prune -o -path ./.tmp -prune -o -path ./.crush -prune -o -path ./vendor -prune -o -path ./librenms-agent/agent/mysql.sh -prune -o -path ./archive -prune -o -path ./node_modules -prune -o \( -name '*.sh' -o -name '*.bash' \) -print0 2>/dev/null)
|
||||||
|
if [ "${#SH_FILES[@]}" -gt 0 ]; then
|
||||||
|
if have shellcheck; then
|
||||||
|
if shellcheck "${SH_FILES[@]}" >/dev/null 2>&1; then
|
||||||
|
check "All shell scripts pass shellcheck (host)" "pass"
|
||||||
|
else
|
||||||
|
check "shellcheck reports violations — run: shellcheck <file>" "fail"
|
||||||
|
fi
|
||||||
|
elif have docker; then
|
||||||
|
MNT_FILES=()
|
||||||
|
for f in "${SH_FILES[@]}"; do MNT_FILES+=("/mnt/${f#./}"); done
|
||||||
|
if docker run --rm -v "$REPO_ROOT:/mnt" koalaman/shellcheck:stable "${MNT_FILES[@]}" >/dev/null 2>&1; then
|
||||||
|
check "All shell scripts pass shellcheck (docker)" "pass"
|
||||||
|
else
|
||||||
|
check "shellcheck (docker) reports violations" "fail"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
check "No shellcheck or docker available to lint scripts" "warn"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
check "No shell scripts to lint" "pass"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# 2. Docker image pinning — no ':latest' tags in compose or Dockerfiles.
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
$RULE_VERBOSE && log_step "Docker image pinning"
|
||||||
|
if grep -rqE '(image:|FROM).*:latest' --include='docker-compose*.y*ml' --include='Dockerfile*' . 2>/dev/null; then
|
||||||
|
check "No ':latest' image tags (pin everything)" "fail"
|
||||||
|
else
|
||||||
|
check "No ':latest' image tags" "pass"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# 2b. Container naming — every service in a docker-compose file MUST set an
|
||||||
|
# explicit container_name (never rely on Docker's default <dir>_<n>).
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
$RULE_VERBOSE && log_step "Container naming"
|
||||||
|
COMPOSE_FILES="$(find . -path ./.git -prune -o \( -name 'docker-compose*.yml' -o -name 'docker-compose*.yaml' -o -name 'compose.yml' -o -name 'compose.yaml' \) -print 2>/dev/null || true)"
|
||||||
|
if [ -n "$COMPOSE_FILES" ]; then
|
||||||
|
BAD=0
|
||||||
|
while IFS= read -r cf; do
|
||||||
|
[ -n "$cf" ] || continue
|
||||||
|
# Count top-level service keys (2-space indent under services:) and
|
||||||
|
# compare against the number of container_name: declarations.
|
||||||
|
svc_count=$(awk '/^services:/{f=1;next} f&&/^[^[:space:]]/{f=0} f&&/^[[:space:]]{2}[[:alnum:]_-]+:[[:space:]]*$/{c++} END{print c+0}' "$cf")
|
||||||
|
cn_count=$(grep -cE '^[[:space:]]*container_name:' "$cf" 2>/dev/null || echo 0)
|
||||||
|
if [ "${svc_count:-0}" -gt 0 ] && [ "$cn_count" -lt "$svc_count" ]; then
|
||||||
|
BAD=$((BAD + 1))
|
||||||
|
fi
|
||||||
|
done <<EOF
|
||||||
|
$COMPOSE_FILES
|
||||||
|
EOF
|
||||||
|
if [ "$BAD" -eq 0 ]; then
|
||||||
|
check "All compose services set container_name" "pass"
|
||||||
|
else
|
||||||
|
check "$BAD compose file(s) with services missing container_name" "fail"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
check "No compose files (container-name check skipped)" "pass"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# 3. Required-files manifest — the files every project using this template owns.
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
$RULE_VERBOSE && log_step "Required files"
|
||||||
|
REQUIRED_FILES="AGENTS.md STATUS.md .env.example scripts/check-rules.sh scripts/setup-hooks.sh"
|
||||||
|
REQUIRED_FILES="$REQUIRED_FILES ${PROJECT_REQUIRED_FILES:-}"
|
||||||
|
for f in $REQUIRED_FILES; do
|
||||||
|
if [ -f "$f" ]; then check "$f exists" "pass"; else check "$f MISSING" "fail"; fi
|
||||||
|
done
|
||||||
|
if compgen -G 'questions-v*.md' > /dev/null; then
|
||||||
|
latest_q="$(find . -maxdepth 1 -name 'questions-v*.md' -printf '%f\n' | sort -V | tail -1)"
|
||||||
|
check "questions-v*.md exists ($latest_q)" "pass"
|
||||||
|
else
|
||||||
|
check "questions-v*.md MISSING" "fail"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# 4. Doc freshness — STATUS.md touched today.
|
||||||
|
# Warning (not failure): staleness is a signal, not a break.
|
||||||
|
# Redmine is the system of record for work; Discourse for docs. STATUS.md is
|
||||||
|
# a scratchpad only — see BASELINE-PROMPT.md §3, §8.
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
$RULE_VERBOSE && log_step "Doc freshness"
|
||||||
|
if [ -f STATUS.md ]; then
|
||||||
|
STATUS_DATE="$(grep -oE 'Last updated: [0-9]{4}-[0-9]{2}-[0-9]{2}' STATUS.md | grep -oE '[0-9]{4}-[0-9]{2}-[0-9]{2}' || echo unknown)"
|
||||||
|
if [ "$STATUS_DATE" = "$TODAY" ]; then
|
||||||
|
check "STATUS.md updated today ($STATUS_DATE)" "pass"
|
||||||
|
else
|
||||||
|
check "STATUS.md is stale (last: $STATUS_DATE, today: $TODAY) — update it" "warn"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
check "STATUS.md MISSING" "fail"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# 4b. Discourse pointer-header policy (MANDATORY).
|
||||||
|
# Discourse is the system of record for documentation. In-repo .md files are
|
||||||
|
# stubs that point to a Discourse topic URL. Operational files exempt.
|
||||||
|
# Override exemptions via PROJECT_DOC_EXEMPT (space-separated globs of
|
||||||
|
# basenames) and the Discourse host via PROJECT_DISCOURSE_HOST.
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
$RULE_VERBOSE && log_step "Discourse pointer-header"
|
||||||
|
DISCOURSE_HOST="${PROJECT_DISCOURSE_HOST:-community.turnsys.com}"
|
||||||
|
DOC_EXEMPT="${PROJECT_DOC_EXEMPT:-AGENTS.md STATUS.md WORKING.md README.md ADOPTING.md LICENSE .env.example questions-v*.md BASELINE-PROMPT.md PATTERNS.md}"
|
||||||
|
POINTER_MISSING=0
|
||||||
|
while IFS= read -r -d '' f; do
|
||||||
|
base="$(basename "$f")"
|
||||||
|
exempt=false
|
||||||
|
for pat in $DOC_EXEMPT; do
|
||||||
|
# shellcheck disable=SC2254
|
||||||
|
case "$base" in $pat) exempt=true; break ;; esac
|
||||||
|
done
|
||||||
|
[ "$exempt" = true ] && continue
|
||||||
|
if ! grep -qF "$DISCOURSE_HOST" "$f" 2>/dev/null; then
|
||||||
|
if [ "$POINTER_MISSING" -eq 0 ]; then
|
||||||
|
$RULE_VERBOSE && printf ' %s\n' "Missing $DISCOURSE_HOST URL in:"
|
||||||
|
fi
|
||||||
|
POINTER_MISSING=$((POINTER_MISSING + 1))
|
||||||
|
$RULE_VERBOSE && printf ' %s\n' "$f"
|
||||||
|
fi
|
||||||
|
done < <(find . -path ./.git -prune -o -path ./.crush -prune -o -path ./.tmp -prune -o -path ./vendor -prune -o -path ./archive -prune -o -name '*.md' -print0 2>/dev/null)
|
||||||
|
if [ "$POINTER_MISSING" -eq 0 ]; then
|
||||||
|
check "All non-exempt .md cite Discourse ($DISCOURSE_HOST)" "pass"
|
||||||
|
else
|
||||||
|
check "$POINTER_MISSING .md file(s) missing Discourse pointer (see BASELINE-PROMPT.md §3)" "fail"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# 5. Git state — uncommitted changes are a warning (the pre-push hook hardens
|
||||||
|
# this where it matters).
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
$RULE_VERBOSE && log_step "Git state"
|
||||||
|
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
||||||
|
if git diff --quiet && git diff --cached --quiet; then
|
||||||
|
check "Working tree clean" "pass"
|
||||||
|
else
|
||||||
|
check "Uncommitted changes present" "warn"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
check "Not a git repo (git checks skipped)" "pass"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# 6. Hooks installed — self-check that git hooks were set up.
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
$RULE_VERBOSE && log_step "Git hooks"
|
||||||
|
if [ -f .git/hooks/pre-commit ]; then
|
||||||
|
check "pre-commit hook installed" "pass"
|
||||||
|
else
|
||||||
|
check "pre-commit NOT installed (run: bash scripts/setup-hooks.sh)" "warn"
|
||||||
|
fi
|
||||||
|
if [ -f .git/hooks/pre-push ]; then
|
||||||
|
check "pre-push hook installed" "pass"
|
||||||
|
else
|
||||||
|
check "pre-push NOT installed (run: bash scripts/setup-hooks.sh)" "warn"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# 7. WORKING.md completion — no unchecked tasks may remain at commit time.
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
$RULE_VERBOSE && log_step "Task completion"
|
||||||
|
if [ -f WORKING.md ]; then
|
||||||
|
UNCHECKED="$(grep -cF -- '- [ ]' WORKING.md || true)"
|
||||||
|
if [ "$UNCHECKED" -eq 0 ]; then
|
||||||
|
check "WORKING.md has no unchecked tasks" "pass"
|
||||||
|
else
|
||||||
|
check "WORKING.md has ${UNCHECKED} unchecked task(s) — finish them before committing" "fail"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
check "WORKING.md absent (no active task tracker)" "pass"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# 8. CNW markers — empty `CNW:` markers flag unresolved questions for the human.
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
$RULE_VERBOSE && log_step "Unresolved questions"
|
||||||
|
EMPTY_CNW="$(grep -rn 'CNW:$' . --include='*.md' 2>/dev/null | head -20 || true)"
|
||||||
|
if [ -z "$EMPTY_CNW" ]; then
|
||||||
|
check "No empty CNW: markers (unresolved questions)" "pass"
|
||||||
|
else
|
||||||
|
CNW_COUNT="$(printf '%s\n' "$EMPTY_CNW" | grep -c . || true)"
|
||||||
|
check "${CNW_COUNT} unresolved CNW: marker(s) — needs user input" "warn"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# 9. Hygiene — merge-conflict markers and trailing whitespace must never land.
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
$RULE_VERBOSE && log_step "File hygiene"
|
||||||
|
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
||||||
|
# archive/ excluded: legacy files are preserved verbatim and may contain
|
||||||
|
# decorative `====` banners that false-positive as conflict markers.
|
||||||
|
CONFLICT="$(git diff --cached --name-only --diff-filter=ACM 2>/dev/null | grep -v '^archive/' | xargs -r grep -lE '^(<{7}( \S+)?|=======|>{7}( \S+)?)$' 2>/dev/null || true)"
|
||||||
|
if [ -z "$CONFLICT" ]; then check "No merge-conflict markers staged" "pass"; else check "Merge-conflict markers staged: $CONFLICT" "fail"; fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# 10. (slow, skipped in --fast) Project test suite via scripts/test.sh.
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
if [ "$RULE_FAST" = false ] && [ -x scripts/test.sh ]; then
|
||||||
|
$RULE_VERBOSE && log_step "Test suite (scripts/test.sh)"
|
||||||
|
if bash scripts/test.sh >/dev/null 2>&1; then
|
||||||
|
check "scripts/test.sh passes" "pass"
|
||||||
|
else
|
||||||
|
check "scripts/test.sh FAILS" "fail"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# 11. Access-channel policy — qemu guest-agent must NEVER be used as an
|
||||||
|
# execution or key-delivery channel. SSH (sshd) is the ONLY approved
|
||||||
|
# remote access path; all commands must be logged through standard
|
||||||
|
# auth/audit infrastructure. ITAR/CMMC environment — non-negotiable.
|
||||||
|
# Allowed: installing/checking qemu-guest-agent for Proxmox state
|
||||||
|
# visibility. Forbidden: `qm guest exec` + any `vm-guest` wrapper.
|
||||||
|
# Scans CODE only (not .md) so docs may describe the ban.
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
$RULE_VERBOSE && log_step "Access-channel policy (no guest-agent exec)"
|
||||||
|
GA_HITS="$(grep -rnE 'qm guest exec|vm-guest|_vm_guest' \
|
||||||
|
--include='*.sh' --include='*.bash' --include='*.py' \
|
||||||
|
. 2>/dev/null | grep -vE 'scripts/check-rules\.sh|/archive/' || true)"
|
||||||
|
if [ -z "$GA_HITS" ]; then
|
||||||
|
check "No guest-agent exec / vm-guest access patterns in code" "pass"
|
||||||
|
else
|
||||||
|
GA_COUNT="$(printf '%s\n' "$GA_HITS" | grep -c . || true)"
|
||||||
|
$RULE_VERBOSE && printf '%s\n' "$GA_HITS" | sed 's/^/ /'
|
||||||
|
check "${GA_COUNT} guest-agent exec / vm-guest reference(s) — SSH-only access policy (AGENTS.md)" "fail"
|
||||||
|
fi
|
||||||
|
|
||||||
|
print_summary_and_exit
|
||||||
Executable
+39
@@ -0,0 +1,39 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# docker-run.sh — canonical ephemeral-container wrapper.
|
||||||
|
#
|
||||||
|
# Keeps the host clean: every build/test/generation runs inside a pinned image.
|
||||||
|
# Ensures output files are owned by the invoking user (not root).
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
# docker-run.sh <image> [command...]
|
||||||
|
# Runs <command> in <image> with the repo mounted at /data, cwd /data.
|
||||||
|
# With no command, drops into the image's default entrypoint.
|
||||||
|
# docker-run.sh --shell <image>
|
||||||
|
# Interactive shell inside the container (for debugging).
|
||||||
|
#
|
||||||
|
# Examples:
|
||||||
|
# docker-run.sh python:3.12-slim python3 -m pytest
|
||||||
|
# docker-run.sh pandoc/extra report.md -o report.pdf
|
||||||
|
# docker-run.sh --shell node:20
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
# shellcheck disable=SC1091
|
||||||
|
source "$HERE/lib/common.sh"
|
||||||
|
|
||||||
|
SHELL_MODE=false
|
||||||
|
case "${1:-}" in
|
||||||
|
--shell) SHELL_MODE=true; shift ;;
|
||||||
|
-h|--help)
|
||||||
|
sed -n '2,18p' "$0"; exit 0 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
[ "$#" -ge 1 ] || { sed -n '2,18p' "$0"; exit 1; }
|
||||||
|
|
||||||
|
if [ "$SHELL_MODE" = true ]; then
|
||||||
|
# ${SHELL:-sh} must expand inside the container, not in this outer shell.
|
||||||
|
# shellcheck disable=SC2016
|
||||||
|
docker_run "$1" sh -c 'exec "${SHELL:-sh}"'
|
||||||
|
else
|
||||||
|
docker_run "$@"
|
||||||
|
fi
|
||||||
Executable
+65
@@ -0,0 +1,65 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# garden.sh — the gardening loop.
|
||||||
|
#
|
||||||
|
# Reports doc sprawl and files that violate the "Discourse is the system of
|
||||||
|
# record for documentation; gitea .md files are stubs" policy. Run via
|
||||||
|
# `bash scripts/garden.sh`. Findings are WARNINGS (advisory); fix them at a natural break.
|
||||||
|
#
|
||||||
|
# What it checks:
|
||||||
|
# 1. Markdown sprawl: count of .md files per directory (top-10 by count).
|
||||||
|
# 2. Oversized .md files (default >300 lines) that don't cite a Discourse URL
|
||||||
|
# — candidates to migrate to Discourse, leaving a stub.
|
||||||
|
# 3. .md files with no Discourse link at all (informational; exempt: the
|
||||||
|
# operational files in EXEMPT_FILES).
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
# shellcheck disable=SC1091
|
||||||
|
source "$HERE/lib/common.sh"
|
||||||
|
REPO_ROOT="$(repo_root)"
|
||||||
|
cd "$REPO_ROOT"
|
||||||
|
|
||||||
|
SIZE_LIMIT="${GARDEN_MD_LINE_LIMIT:-300}"
|
||||||
|
# Operational files that legitimately live next to code, not in Discourse.
|
||||||
|
EXEMPT_FILES="${GARDEN_EXEMPT:-AGENTS.md STATUS.md WORKING.md questions-v.*.md PATTERNS.md BASELINE-PROMPT.md README.md}"
|
||||||
|
|
||||||
|
log_step "Gardening report for $REPO_ROOT"
|
||||||
|
|
||||||
|
# --- 1. sprawl by directory -------------------------------------------------
|
||||||
|
log_info "Markdown file count by directory (top 10):"
|
||||||
|
find . -path ./.git -prune -o -name '*.md' -print 2>/dev/null \
|
||||||
|
| sed 's|/[^/]*$||' | sort | uniq -c | sort -rn | head -10 | sed 's/^/ /'
|
||||||
|
|
||||||
|
# --- 2. oversized .md without a Discourse link ------------------------------
|
||||||
|
log_info "Oversized .md (>${SIZE_LIMIT} lines) lacking a Discourse URL — migrate candidates:"
|
||||||
|
OVERSIZED=0
|
||||||
|
while IFS= read -r -d '' f; do
|
||||||
|
# skip exempt files (glob match against basename and relative path)
|
||||||
|
exempt=false
|
||||||
|
base=$(basename "$f")
|
||||||
|
rel=${f#./}
|
||||||
|
for pat in $EXEMPT_FILES; do
|
||||||
|
# shellcheck disable=SC2254 # glob match is intentional
|
||||||
|
case "$base" in $pat) exempt=true; break ;; esac
|
||||||
|
# shellcheck disable=SC2254
|
||||||
|
case "$rel" in $pat) exempt=true; break ;; esac
|
||||||
|
done
|
||||||
|
[ "$exempt" = true ] && continue
|
||||||
|
lines=$(wc -l < "$f" 2>/dev/null || echo 0)
|
||||||
|
if [ "$lines" -gt "$SIZE_LIMIT" ]; then
|
||||||
|
if ! grep -qiE 'community\.turnsys\.com|discourse' "$f" 2>/dev/null; then
|
||||||
|
printf ' %-60s %s lines\n' "$f" "$lines"
|
||||||
|
OVERSIZED=$((OVERSIZED + 1))
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done < <(find . -path ./.git -prune -o -name '*.md' -print0 2>/dev/null)
|
||||||
|
[ "$OVERSIZED" -eq 0 ] && echo " (none)"
|
||||||
|
|
||||||
|
# --- 3. summary -------------------------------------------------------------
|
||||||
|
log_step "Gardening summary"
|
||||||
|
echo " Oversized non-Discourse .md files: $OVERSIZED"
|
||||||
|
if [ "$OVERSIZED" -eq 0 ]; then
|
||||||
|
log_ok "no migration candidates"
|
||||||
|
else
|
||||||
|
log_warn "$OVERSIZED file(s) to migrate to Discourse"
|
||||||
|
fi
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# lib/common.sh — shared helpers for shell scripts and hooks in this repo.
|
||||||
|
#
|
||||||
|
# Source it from any script:
|
||||||
|
# #!/usr/bin/env bash
|
||||||
|
# set -euo pipefail
|
||||||
|
# HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
# # shellcheck source=lib/common.sh
|
||||||
|
# source "$HERE/lib/common.sh" # or the appropriate relative path
|
||||||
|
#
|
||||||
|
# This library exists to drive a known cross-project inconsistency to zero:
|
||||||
|
# every repo used to re-paste the ANSI color block, redefine log_* helpers,
|
||||||
|
# pick one of three incompatible shebangs, and roll its own docker wrapper.
|
||||||
|
# Import this once instead.
|
||||||
|
|
||||||
|
# Do NOT set -euo pipefail here unconditionally — some callers (git hooks)
|
||||||
|
# source this file and rely on controlling their own shell options. We only
|
||||||
|
# guarantee the functions below are defined.
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Config — override via environment before sourcing if needed
|
||||||
|
###############################################################################
|
||||||
|
: "${TEMPLATE_ROOT:=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)}"
|
||||||
|
export TEMPLATE_ROOT
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# ANSI colors (defined once, used everywhere)
|
||||||
|
###############################################################################
|
||||||
|
if [ -t 1 ] && [ -z "${NO_COLOR:-}" ]; then
|
||||||
|
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'
|
||||||
|
BLUE='\033[0;34m'; BOLD='\033[1m'; NC='\033[0m'
|
||||||
|
else
|
||||||
|
RED=''; GREEN=''; YELLOW=''; BLUE=''; BOLD=''; NC=''
|
||||||
|
fi
|
||||||
|
export RED GREEN YELLOW BLUE BOLD NC
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Logging
|
||||||
|
###############################################################################
|
||||||
|
log_info() { printf "${BLUE}›${NC} %s\n" "$*"; }
|
||||||
|
log_ok() { printf "${GREEN}✓${NC} %s\n" "$*"; }
|
||||||
|
log_warn() { printf "${YELLOW}⚠${NC} %s\n" "$*" >&2; }
|
||||||
|
log_error() { printf "${RED}✗${NC} %s\n" "$*" >&2; }
|
||||||
|
log_step() { printf "\n${BOLD}== %s ==${NC}\n" "$*"; }
|
||||||
|
|
||||||
|
die() { log_error "$*"; exit 1; }
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Predicates
|
||||||
|
###############################################################################
|
||||||
|
# have <cmd> — return 0 if <cmd> is on PATH
|
||||||
|
have() { command -v "$1" >/dev/null 2>&1; }
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Path helpers
|
||||||
|
###############################################################################
|
||||||
|
repo_root() {
|
||||||
|
# Prefer git's notion of the repo root, fall back to $TEMPLATE_ROOT, then pwd.
|
||||||
|
if git rev-parse --show-toplevel >/dev/null 2>&1; then
|
||||||
|
git rev-parse --show-toplevel
|
||||||
|
else
|
||||||
|
printf '%s\n' "${TEMPLATE_ROOT:-$(pwd)}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Privilege helpers
|
||||||
|
###############################################################################
|
||||||
|
# as_root — run the remaining args as root via sudo, or directly if already root.
|
||||||
|
as_root() {
|
||||||
|
if [ "$(id -u)" -eq 0 ]; then "$@"; else sudo "$@"; fi
|
||||||
|
}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Docker wrapper
|
||||||
|
###############################################################################
|
||||||
|
# docker_run <image> <args...>
|
||||||
|
# Ephemeral container, host-uid ownership, repo mounted at /data, cwd /data.
|
||||||
|
# Drives the "host stays clean; everything runs in containers" policy and
|
||||||
|
# ensures output files are owned by the invoking user, not root.
|
||||||
|
docker_run() {
|
||||||
|
[ "$#" -ge 1 ] || die "docker_run: image required"
|
||||||
|
local image="$1"; shift
|
||||||
|
have docker || die "docker not found on PATH"
|
||||||
|
local root
|
||||||
|
root="$(repo_root)"
|
||||||
|
docker run --rm \
|
||||||
|
--user "$(id -u):$(id -g)" \
|
||||||
|
-e HOME=/tmp \
|
||||||
|
-v "$root:/data" \
|
||||||
|
-w /data \
|
||||||
|
"$image" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Rule-audit accumulator (used by scripts/check-rules.sh)
|
||||||
|
# Globals read/written: RULE_PASS RULE_WARN RULE_FAIL
|
||||||
|
###############################################################################
|
||||||
|
init_counters() { RULE_PASS=0; RULE_WARN=0; RULE_FAIL=0; }
|
||||||
|
|
||||||
|
# check <description> <pass|warn|fail>
|
||||||
|
check() {
|
||||||
|
local desc="$1" result="$2"
|
||||||
|
case "$result" in
|
||||||
|
pass)
|
||||||
|
RULE_PASS=$((RULE_PASS + 1))
|
||||||
|
if [ "${RULE_VERBOSE:-true}" = true ]; then printf " ${GREEN}PASS${NC} %s\n" "$desc"; fi
|
||||||
|
;;
|
||||||
|
warn)
|
||||||
|
RULE_WARN=$((RULE_WARN + 1))
|
||||||
|
if [ "${RULE_VERBOSE:-true}" = true ]; then printf " ${YELLOW}WARN${NC} %s\n" "$desc"; fi
|
||||||
|
;;
|
||||||
|
fail)
|
||||||
|
RULE_FAIL=$((RULE_FAIL + 1))
|
||||||
|
printf " ${RED}FAIL${NC} %s\n" "$desc"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
die "check(): invalid result '$result' (use pass|warn|fail)"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# print_summary_and_exit
|
||||||
|
print_summary_and_exit() {
|
||||||
|
if [ "${RULE_VERBOSE:-true}" = true ]; then
|
||||||
|
printf "\n=== Summary ===\n PASS: %s\n WARN: %s\n FAIL: %s\n\n" \
|
||||||
|
"$RULE_PASS" "$RULE_WARN" "$RULE_FAIL"
|
||||||
|
fi
|
||||||
|
if [ "$RULE_FAIL" -gt 0 ]; then
|
||||||
|
if [ "${RULE_VERBOSE:-true}" = true ]; then
|
||||||
|
printf "AUDIT FAILED — %s rule(s) violated.\n" "$RULE_FAIL"
|
||||||
|
fi
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [ "${RULE_VERBOSE:-true}" = true ]; then printf "AUDIT PASSED.\n"; fi
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
Executable
+25
@@ -0,0 +1,25 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# pre-commit — fast rule audit (< 1s typical).
|
||||||
|
# Hot-path bypass: commits that ONLY touch STATUS.md / WORKING.md skip the
|
||||||
|
# audit so frequent status/task commits stay frictionless.
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
REPO_ROOT="$(git rev-parse --show-toplevel)"
|
||||||
|
cd "$REPO_ROOT"
|
||||||
|
|
||||||
|
CHANGED="$(git diff --cached --name-only)"
|
||||||
|
HOT_PATHS="$(printf '%s\n' "$CHANGED" | grep -vE '^(STATUS.md|WORKING.md)$' || true)"
|
||||||
|
|
||||||
|
if [ -z "$HOT_PATHS" ]; then
|
||||||
|
echo "hot-path files only (STATUS/WORKING) — skipping rule audit"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! bash scripts/check-rules.sh --fast; then
|
||||||
|
echo ""
|
||||||
|
echo "pre-commit audit FAILED. Fix the violations above before committing."
|
||||||
|
echo "Full audit: bash scripts/check-rules.sh"
|
||||||
|
echo "Bypass: git commit --no-verify (emergencies only)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
exit 0
|
||||||
Executable
+25
@@ -0,0 +1,25 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# pre-push — full rule audit + clean-working-tree gate before pushing.
|
||||||
|
# Installed via: bash scripts/setup-hooks.sh
|
||||||
|
#
|
||||||
|
# Combines two proven policies observed across projects:
|
||||||
|
# - KNEL-AIMiddleware: block push if the working tree is dirty.
|
||||||
|
# - RCEO-PersonalAssistant: block push if the full test suite fails.
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
REPO_ROOT="$(git rev-parse --show-toplevel)"
|
||||||
|
cd "$REPO_ROOT"
|
||||||
|
|
||||||
|
echo "pre-push: running full rule audit..."
|
||||||
|
|
||||||
|
# Full audit (non-fast): runs the slow test suite via `make test` if present.
|
||||||
|
if ! bash scripts/check-rules.sh --quiet; then
|
||||||
|
echo ""
|
||||||
|
echo "pre-push audit FAILED. Push blocked."
|
||||||
|
echo "Re-run with output: bash scripts/check-rules.sh"
|
||||||
|
echo "Bypass: git push --no-verify (emergencies only)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "pre-push: all rules and tests passed."
|
||||||
|
exit 0
|
||||||
Executable
+44
@@ -0,0 +1,44 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# setup-hooks.sh — install this repo's git hooks.
|
||||||
|
#
|
||||||
|
# Mechanism: copy scripts/pre-commit and scripts/pre-push into .git/hooks/ and
|
||||||
|
# make them executable. This is the most portable pattern (works on any clone,
|
||||||
|
# no `git config core.hooksPath` mutation, survives config resets, idempotent).
|
||||||
|
#
|
||||||
|
# Run once after cloning: bash scripts/setup-hooks.sh
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
# shellcheck disable=SC1091
|
||||||
|
source "$HERE/lib/common.sh"
|
||||||
|
REPO_ROOT="$(repo_root)"
|
||||||
|
cd "$REPO_ROOT"
|
||||||
|
|
||||||
|
[ -d .git ] || die "no .git directory here — run this from a git checkout"
|
||||||
|
|
||||||
|
HOOKS_DIR=".git/hooks"
|
||||||
|
HOOK_NAMES="pre-commit pre-push"
|
||||||
|
|
||||||
|
log_step "Installing git hooks"
|
||||||
|
for name in $HOOK_NAMES; do
|
||||||
|
src="scripts/$name"
|
||||||
|
dst="$HOOKS_DIR/$name"
|
||||||
|
[ -f "$src" ] || die "source hook not found: $src"
|
||||||
|
cp "$src" "$dst"
|
||||||
|
chmod +x "$dst"
|
||||||
|
log_ok "installed $dst"
|
||||||
|
done
|
||||||
|
|
||||||
|
cat <<EOF
|
||||||
|
|
||||||
|
Git hooks installed. The following now run automatically:
|
||||||
|
|
||||||
|
pre-commit fast rule audit (shellcheck, image pinning, container naming,
|
||||||
|
required files, doc freshness, Discourse pointers, WORKING.md
|
||||||
|
completion, hygiene).
|
||||||
|
Hot-path bypass for STATUS.md / WORKING.md.
|
||||||
|
pre-push full rule audit (includes scripts/test.sh) + clean-working-tree gate.
|
||||||
|
|
||||||
|
Bypass either with \`git commit --no-verify\` / \`git push --no-verify\`
|
||||||
|
(emergencies only).
|
||||||
|
EOF
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
*** General ***
|
||||||
|
|
||||||
|
owner = Charles N Wyble
|
||||||
|
contact = reachableceo@knownelement.com
|
||||||
|
mailhost = localhost
|
||||||
|
cgiurl = http://tsys-librenms.knel.net:8081/smokeping/smokeping.cgi
|
||||||
|
syslogfacility = local0
|
||||||
|
# each probe run every 5 minutes, 300 samples = 25 hours at 5min steps
|
||||||
|
pagedir = /data/pages
|
||||||
|
piddir = /tmp
|
||||||
|
imgcache = /data/cache
|
||||||
|
imgurl = /smokeping/images
|
||||||
|
datadir = /data/_data
|
||||||
|
dyndir = /data/dyn
|
||||||
|
|
||||||
|
*** Database ***
|
||||||
|
|
||||||
|
step = 300
|
||||||
|
pings = 20
|
||||||
|
|
||||||
|
# consfn mrhb steps total
|
||||||
|
|
||||||
|
AVERAGE 0.5 1 100800
|
||||||
|
AVERAGE 0.5 12 43200
|
||||||
|
MIN 0.5 12 43200
|
||||||
|
MAX 0.5 12 43200
|
||||||
|
AVERAGE 0.5 144 7200
|
||||||
|
MAX 0.5 144 7200
|
||||||
|
MIN 0.5 144 7200
|
||||||
|
|
||||||
|
*** Presentation ***
|
||||||
|
|
||||||
|
template = /etc/smokeping/basepage.html
|
||||||
|
|
||||||
|
+ charts
|
||||||
|
|
||||||
|
+ detail
|
||||||
|
width = 600
|
||||||
|
height = 200
|
||||||
|
nradius = 5
|
||||||
|
|
||||||
|
*** Probes ***
|
||||||
|
|
||||||
|
+ FPing
|
||||||
|
|
||||||
|
binary = /usr/local/bin/fping
|
||||||
|
hostinterval = 1.5
|
||||||
|
mininterval = 0.001
|
||||||
|
offset = 0%
|
||||||
|
|
||||||
|
*** Alerts ***
|
||||||
|
|
||||||
|
to = reachableceo@knownelement.com
|
||||||
|
from = smokeping-alert@tsys-librenms.knel.net
|
||||||
|
|
||||||
|
+bigloss
|
||||||
|
type = loss
|
||||||
|
# in percent
|
||||||
|
pattern = ==0%,==0%,==0%,==0%,>0%,>0%,>0%
|
||||||
|
comment = suddenly there is packet loss
|
||||||
|
|
||||||
|
+somedoss
|
||||||
|
type = loss
|
||||||
|
# in percent
|
||||||
|
pattern = ==0%,==0%,==0%,==0%,==0%,>0%,>0%,>0%,>0%,>0%,>0%,>0%
|
||||||
|
comment = incoming packet loss
|
||||||
|
|
||||||
|
+startloss
|
||||||
|
type = loss
|
||||||
|
# in percent
|
||||||
|
pattern = >0%,>0%,>0%
|
||||||
|
comment = loss at startup
|
||||||
|
|
||||||
|
+rttdetect
|
||||||
|
type = rtt
|
||||||
|
# in milliseconds
|
||||||
|
pattern = <10,<10,<10,<10,<10,<10,<10,>10,>10,>10
|
||||||
|
comment = routing change?
|
||||||
|
|
||||||
|
+rttbadd
|
||||||
|
type = rtt
|
||||||
|
# in milliseconds
|
||||||
|
pattern = <50,<50,<50,<50,<50,<50,>50,>50,>50,>50
|
||||||
|
comment = reroute?
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
*** Targets ***
|
||||||
|
|
||||||
|
probe = FPing
|
||||||
|
|
||||||
|
menu = Top
|
||||||
|
title = Network Latency Monitor
|
||||||
|
|
||||||
|
+ Infrastructure
|
||||||
|
menu = Infrastructure
|
||||||
|
title = Core Infrastructure
|
||||||
|
|
||||||
|
++ pfv-r5-core-01
|
||||||
|
menu = pfv-r5-core-01 (Core Switch)
|
||||||
|
title = Dell PowerConnect 5448 - Rack 5 Core
|
||||||
|
host = pfv-r5-core-01.knel.net
|
||||||
|
|
||||||
|
++ pfv-r3-tor-mgmt-01
|
||||||
|
menu = pfv-r3-tor-mgmt-01 (Rack 3 Mgmt TOR)
|
||||||
|
title = Neyland 24T - Rack 3 Management TOR
|
||||||
|
host = pfv-r3-tor-mgmt-01.knel.net
|
||||||
|
|
||||||
|
++ pfv-r3-tor-stor-01
|
||||||
|
menu = pfv-r3-tor-stor-01 (Rack 3 Storage TOR)
|
||||||
|
title = Neyland 24T - Rack 3 Storage TOR
|
||||||
|
host = pfv-r3-tor-stor-01.knel.net
|
||||||
|
|
||||||
|
++ pfv-r6-mgmt-01
|
||||||
|
menu = pfv-r6-mgmt-01 (Rack 6 Mgmt Switch)
|
||||||
|
title = Neyland 24T - Rack 6 Management Switch
|
||||||
|
host = pfv-r6-mgmt-01.knel.net
|
||||||
|
|
||||||
|
+ Servers
|
||||||
|
menu = Servers
|
||||||
|
title = Server Infrastructure
|
||||||
|
|
||||||
|
++ pfv-stor1
|
||||||
|
menu = pfv-stor1
|
||||||
|
title = Storage Server 1
|
||||||
|
host = pfv-stor1.knel.net
|
||||||
|
|
||||||
|
++ pfv-bms
|
||||||
|
menu = pfv-bms (HomeAssistant)
|
||||||
|
title = Home Assistant / UniFi Controller
|
||||||
|
host = pfv-bms.knel.net
|
||||||
|
|
||||||
|
++ tsys-librenms
|
||||||
|
menu = tsys-librenms
|
||||||
|
title = LibreNMS Monitoring Server
|
||||||
|
host = tsys-librenms.knel.net
|
||||||
|
|
||||||
|
+ Wireless
|
||||||
|
menu = Wireless
|
||||||
|
title = Wireless Access Points
|
||||||
|
|
||||||
|
++ ap-tablemount
|
||||||
|
menu = ap-tablemount
|
||||||
|
title = UniFi AP-AC-Lite (Table Mount)
|
||||||
|
host = ap-tablemount.knel.net
|
||||||
|
|
||||||
|
++ ap-wallmount
|
||||||
|
menu = ap-wallmount
|
||||||
|
title = UniFi AP-AC-LR (Wall Mount)
|
||||||
|
host = ap-wallmount.knel.net
|
||||||
|
|
||||||
|
+ ProxmoxHosts
|
||||||
|
menu = Proxmox Hosts
|
||||||
|
title = Proxmox Hypervisor Nodes
|
||||||
|
|
||||||
|
++ pfv-tsys1
|
||||||
|
menu = pfv-tsys1
|
||||||
|
title = Proxmox Host - Infrastructure
|
||||||
|
host = pfv-tsys1.knel.net
|
||||||
|
|
||||||
|
++ pfv-tsys3
|
||||||
|
menu = pfv-tsys3
|
||||||
|
title = Proxmox Host - Compute
|
||||||
|
host = pfv-tsys3.knel.net
|
||||||
|
|
||||||
|
++ pfv-tsys4
|
||||||
|
menu = pfv-tsys4
|
||||||
|
title = Proxmox Host - Storage + PBS
|
||||||
|
host = pfv-tsys4.knel.net
|
||||||
|
|
||||||
|
++ pfv-tsys5
|
||||||
|
menu = pfv-tsys5
|
||||||
|
title = Proxmox Host - Storage + Sandbox
|
||||||
|
host = pfv-tsys5.knel.net
|
||||||
|
|
||||||
|
++ pfv-tsys6
|
||||||
|
menu = pfv-tsys6
|
||||||
|
title = Proxmox Host - RackRental
|
||||||
|
host = pfv-tsys6.knel.net
|
||||||
|
|
||||||
|
++ pfv-tsys7
|
||||||
|
menu = pfv-tsys7
|
||||||
|
title = Proxmox Host - RackRental
|
||||||
|
host = pfv-tsys7.knel.net
|
||||||
|
|
||||||
|
++ pfv-tsys9
|
||||||
|
menu = pfv-tsys9
|
||||||
|
title = Proxmox Host - Infra + Compute
|
||||||
|
host = pfv-tsys9.knel.net
|
||||||
|
|
||||||
|
+ Power
|
||||||
|
menu = Power
|
||||||
|
title = Power Devices
|
||||||
|
|
||||||
|
++ pfv-garage-pdu-01
|
||||||
|
menu = pfv-garage-pdu-1
|
||||||
|
title = APC PDU (Garage)
|
||||||
|
host = pfv-garage-pdu-1.knel.net
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
services:
|
||||||
|
smokeping:
|
||||||
|
image: linuxserver/smokeping:2.9.0
|
||||||
|
container_name: oam-smokeping
|
||||||
|
environment:
|
||||||
|
- PUID=1000
|
||||||
|
- PGID=1000
|
||||||
|
- TZ=America/Chicago
|
||||||
|
volumes:
|
||||||
|
- /opt/oam/smokeping/config:/config
|
||||||
|
- /opt/oam/smokeping/data:/data
|
||||||
|
ports:
|
||||||
|
- "8081:80"
|
||||||
|
restart: unless-stopped
|
||||||
@@ -0,0 +1,237 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# Deploy Smokeping on tsys-librenms
|
||||||
|
# Part of OAM platform [#337]
|
||||||
|
|
||||||
|
echo "=== Setting up Smokeping ==="
|
||||||
|
|
||||||
|
# Ensure directories
|
||||||
|
mkdir -p /opt/oam/smokeping/{config,data}
|
||||||
|
|
||||||
|
# General config
|
||||||
|
cat > /opt/oam/smokeping/config/General <<'GENEOF'
|
||||||
|
*** General ***
|
||||||
|
|
||||||
|
owner = Charles N Wyble
|
||||||
|
contact = reachableceo@knownelement.com
|
||||||
|
mailhost = localhost
|
||||||
|
cgiurl = http://tsys-librenms.knel.net:8081/smokeping/smokeping.cgi
|
||||||
|
syslogfacility = local0
|
||||||
|
pagedir = /data/pages
|
||||||
|
piddir = /tmp
|
||||||
|
imgcache = /data/cache
|
||||||
|
imgurl = /smokeping/images
|
||||||
|
datadir = /data/_data
|
||||||
|
dyndir = /data/dyn
|
||||||
|
|
||||||
|
*** Database ***
|
||||||
|
|
||||||
|
step = 300
|
||||||
|
pings = 20
|
||||||
|
|
||||||
|
AVERAGE 0.5 1 100800
|
||||||
|
AVERAGE 0.5 12 43200
|
||||||
|
MIN 0.5 12 43200
|
||||||
|
MAX 0.5 12 43200
|
||||||
|
AVERAGE 0.5 144 7200
|
||||||
|
MAX 0.5 144 7200
|
||||||
|
MIN 0.5 144 7200
|
||||||
|
|
||||||
|
*** Presentation ***
|
||||||
|
|
||||||
|
template = /etc/smokeping/basepage.html
|
||||||
|
|
||||||
|
+ charts
|
||||||
|
|
||||||
|
+ detail
|
||||||
|
width = 600
|
||||||
|
height = 200
|
||||||
|
nradius = 5
|
||||||
|
|
||||||
|
*** Probes ***
|
||||||
|
|
||||||
|
+ FPing
|
||||||
|
|
||||||
|
binary = /usr/local/bin/fping
|
||||||
|
hostinterval = 1.5
|
||||||
|
mininterval = 0.001
|
||||||
|
offset = 0%
|
||||||
|
|
||||||
|
*** Alerts ***
|
||||||
|
|
||||||
|
to = reachableceo@knownelement.com
|
||||||
|
from = smokeping-alert@tsys-librenms.knel.net
|
||||||
|
|
||||||
|
+bigloss
|
||||||
|
type = loss
|
||||||
|
pattern = ==0%,==0%,==0%,==0%,>0%,>0%,>0%
|
||||||
|
comment = suddenly there is packet loss
|
||||||
|
|
||||||
|
+somedoss
|
||||||
|
type = loss
|
||||||
|
pattern = ==0%,==0%,==0%,==0%,==0%,>0%,>0%,>0%,>0%,>0%,>0%,>0%
|
||||||
|
comment = incoming packet loss
|
||||||
|
|
||||||
|
+startloss
|
||||||
|
type = loss
|
||||||
|
pattern = >0%,>0%,>0%
|
||||||
|
comment = loss at startup
|
||||||
|
|
||||||
|
+rttdetect
|
||||||
|
type = rtt
|
||||||
|
pattern = <10,<10,<10,<10,<10,<10,<10,>10,>10,>10
|
||||||
|
comment = routing change?
|
||||||
|
|
||||||
|
+rttbadd
|
||||||
|
type = rtt
|
||||||
|
pattern = <50,<50,<50,<50,<50,<50,>50,>50,>50,>50
|
||||||
|
comment = reroute?
|
||||||
|
GENEOF
|
||||||
|
|
||||||
|
# Targets config
|
||||||
|
cat > /opt/oam/smokeping/config/Targets <<'TGTEOF'
|
||||||
|
*** Targets ***
|
||||||
|
|
||||||
|
probe = FPing
|
||||||
|
|
||||||
|
menu = Top
|
||||||
|
title = Network Latency Monitor
|
||||||
|
|
||||||
|
+ Infrastructure
|
||||||
|
menu = Infrastructure
|
||||||
|
title = Core Infrastructure
|
||||||
|
|
||||||
|
++ pfv-r5-core-01
|
||||||
|
menu = pfv-r5-core-01 (Core Switch)
|
||||||
|
title = Dell PowerConnect 5448 - Rack 5 Core
|
||||||
|
host = pfv-r5-core-01.knel.net
|
||||||
|
|
||||||
|
++ pfv-r3-tor-mgmt-01
|
||||||
|
menu = pfv-r3-tor-mgmt-01 (Rack 3 Mgmt TOR)
|
||||||
|
title = Neyland 24T - Rack 3 Management TOR
|
||||||
|
host = pfv-r3-tor-mgmt-01.knel.net
|
||||||
|
|
||||||
|
++ pfv-r3-tor-stor-01
|
||||||
|
menu = pfv-r3-tor-stor-01 (Rack 3 Storage TOR)
|
||||||
|
title = Neyland 24T - Rack 3 Storage TOR
|
||||||
|
host = pfv-r3-tor-stor-01.knel.net
|
||||||
|
|
||||||
|
++ pfv-r6-mgmt-01
|
||||||
|
menu = pfv-r6-mgmt-01 (Rack 6 Mgmt Switch)
|
||||||
|
title = Neyland 24T - Rack 6 Management Switch
|
||||||
|
host = pfv-r6-mgmt-01.knel.net
|
||||||
|
|
||||||
|
+ Servers
|
||||||
|
menu = Servers
|
||||||
|
title = Server Infrastructure
|
||||||
|
|
||||||
|
++ pfv-stor1
|
||||||
|
menu = pfv-stor1
|
||||||
|
title = Storage Server 1
|
||||||
|
host = pfv-stor1.knel.net
|
||||||
|
|
||||||
|
++ pfv-bms
|
||||||
|
menu = pfv-bms (HomeAssistant)
|
||||||
|
title = Home Assistant / UniFi Controller
|
||||||
|
host = pfv-bms.knel.net
|
||||||
|
|
||||||
|
++ tsys-librenms
|
||||||
|
menu = tsys-librenms
|
||||||
|
title = LibreNMS Monitoring Server
|
||||||
|
host = tsys-librenms.knel.net
|
||||||
|
|
||||||
|
+ Wireless
|
||||||
|
menu = Wireless
|
||||||
|
title = Wireless Access Points
|
||||||
|
|
||||||
|
++ ap-tablemount
|
||||||
|
menu = ap-tablemount
|
||||||
|
title = UniFi AP-AC-Lite (Table Mount)
|
||||||
|
host = ap-tablemount.knel.net
|
||||||
|
|
||||||
|
++ ap-wallmount
|
||||||
|
menu = ap-wallmount
|
||||||
|
title = UniFi AP-AC-LR (Wall Mount)
|
||||||
|
host = ap-wallmount.knel.net
|
||||||
|
|
||||||
|
+ ProxmoxHosts
|
||||||
|
menu = Proxmox Hosts
|
||||||
|
title = Proxmox Hypervisor Nodes
|
||||||
|
|
||||||
|
++ pfv-tsys1
|
||||||
|
menu = pfv-tsys1
|
||||||
|
title = Proxmox Host - Infrastructure
|
||||||
|
host = pfv-tsys1.knel.net
|
||||||
|
|
||||||
|
++ pfv-tsys3
|
||||||
|
menu = pfv-tsys3
|
||||||
|
title = Proxmox Host - Compute
|
||||||
|
host = pfv-tsys3.knel.net
|
||||||
|
|
||||||
|
++ pfv-tsys4
|
||||||
|
menu = pfv-tsys4
|
||||||
|
title = Proxmox Host - Storage + PBS
|
||||||
|
host = pfv-tsys4.knel.net
|
||||||
|
|
||||||
|
++ pfv-tsys5
|
||||||
|
menu = pfv-tsys5
|
||||||
|
title = Proxmox Host - Storage + Sandbox
|
||||||
|
host = pfv-tsys5.knel.net
|
||||||
|
|
||||||
|
++ pfv-tsys6
|
||||||
|
menu = pfv-tsys6
|
||||||
|
title = Proxmox Host - RackRental
|
||||||
|
host = pfv-tsys6.knel.net
|
||||||
|
|
||||||
|
++ pfv-tsys7
|
||||||
|
menu = pfv-tsys7
|
||||||
|
title = Proxmox Host - RackRental
|
||||||
|
host = pfv-tsys7.knel.net
|
||||||
|
|
||||||
|
++ pfv-tsys9
|
||||||
|
menu = pfv-tsys9
|
||||||
|
title = Proxmox Host - Infra + Compute
|
||||||
|
host = pfv-tsys9.knel.net
|
||||||
|
|
||||||
|
+ Power
|
||||||
|
menu = Power
|
||||||
|
title = Power Devices
|
||||||
|
|
||||||
|
++ pfv-garage-pdu-01
|
||||||
|
menu = pfv-garage-pdu-1
|
||||||
|
title = APC PDU (Garage)
|
||||||
|
host = pfv-garage-pdu-1.knel.net
|
||||||
|
TGTEOF
|
||||||
|
|
||||||
|
# Docker compose
|
||||||
|
cat > /opt/oam/smokeping/docker-compose.yml <<'DCEOF'
|
||||||
|
services:
|
||||||
|
smokeping:
|
||||||
|
image: linuxserver/smokeping:2.9.0
|
||||||
|
container_name: oam-smokeping
|
||||||
|
environment:
|
||||||
|
- PUID=1000
|
||||||
|
- PGID=1000
|
||||||
|
- TZ=America/Chicago
|
||||||
|
volumes:
|
||||||
|
- /opt/oam/smokeping/config:/config
|
||||||
|
- /opt/oam/smokeping/data:/data
|
||||||
|
ports:
|
||||||
|
- "8081:80"
|
||||||
|
restart: unless-stopped
|
||||||
|
DCEOF
|
||||||
|
|
||||||
|
echo "=== Starting Smokeping container ==="
|
||||||
|
cd /opt/oam/smokeping && docker compose up -d 2>&1
|
||||||
|
|
||||||
|
echo "=== Waiting for startup ==="
|
||||||
|
sleep 5
|
||||||
|
|
||||||
|
echo "=== Container status ==="
|
||||||
|
docker ps --filter name=oam-smokeping --format "table {{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}"
|
||||||
|
|
||||||
|
echo "=== Smokeping logs (last 20) ==="
|
||||||
|
docker logs oam-smokeping --tail 20 2>&1
|
||||||
|
|
||||||
|
echo "=== Done ==="
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
#
|
||||||
|
# tests/shellcheck.sh — enforce shellcheck (via Docker) on all repo shell scripts
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
# bash tests/shellcheck.sh # lint every .sh in the repo
|
||||||
|
# bash tests/shellcheck.sh path/a.sh path/b.sh # lint specific files
|
||||||
|
#
|
||||||
|
# Uses the koalaman/shellcheck:stable image (no native binary required).
|
||||||
|
# Exits non-zero if ANY script emits a diagnostic. Skips non-bash scripts
|
||||||
|
# (e.g. PHP files with a .sh extension) and the vendored/ trees.
|
||||||
|
#
|
||||||
|
set -uo pipefail
|
||||||
|
|
||||||
|
IMAGE="koalaman/shellcheck:stable"
|
||||||
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||||
|
|
||||||
|
# --- Gather target files -----------------------------------------------------
|
||||||
|
mapfile -t FILES < <(
|
||||||
|
if [ "$#" -gt 0 ]; then
|
||||||
|
# Explicit args: resolve to repo-root-relative paths, keep only .sh
|
||||||
|
for f in "$@"; do
|
||||||
|
f_abs="$(cd "$(dirname "$f")" && pwd)/$(basename "$f")"
|
||||||
|
case "$f_abs" in
|
||||||
|
"$ROOT"/vendor/*) ;; # skip vendored
|
||||||
|
"$ROOT"/archive/provisioning/Agents/librenms/*) ;; # upstream librenms-agent scripts
|
||||||
|
"$ROOT"/oam/librenms-agent/agent/*) ;; # upstream librenms-agent scripts (verbatim port [#474])
|
||||||
|
"$ROOT"/archive/KNELServerBuild/*) ;; # archived legacy code, not maintained [#474]
|
||||||
|
*) case "$f_abs" in *.sh) echo "$f_abs";; esac ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
else
|
||||||
|
# Default: every .sh under the repo, minus vendor/
|
||||||
|
while IFS= read -r f_abs; do
|
||||||
|
case "$f_abs" in
|
||||||
|
"$ROOT"/vendor/*) ;; # skip vendored
|
||||||
|
"$ROOT"/archive/provisioning/Agents/librenms/*) ;; # upstream librenms-agent scripts
|
||||||
|
"$ROOT"/oam/librenms-agent/agent/*) ;; # upstream librenms-agent scripts (verbatim port [#474])
|
||||||
|
"$ROOT"/archive/KNELServerBuild/*) ;; # archived legacy code, not maintained [#474]
|
||||||
|
*) echo "$f_abs" ;;
|
||||||
|
esac
|
||||||
|
done < <(find "$ROOT" -type f -name '*.sh' \
|
||||||
|
-not -path '*/.git/*' -not -path "$ROOT/vendor/*" \
|
||||||
|
-not -path "$ROOT/.crush/*")
|
||||||
|
fi
|
||||||
|
)
|
||||||
|
|
||||||
|
if [ "${#FILES[@]}" -eq 0 ]; then
|
||||||
|
echo "shellcheck.sh: no .sh files to check." >&2
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --- Filter out non-bash scripts (e.g. PHP with a .sh extension) --------------
|
||||||
|
BASH_FILES=()
|
||||||
|
for f in "${FILES[@]}"; do
|
||||||
|
shebang=$(head -c 64 "$f" 2>/dev/null | head -n1)
|
||||||
|
case "$shebang" in
|
||||||
|
\#!/usr/bin/php*|\#!/usr/bin/env\ php*) ;; # PHP, skip
|
||||||
|
\#!*) BASH_FILES+=("$f") ;; # any other shebang → check
|
||||||
|
*) BASH_FILES+=("$f") ;; # no shebang → check anyway
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "${#BASH_FILES[@]}" -eq 0 ]; then
|
||||||
|
echo "shellcheck.sh: no bash scripts among targets." >&2
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --- Run shellcheck in Docker (mount repo root, pass root-relative paths) -----
|
||||||
|
# shellcheck disable=SC2012 # basename loop is intentional
|
||||||
|
REL=()
|
||||||
|
for f in "${BASH_FILES[@]}"; do REL+=("${f#"$ROOT"/}"); done
|
||||||
|
|
||||||
|
# Disable checks that are intentional conventions of this codebase (not bugs):
|
||||||
|
# SC1090/SC1091 — cannot follow dynamically-computed `source` paths (KNEL framework)
|
||||||
|
# SC2029 — ssh orchestration deliberately expands the command client-side
|
||||||
|
DISABLES=(
|
||||||
|
-e SC1090
|
||||||
|
-e SC1091
|
||||||
|
-e SC2029
|
||||||
|
)
|
||||||
|
|
||||||
|
echo "Checking ${#BASH_FILES[@]} script(s) with $IMAGE:"
|
||||||
|
printf ' %s\n' "${REL[@]}"
|
||||||
|
|
||||||
|
docker run --rm \
|
||||||
|
-v "$ROOT:/mnt:ro" \
|
||||||
|
-w /mnt \
|
||||||
|
"$IMAGE" -x "${DISABLES[@]}" "${REL[@]}"
|
||||||
|
rc=$?
|
||||||
|
|
||||||
|
if [ "$rc" -eq 0 ]; then
|
||||||
|
echo "shellcheck: PASS (${#BASH_FILES[@]} scripts clean)"
|
||||||
|
else
|
||||||
|
echo "shellcheck: FAIL (fix the findings above or add targeted disable directives)" >&2
|
||||||
|
fi
|
||||||
|
exit "$rc"
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# Deploy UNPoller on tsys-librenms
|
||||||
|
# Part of OAM platform [#337]
|
||||||
|
# UniFi controller polling for metrics export
|
||||||
|
|
||||||
|
echo "=== Setting up UNPoller ==="
|
||||||
|
|
||||||
|
mkdir -p /opt/oam/unpoller
|
||||||
|
|
||||||
|
# Write config
|
||||||
|
cat > /opt/oam/unpoller/up.conf <<'CONFEOF'
|
||||||
|
[poller]
|
||||||
|
debug = false
|
||||||
|
quiet = false
|
||||||
|
plugins = []
|
||||||
|
|
||||||
|
[unifi.defaults]
|
||||||
|
url = "https://pfv-bms.knel.net:8443"
|
||||||
|
user = "CHANGE_ME"
|
||||||
|
pass = "CHANGE_ME"
|
||||||
|
sites = ["all"]
|
||||||
|
ssl_verify = false
|
||||||
|
|
||||||
|
[unifi.defaults.save_dpi]
|
||||||
|
enabled = true
|
||||||
|
|
||||||
|
[influxdb]
|
||||||
|
enable = false
|
||||||
|
url = "http://tsys-librenms.knel.net:8086"
|
||||||
|
db = "unifi"
|
||||||
|
|
||||||
|
[datadog]
|
||||||
|
enable = false
|
||||||
|
|
||||||
|
[prometheus]
|
||||||
|
enable = true
|
||||||
|
http_listen = ":9130"
|
||||||
|
report_errors = true
|
||||||
|
|
||||||
|
[loki]
|
||||||
|
enable = false
|
||||||
|
CONFEOF
|
||||||
|
|
||||||
|
# Docker compose
|
||||||
|
cat > /opt/oam/unpoller/docker-compose.yml <<'DCEOF'
|
||||||
|
services:
|
||||||
|
unpoller:
|
||||||
|
image: ghcr.io/unpoller/unpoller:latest
|
||||||
|
container_name: oam-unpoller
|
||||||
|
environment:
|
||||||
|
- UP_UNIFI_DEFAULT_URL=https://pfv-bms.knel.net:8443
|
||||||
|
- UP_UNIFI_DEFAULT_USER=CHANGE_ME
|
||||||
|
- UP_UNIFI_DEFAULT_PASS=CHANGE_ME
|
||||||
|
- UP_UNIFI_DEFAULT_VERIFY_SSL=false
|
||||||
|
- UP_PROMETHEUS_ENABLE=true
|
||||||
|
- UP_PROMETHEUS_HTTP_LISTEN=:9130
|
||||||
|
- TZ=America/Chicago
|
||||||
|
ports:
|
||||||
|
- "8084:9130"
|
||||||
|
volumes:
|
||||||
|
- /opt/oam/unpoller/up.conf:/config/unifi-poller.conf:ro
|
||||||
|
restart: unless-stopped
|
||||||
|
DCEOF
|
||||||
|
|
||||||
|
echo "=== Pulling UNPoller image ==="
|
||||||
|
cd /opt/oam/unpoller && timeout 120 docker compose pull 2>&1
|
||||||
|
|
||||||
|
echo "=== Starting UNPoller ==="
|
||||||
|
cd /opt/oam/unpoller && docker compose up -d 2>&1
|
||||||
|
|
||||||
|
echo "=== Status ==="
|
||||||
|
docker ps --filter name=oam-unpoller --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "=== IMPORTANT ==="
|
||||||
|
echo "UNPoller deployed with placeholder UniFi credentials (CHANGE_ME)."
|
||||||
|
echo "Update UP_UNIFI_DEFAULT_USER and UP_UNINI_DEFAULT_PASS env vars"
|
||||||
|
echo "in /opt/oam/unpoller/docker-compose.yml with real UniFi controller"
|
||||||
|
echo "credentials, then restart: cd /opt/oam/unpoller && docker compose up -d"
|
||||||
|
echo ""
|
||||||
|
echo "=== UNPoller Prometheus metrics: http://tsys-librenms.knel.net:8084 ==="
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
WIDTH 800
|
||||||
|
HEIGHT 600
|
||||||
|
HTMLOUTPUTFILE output/network.html
|
||||||
|
IMAGEOUTPUTFILE output/network.png
|
||||||
|
BACKGROUNDCOLOR 255 255 255
|
||||||
|
TITLE "PFV Cluster Network Map"
|
||||||
|
TIMEPOS 0 0
|
||||||
|
TITLECOLOR 0 0 0
|
||||||
|
TIMECOLOR 0 0 0
|
||||||
|
HTMLSTYLE overlib
|
||||||
|
KEYPOS DEFAULT 400 580
|
||||||
|
KEYTEXTCOLOR 0 0 0
|
||||||
|
KEYOUTLINECOLOR 0 0 0
|
||||||
|
KEYBGCOLOR 255 255 255
|
||||||
|
SCALE DEFAULT 0 10 0 255 0
|
||||||
|
SCALE DEFAULT 10 50 255 255 0
|
||||||
|
SCALE DEFAULT 50 100 255 128 0
|
||||||
|
SCALE DEFAULT 100 1000 255 0 0
|
||||||
|
NODE core_sw01
|
||||||
|
LABEL pfv-r5-core-01
|
||||||
|
POSITION 400 200
|
||||||
|
NODE tor_mgmt
|
||||||
|
LABEL pfv-r3-tor-mgmt-01
|
||||||
|
POSITION 200 350
|
||||||
|
NODE tor_stor
|
||||||
|
LABEL pfv-r3-tor-stor-01
|
||||||
|
POSITION 400 350
|
||||||
|
NODE r6_mgmt
|
||||||
|
LABEL pfv-r6-mgmt-01
|
||||||
|
POSITION 600 350
|
||||||
|
NODE pfv_tsys1
|
||||||
|
LABEL pfv-tsys1
|
||||||
|
POSITION 200 100
|
||||||
|
NODE pfv_tsys9
|
||||||
|
LABEL pfv-tsys9
|
||||||
|
POSITION 600 100
|
||||||
|
NODE pfv_bms
|
||||||
|
LABEL pfv-bms
|
||||||
|
POSITION 100 200
|
||||||
|
LINK core_to_mgmt
|
||||||
|
NODES core_sw01 tor_mgmt
|
||||||
|
BANDWIDTH 1000M
|
||||||
|
LINK core_to_stor
|
||||||
|
NODES core_sw01 tor_stor
|
||||||
|
BANDWIDTH 1000M
|
||||||
|
LINK core_to_r6
|
||||||
|
NODES core_sw01 r6_mgmt
|
||||||
|
BANDWIDTH 1000M
|
||||||
|
LINK tsys1_to_core
|
||||||
|
NODES pfv_tsys1 core_sw01
|
||||||
|
BANDWIDTH 1000M
|
||||||
|
LINK tsys9_to_core
|
||||||
|
NODES pfv_tsys9 core_sw01
|
||||||
|
BANDWIDTH 1000M
|
||||||
|
LINK bms_to_core
|
||||||
|
NODES pfv_bms core_sw01
|
||||||
|
BANDWIDTH 1000M
|
||||||
Reference in New Issue
Block a user