Compare commits
No commits in common. "main" and "dev-typescript" have entirely different histories.
main
...
dev-typesc
|
|
@ -2,7 +2,6 @@ test:
|
|||
image: docker.io/library/alpine:3.18
|
||||
script:
|
||||
- apk update
|
||||
- apk add python3 npm
|
||||
- npm install --global typescript mocha
|
||||
- tools/build --include-tests
|
||||
- mocha heimdall-test.mocha.js
|
||||
- apk add python3 py3-requests
|
||||
- tools/build --target=test
|
||||
- build/heimdall-test
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
"attentive_interval": 1,
|
||||
"reminding_interval": 20
|
||||
},
|
||||
"threshold": 1,
|
||||
"threshold": 3,
|
||||
"notifications": [
|
||||
{
|
||||
"kind": "console",
|
||||
|
|
@ -15,6 +15,6 @@
|
|||
]
|
||||
},
|
||||
"includes": [
|
||||
"tls_certificate.hmdl.json"
|
||||
"file_state.hmdl.json"
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,14 @@
|
|||
"kind": "tls_certificate",
|
||||
"parameters": {
|
||||
"host": "greenscale.de",
|
||||
"expiry_threshold": 74
|
||||
"expiry_threshold": 50
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "test2",
|
||||
"kind": "tls_certificate",
|
||||
"parameters": {
|
||||
"host": "chemnitz-gesundheit.de"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
|||
674
gpl-3.0.txt
674
gpl-3.0.txt
|
|
@ -1,674 +0,0 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is 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. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
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.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
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 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. Use with the GNU Affero General Public License.
|
||||
|
||||
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 Affero 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 special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU 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 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 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 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.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
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 GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
260
lib/plankton/plankton.d.ts
vendored
260
lib/plankton/plankton.d.ts
vendored
|
|
@ -202,6 +202,154 @@ declare class class_observer {
|
|||
/**
|
||||
* @author frac
|
||||
*/
|
||||
declare module lib_maybe {
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
type type_maybe<type_value> = {
|
||||
kind: string;
|
||||
parameters: Object;
|
||||
};
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
function make_nothing<type_value>(): type_maybe<type_value>;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
function make_just<type_value>(value: type_value): type_maybe<type_value>;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
function is_nothing<type_value>(maybe: type_maybe<type_value>): boolean;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
function is_just<type_value>(maybe: type_maybe<type_value>): boolean;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
function cull<type_value>(maybe: type_maybe<type_value>): type_value;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
function propagate<type_value, type_value_>(maybe: type_maybe<type_value>, function_: (value: type_value) => type_maybe<type_value_>): type_maybe<type_value_>;
|
||||
}
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
declare class class_maybe<type_value> implements interface_showable {
|
||||
/**
|
||||
* @desc whether the wrapper is nothing
|
||||
* @author fenris
|
||||
*/
|
||||
is_nothing(): boolean;
|
||||
/**
|
||||
* @desc whether the wrapper is just
|
||||
* @author fenris
|
||||
*/
|
||||
is_just(): boolean;
|
||||
/**
|
||||
* @desc return the value, stored in the maybe-wrapper
|
||||
* @author fenris
|
||||
*/
|
||||
cull(): type_value;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
toString(): string;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
distinguish(action_just: (value?: type_value) => void, action_nothing?: (reason?: string) => void): void;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
propagate<type_value_>(action: (value: type_value) => class_maybe<type_value_>): class_maybe<type_value_>;
|
||||
/**
|
||||
* @desc [implementation]
|
||||
* @author fenris
|
||||
*/
|
||||
_show(): string;
|
||||
}
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
declare class class_nothing<type_value> extends class_maybe<type_value> {
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
private reason;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
constructor(reason?: string);
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
is_nothing(): boolean;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
is_just(): boolean;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
cull(): type_value;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
toString(): string;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
reason_get(): string;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
distinguish(action_just: (value?: type_value) => void, action_nothing?: (reason?: string) => void): void;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
propagate<type_value_>(action: (value: type_value) => class_maybe<type_value_>): class_maybe<type_value_>;
|
||||
}
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
declare class class_just<type_value> extends class_maybe<type_value> {
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
private value;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
constructor(value: type_value);
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
is_nothing(): boolean;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
is_just(): boolean;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
cull(): type_value;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
toString(): string;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
distinguish(action_just: (value?: type_value) => void, action_nothing?: (reason?: string) => void): void;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
propagate<type_value_>(action: (value: type_value) => class_maybe<type_value_>): class_maybe<type_value_>;
|
||||
}
|
||||
/**
|
||||
* @author frac
|
||||
*/
|
||||
|
|
@ -235,65 +383,6 @@ declare namespace lib_plankton.base {
|
|||
*/
|
||||
function object_merge(core: Record<string, any>, mantle: Record<string, any>): Record<string, any>;
|
||||
}
|
||||
declare module lib_plankton.pod {
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
type type_pod<type_value> = {
|
||||
kind: ("empty" | "filled");
|
||||
value?: type_value;
|
||||
};
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
function make_empty<type_value>(): type_pod<type_value>;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
function make_filled<type_value>(value: type_value): type_pod<type_value>;
|
||||
/**
|
||||
* whether the pod is filled
|
||||
*
|
||||
* @author fenris
|
||||
*/
|
||||
function is_filled<type_value>(pod: type_pod<type_value>): boolean;
|
||||
/**
|
||||
* return the value, stored in the pod-wrapper
|
||||
*
|
||||
* @author fenris
|
||||
*/
|
||||
function cull<type_value>(pod: type_pod<type_value>): type_value;
|
||||
/**
|
||||
* to pass on a empty-pod or to use a filled-pod
|
||||
*
|
||||
* @author fenris
|
||||
*/
|
||||
function propagate<type_value, type_value_>(pod: type_pod<type_value>, function_: ((value: type_value) => type_value_)): type_pod<type_value_>;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
function distinguish<type_value, type_result>(pod: type_pod<type_value>, function_empty: (() => type_result), function_filled: ((value: type_value) => type_result)): type_result;
|
||||
/**
|
||||
*/
|
||||
function show<type_value>(pod: type_pod<type_value>, options?: {
|
||||
show_value?: ((value: type_value) => string);
|
||||
}): string;
|
||||
}
|
||||
declare module lib_plankton.pod {
|
||||
/**
|
||||
*/
|
||||
class class_pod<type_value> {
|
||||
private subject;
|
||||
private constructor();
|
||||
is_empty(): boolean;
|
||||
is_filled(): boolean;
|
||||
cull(): type_value;
|
||||
show(show_value?: any): string;
|
||||
toString(): string;
|
||||
propagate<type_value_>(function_: ((value: type_value) => type_value_)): class_pod<type_value_>;
|
||||
distinguish<type_result>(function_empty: (() => type_result), function_filled: ((value: type_value) => type_result)): type_result;
|
||||
}
|
||||
}
|
||||
declare namespace lib_plankton.call {
|
||||
/**
|
||||
* @desc hacked class for postfix function application
|
||||
|
|
@ -455,9 +544,11 @@ declare namespace lib_plankton.call {
|
|||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
function promise_show<type_result, type_reason>(label: string): (result: type_result) => type_promise<type_result, type_reason>;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
function promise_log<type_result, type_reason>(result: type_result): (result: type_result) => type_promise<type_result, type_reason>;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
|
|
@ -1089,7 +1180,7 @@ declare namespace lib_plankton.string {
|
|||
to: string;
|
||||
}>, options?: {}): string;
|
||||
/**
|
||||
* @desc replaces occurences of "{{name}}" in a string by the corresponding values of an argument object
|
||||
* @desc replaces occurences of "${name}" in a string by the corresponding values of an argument object
|
||||
* @author fenris
|
||||
*/
|
||||
function coin(str: string, args: {
|
||||
|
|
@ -1396,9 +1487,6 @@ declare namespace lib_plankton.file {
|
|||
* @author fenris
|
||||
*/
|
||||
function write_buffer(path: string, content: Buffer, options?: {}): Promise<void>;
|
||||
/**
|
||||
*/
|
||||
function delete_(path: string): Promise<void>;
|
||||
}
|
||||
declare namespace lib_plankton.translate {
|
||||
/**
|
||||
|
|
@ -1443,7 +1531,7 @@ declare namespace lib_plankton.translate {
|
|||
*/
|
||||
function fetch(identifier: string, path: string, args?: {
|
||||
[id: string]: string;
|
||||
}): lib_plankton.pod.type_pod<string>;
|
||||
}): class_maybe<string>;
|
||||
/**
|
||||
* @desc retrieves a string by going through the order and trying to fetch it for the current entry
|
||||
* @author fenris
|
||||
|
|
@ -1739,7 +1827,7 @@ declare namespace lib_plankton.http {
|
|||
* @author fenris <frass@greenscale.de>
|
||||
*/
|
||||
type type_response = {
|
||||
version: (null | string);
|
||||
version: string;
|
||||
status_code: int;
|
||||
headers: Record<string, string>;
|
||||
body: Buffer;
|
||||
|
|
@ -1817,45 +1905,3 @@ declare namespace lib_plankton.http {
|
|||
decode(x: string): type_response;
|
||||
}
|
||||
}
|
||||
declare namespace lib_plankton.sqlite {
|
||||
/**
|
||||
*/
|
||||
type type_query_raw = {
|
||||
template: string;
|
||||
arguments: Record<string, any>;
|
||||
};
|
||||
/**
|
||||
*/
|
||||
type type_connection = {
|
||||
handle: any;
|
||||
};
|
||||
/**
|
||||
*/
|
||||
function get_connection(database_path: string): Promise<type_connection>;
|
||||
/**
|
||||
*/
|
||||
function drop_connection(connection: type_connection): Promise<void>;
|
||||
/**
|
||||
* for CREATE TABLE, DROP TABLE, etc.
|
||||
*/
|
||||
function query_set(connection: type_connection, query_raw: type_query_raw): Promise<any>;
|
||||
/**
|
||||
* for INSERT, UPDATE, DELETE
|
||||
*/
|
||||
function query_put(connection: type_connection, query_raw: type_query_raw): Promise<{
|
||||
id: (null | number);
|
||||
affected: (null | number);
|
||||
}>;
|
||||
/**
|
||||
* for SELECT
|
||||
*
|
||||
* @todo rather use handle procedure for rows instead of returning an array
|
||||
*/
|
||||
function query_get(connection: type_connection, query_raw: type_query_raw): Promise<Array<Record<string, any>>>;
|
||||
/**
|
||||
* for SELECT
|
||||
*
|
||||
* @todo rather use handle procedure for rows instead of returning an array
|
||||
*/
|
||||
function query_probe(connection: type_connection, query_raw: type_query_raw, handler: ((row: Record<string, any>) => void)): void;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -383,6 +383,261 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with »bacterio-plankton:base«. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
var lib_maybe;
|
||||
(function (lib_maybe) {
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
function make_nothing() {
|
||||
return {
|
||||
"kind": "nothing",
|
||||
"parameters": {}
|
||||
};
|
||||
}
|
||||
lib_maybe.make_nothing = make_nothing;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
function make_just(value) {
|
||||
return {
|
||||
"kind": "just",
|
||||
"parameters": {
|
||||
"value": value
|
||||
}
|
||||
};
|
||||
}
|
||||
lib_maybe.make_just = make_just;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
function is_nothing(maybe) {
|
||||
return (maybe.kind === "nothing");
|
||||
}
|
||||
lib_maybe.is_nothing = is_nothing;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
function is_just(maybe) {
|
||||
return (maybe.kind === "just");
|
||||
}
|
||||
lib_maybe.is_just = is_just;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
function cull(maybe) {
|
||||
if (!is_just(maybe)) {
|
||||
var message = "cull from nothing";
|
||||
throw (new Error(message));
|
||||
}
|
||||
else {
|
||||
var value = maybe.parameters["value"];
|
||||
return value;
|
||||
}
|
||||
}
|
||||
lib_maybe.cull = cull;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
function propagate(maybe, function_) {
|
||||
if (!is_just(maybe)) {
|
||||
}
|
||||
else {
|
||||
var value = maybe.parameters["value"];
|
||||
var maybe_ = function_(value);
|
||||
return maybe_;
|
||||
}
|
||||
}
|
||||
lib_maybe.propagate = propagate;
|
||||
})(lib_maybe || (lib_maybe = {}));
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
/*export*/ var class_maybe = /** @class */ (function () {
|
||||
function class_maybe() {
|
||||
}
|
||||
/**
|
||||
* @desc whether the wrapper is nothing
|
||||
* @author fenris
|
||||
*/
|
||||
class_maybe.prototype.is_nothing = function () {
|
||||
throw (new Error("not implemented: class_maybe.is_nothing"));
|
||||
};
|
||||
/**
|
||||
* @desc whether the wrapper is just
|
||||
* @author fenris
|
||||
*/
|
||||
class_maybe.prototype.is_just = function () {
|
||||
throw (new Error("not implemented: class_maybe.is_just"));
|
||||
};
|
||||
/**
|
||||
* @desc return the value, stored in the maybe-wrapper
|
||||
* @author fenris
|
||||
*/
|
||||
class_maybe.prototype.cull = function () {
|
||||
throw (new Error("not implemented: class_maybe.cull"));
|
||||
};
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
class_maybe.prototype.toString = function () {
|
||||
throw (new Error("not implemented: class_maybe.cull"));
|
||||
};
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
class_maybe.prototype.distinguish = function (action_just, action_nothing) {
|
||||
if (action_nothing === void 0) { action_nothing = function () { }; }
|
||||
throw (new Error("not implemented: class_maybe.distinguish"));
|
||||
};
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
class_maybe.prototype.propagate = function (action) {
|
||||
throw (new Error("not implemented: class_maybe.propagate"));
|
||||
};
|
||||
/**
|
||||
* @desc [implementation]
|
||||
* @author fenris
|
||||
*/
|
||||
class_maybe.prototype._show = function () {
|
||||
return this.toString();
|
||||
};
|
||||
return class_maybe;
|
||||
}());
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
/*export*/ var class_nothing = /** @class */ (function (_super) {
|
||||
__extends(class_nothing, _super);
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
function class_nothing(reason) {
|
||||
if (reason === void 0) { reason = null; }
|
||||
var _this = _super.call(this) || this;
|
||||
_this.reason = reason;
|
||||
return _this;
|
||||
}
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
class_nothing.prototype.is_nothing = function () {
|
||||
return true;
|
||||
};
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
class_nothing.prototype.is_just = function () {
|
||||
return false;
|
||||
};
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
class_nothing.prototype.cull = function () {
|
||||
var message = "you shouldn't cull a nothing-value …";
|
||||
// lib_plankton.log.warn(message);
|
||||
return null;
|
||||
};
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
class_nothing.prototype.toString = function () {
|
||||
return "<\u00B7>";
|
||||
};
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
class_nothing.prototype.reason_get = function () {
|
||||
var content = ((this.reason == null) ? "·" : this.reason);
|
||||
return "<- ".concat(content, " ->");
|
||||
};
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
class_nothing.prototype.distinguish = function (action_just, action_nothing) {
|
||||
if (action_nothing === void 0) { action_nothing = function () { }; }
|
||||
action_nothing(this.reason);
|
||||
};
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
class_nothing.prototype.propagate = function (action) {
|
||||
return (new class_nothing(this.reason));
|
||||
};
|
||||
return class_nothing;
|
||||
}(class_maybe));
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
/*export*/ var class_just = /** @class */ (function (_super) {
|
||||
__extends(class_just, _super);
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
function class_just(value) {
|
||||
var _this = _super.call(this) || this;
|
||||
_this.value = value;
|
||||
return _this;
|
||||
}
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
class_just.prototype.is_nothing = function () {
|
||||
return false;
|
||||
};
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
class_just.prototype.is_just = function () {
|
||||
return true;
|
||||
};
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
class_just.prototype.cull = function () {
|
||||
return this.value;
|
||||
};
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
class_just.prototype.toString = function () {
|
||||
var content = instance_show(this.value);
|
||||
return "<+ ".concat(content, " +>");
|
||||
};
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
class_just.prototype.distinguish = function (action_just, action_nothing) {
|
||||
if (action_nothing === void 0) { action_nothing = function () { }; }
|
||||
action_just(this.value);
|
||||
};
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
class_just.prototype.propagate = function (action) {
|
||||
return action(this.value);
|
||||
};
|
||||
return class_just;
|
||||
}(class_maybe));
|
||||
/*
|
||||
This file is part of »bacterio-plankton:base«.
|
||||
|
||||
Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||
<info@greenscale.de>
|
||||
|
||||
»bacterio-plankton:base« is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
»bacterio-plankton:base« 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 Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with »bacterio-plankton:base«. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
|
@ -435,148 +690,6 @@ var lib_plankton;
|
|||
})(base = lib_plankton.base || (lib_plankton.base = {}));
|
||||
})(lib_plankton || (lib_plankton = {}));
|
||||
/*
|
||||
This file is part of »bacterio-plankton:pod«.
|
||||
|
||||
Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||
<info@greenscale.de>
|
||||
|
||||
»bacterio-plankton:pod« is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
»bacterio-plankton:pod« 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 Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with »bacterio-plankton:pod«. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
var lib_plankton;
|
||||
(function (lib_plankton) {
|
||||
var pod;
|
||||
(function (pod_1) {
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
function make_empty() {
|
||||
return {
|
||||
"kind": "empty"
|
||||
};
|
||||
}
|
||||
pod_1.make_empty = make_empty;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
function make_filled(value) {
|
||||
return {
|
||||
"kind": "filled",
|
||||
"value": value
|
||||
};
|
||||
}
|
||||
pod_1.make_filled = make_filled;
|
||||
/**
|
||||
* whether the pod is filled
|
||||
*
|
||||
* @author fenris
|
||||
*/
|
||||
function is_filled(pod) {
|
||||
return (pod.kind === "filled");
|
||||
}
|
||||
pod_1.is_filled = is_filled;
|
||||
/**
|
||||
* return the value, stored in the pod-wrapper
|
||||
*
|
||||
* @author fenris
|
||||
*/
|
||||
function cull(pod) {
|
||||
if (!is_filled(pod)) {
|
||||
throw (new Error("cull from empty"));
|
||||
}
|
||||
else {
|
||||
return pod.value;
|
||||
}
|
||||
}
|
||||
pod_1.cull = cull;
|
||||
/**
|
||||
* to pass on a empty-pod or to use a filled-pod
|
||||
*
|
||||
* @author fenris
|
||||
*/
|
||||
function propagate(pod, function_) {
|
||||
if (!is_filled(pod)) {
|
||||
return make_empty();
|
||||
}
|
||||
else {
|
||||
return make_filled(function_(pod.value));
|
||||
}
|
||||
}
|
||||
pod_1.propagate = propagate;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
function distinguish(pod, function_empty, function_filled) {
|
||||
return ((!is_filled(pod))
|
||||
? function_empty()
|
||||
: function_filled(pod.value));
|
||||
}
|
||||
pod_1.distinguish = distinguish;
|
||||
/**
|
||||
*/
|
||||
function show(pod, options = {}) {
|
||||
options = Object.assign({
|
||||
"show_value": value => String(value),
|
||||
}, options);
|
||||
if (!is_filled(pod)) {
|
||||
return "<·>";
|
||||
}
|
||||
else {
|
||||
return ("<- " + options.show_value(pod.value) + " ->");
|
||||
}
|
||||
}
|
||||
pod_1.show = show;
|
||||
})(pod = lib_plankton.pod || (lib_plankton.pod = {}));
|
||||
})(lib_plankton || (lib_plankton = {}));
|
||||
/*
|
||||
This file is part of »bacterio-plankton:pod«.
|
||||
|
||||
Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||
<info@greenscale.de>
|
||||
|
||||
»bacterio-plankton:pod« is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
»bacterio-plankton:pod« 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 Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with »bacterio-plankton:pod«. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
var lib_plankton;
|
||||
(function (lib_plankton) {
|
||||
var pod;
|
||||
(function (pod) {
|
||||
/**
|
||||
*/
|
||||
class class_pod {
|
||||
constructor(subject) { this.subject = subject; }
|
||||
is_empty() { return (!pod.is_filled(this.subject)); }
|
||||
is_filled() { return pod.is_filled(this.subject); }
|
||||
cull() { return pod.cull(this.subject); }
|
||||
show(show_value = undefined) { return pod.show(this.subject, show_value); }
|
||||
toString() { return this.show(); }
|
||||
propagate(function_) { return new class_pod(pod.propagate(this.subject, function_)); }
|
||||
distinguish(function_empty, function_filled) { return pod.distinguish(this.subject, function_empty, function_filled); }
|
||||
}
|
||||
pod.class_pod = class_pod;
|
||||
})(pod = lib_plankton.pod || (lib_plankton.pod = {}));
|
||||
})(lib_plankton || (lib_plankton = {}));
|
||||
/*
|
||||
This file is part of »bacterio-plankton:call«.
|
||||
|
||||
Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||
|
|
@ -1000,27 +1113,21 @@ var lib_plankton;
|
|||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
/*
|
||||
export function promise_show<type_result, type_reason>(label : string) : (result : type_result)=>type_promise<type_result, type_reason> {
|
||||
return (
|
||||
result => promise_make<type_result, type_reason>(
|
||||
(resolve, reject) => {
|
||||
// lib_plankton.log.info(label + ": " + instance_show(result));
|
||||
process.stdout.write(label + ": " + instance_show(result));
|
||||
resolve(result);
|
||||
}
|
||||
)
|
||||
);
|
||||
function promise_show(label) {
|
||||
return (result => promise_make((resolve, reject) => {
|
||||
// lib_plankton.log.info(label + ": " + instance_show(result));
|
||||
process.stdout.write(label + ": " + instance_show(result));
|
||||
resolve(result);
|
||||
}));
|
||||
}
|
||||
*/
|
||||
call.promise_show = promise_show;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
/*
|
||||
export function promise_log<type_result, type_reason>(result : type_result) : (result : type_result)=>type_promise<type_result, type_reason> {
|
||||
return promise_show<type_result, type_reason>("log");
|
||||
function promise_log(result) {
|
||||
return promise_show("log");
|
||||
}
|
||||
*/
|
||||
call.promise_log = promise_log;
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
|
|
@ -1335,16 +1442,16 @@ var lib_plankton;
|
|||
function deferral_compose_parallel({ "left": deferral_left, "right": deferral_right, }) {
|
||||
return (deferral_make((input, convey) => {
|
||||
let object = {
|
||||
"left": lib_plankton.pod.make_empty(),
|
||||
"right": lib_plankton.pod.make_empty(),
|
||||
"left": lib_maybe.make_nothing(),
|
||||
"right": lib_maybe.make_nothing(),
|
||||
};
|
||||
let finish = function () {
|
||||
if (lib_plankton.pod.is_filled(object.left)
|
||||
if (lib_maybe.is_just(object.left)
|
||||
&&
|
||||
lib_plankton.pod.is_filled(object.right)) {
|
||||
lib_maybe.is_just(object.right)) {
|
||||
let result = {
|
||||
"left": lib_plankton.pod.cull(object.left),
|
||||
"right": lib_plankton.pod.cull(object.right),
|
||||
"left": lib_maybe.cull(object.left),
|
||||
"right": lib_maybe.cull(object.right),
|
||||
};
|
||||
convey(result);
|
||||
}
|
||||
|
|
@ -1353,11 +1460,11 @@ var lib_plankton;
|
|||
}
|
||||
};
|
||||
deferral_use(deferral_left, input, output_left => {
|
||||
object.left = lib_plankton.pod.make_filled(output_left);
|
||||
object.left = lib_maybe.make_just(output_left);
|
||||
finish();
|
||||
});
|
||||
deferral_use(deferral_right, input, output_right => {
|
||||
object.right = lib_plankton.pod.make_filled(output_right);
|
||||
object.right = lib_maybe.make_just(output_right);
|
||||
finish();
|
||||
});
|
||||
}));
|
||||
|
|
@ -2195,14 +2302,14 @@ var lib_plankton;
|
|||
"info": lib_plankton.log.enum_level.info,
|
||||
"notice": lib_plankton.log.enum_level.notice,
|
||||
"warning": lib_plankton.log.enum_level.warning,
|
||||
"error": lib_plankton.log.enum_level.error,
|
||||
"error": lib_plankton.log.enum_level.error
|
||||
}[type]),
|
||||
"incident": message,
|
||||
"details": {
|
||||
"prefix": prefix,
|
||||
"level": level,
|
||||
"indent": indent,
|
||||
},
|
||||
"indent": indent
|
||||
}
|
||||
};
|
||||
lib_plankton.log.add(entry);
|
||||
}
|
||||
|
|
@ -2338,7 +2445,7 @@ var lib_plankton;
|
|||
var _this = this;
|
||||
var nm_fs = require("fs");
|
||||
nm_fs.writeFile(this.path, {
|
||||
"flag": "a+",
|
||||
"flag": "a+"
|
||||
}, (("<" + (new Date(Date.now())).toISOString().slice(0, 19) + ">")
|
||||
+
|
||||
" "
|
||||
|
|
@ -2511,7 +2618,7 @@ var lib_plankton;
|
|||
"info": log.enum_level.info,
|
||||
"notice": log.enum_level.notice,
|
||||
"warning": log.enum_level.warning,
|
||||
"error": log.enum_level.error,
|
||||
"error": log.enum_level.error
|
||||
}[level_string];
|
||||
}
|
||||
/**
|
||||
|
|
@ -3078,7 +3185,7 @@ var lib_plankton;
|
|||
}
|
||||
string.replace = replace;
|
||||
/**
|
||||
* @desc replaces occurences of "{{name}}" in a string by the corresponding values of an argument object
|
||||
* @desc replaces occurences of "${name}" in a string by the corresponding values of an argument object
|
||||
* @author fenris
|
||||
*/
|
||||
function coin(str, args, options = {}) {
|
||||
|
|
@ -3974,7 +4081,7 @@ var lib_plankton;
|
|||
}
|
||||
return {
|
||||
"keys": keys,
|
||||
"data": from.map(function (line) { return keys.map(function (name) { return line[name]; }); }),
|
||||
"data": from.map(function (line) { return keys.map(function (name) { return line[name]; }); })
|
||||
};
|
||||
}
|
||||
code.flatten_encode = flatten_encode;
|
||||
|
|
@ -4262,17 +4369,6 @@ var lib_plankton;
|
|||
}));
|
||||
}
|
||||
file.write_buffer = write_buffer;
|
||||
/**
|
||||
*/
|
||||
function delete_(path) {
|
||||
var nm_fs = require("fs");
|
||||
return (new Promise(function (resolve, reject) {
|
||||
nm_fs.unlink(path, function () {
|
||||
resolve(undefined);
|
||||
});
|
||||
}));
|
||||
}
|
||||
file.delete_ = delete_;
|
||||
})(file = lib_plankton.file || (lib_plankton.file = {}));
|
||||
})(lib_plankton || (lib_plankton = {}));
|
||||
/*
|
||||
|
|
@ -4395,7 +4491,7 @@ var lib_plankton;
|
|||
if (translate._verbosity >= 1) {
|
||||
console.warn(`${_logprefix} no package '${identifier}'`);
|
||||
}
|
||||
return (lib_plankton.pod.make_empty());
|
||||
return (new class_nothing());
|
||||
}
|
||||
else {
|
||||
// let str : string = lib_plankton.object.path_read<string>(_packages[identifier].tree, path);
|
||||
|
|
@ -4404,7 +4500,7 @@ var lib_plankton;
|
|||
if (translate._verbosity >= 1) {
|
||||
console.warn(`${_logprefix} string '${path}' missing in package '${identifier}'`);
|
||||
}
|
||||
return (lib_plankton.pod.make_empty());
|
||||
return (new class_nothing());
|
||||
}
|
||||
else {
|
||||
// resolve references
|
||||
|
|
@ -4432,13 +4528,13 @@ var lib_plankton;
|
|||
// fetch referenced string
|
||||
{
|
||||
let result_ = fetch(identifier, path_, args_);
|
||||
if (lib_plankton.pod.is_filled(result_)) {
|
||||
if (result_.is_just()) {
|
||||
let front = str.slice(0, matching.index);
|
||||
let back = str.slice(matching.index + matching[0].length);
|
||||
str = (front + lib_plankton.pod.cull(result_) + back);
|
||||
str = (front + result_.cull() + back);
|
||||
}
|
||||
else {
|
||||
return (lib_plankton.pod.make_empty());
|
||||
return (new class_nothing());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -4452,7 +4548,7 @@ var lib_plankton;
|
|||
{
|
||||
str = lib_plankton.string.coin(str, args);
|
||||
}
|
||||
return (lib_plankton.pod.make_filled(str));
|
||||
return (new class_just(str));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4468,13 +4564,13 @@ var lib_plankton;
|
|||
if (translate._verbosity >= 2) {
|
||||
console.info(`${_logprefix} getting translation for string '${path}' with arguments ${JSON.stringify(args)} …`);
|
||||
}
|
||||
let result = lib_plankton.pod.make_empty();
|
||||
let result = new class_nothing();
|
||||
let found = _order.some(identifier => {
|
||||
if (translate._verbosity >= 2) {
|
||||
console.info(`${_logprefix} trying package '${identifier}' …`);
|
||||
}
|
||||
let result_ = fetch(identifier, path, args);
|
||||
if (lib_plankton.pod.is_filled(result_)) {
|
||||
if (result_.is_just()) {
|
||||
result = result_;
|
||||
return true;
|
||||
}
|
||||
|
|
@ -4483,7 +4579,7 @@ var lib_plankton;
|
|||
}
|
||||
});
|
||||
if (found) {
|
||||
let str = lib_plankton.pod.cull(result);
|
||||
let str = result.cull();
|
||||
if (translate._verbosity >= 3) {
|
||||
console.info(`${_logprefix} found translation: '${str}'`);
|
||||
}
|
||||
|
|
@ -5690,10 +5786,7 @@ var lib_plankton;
|
|||
function decode_response(response_raw) {
|
||||
const lines = response_raw.split(linebreak);
|
||||
const first = lines.shift();
|
||||
const first_parts = first.split(" ");
|
||||
const version = first_parts[0];
|
||||
const status_code = parseInt(first_parts[1]);
|
||||
// first_parts.slice(2) ? probably irrelevant
|
||||
const status_code = parseInt(first.split(" ")[1]);
|
||||
let headers = {};
|
||||
while (true) {
|
||||
const line = lines.shift();
|
||||
|
|
@ -5708,7 +5801,7 @@ var lib_plankton;
|
|||
const body = Buffer["from"](lines.join(linebreak));
|
||||
const response = {
|
||||
// TODO
|
||||
"version": version,
|
||||
"version": "HTTP/1.1",
|
||||
"status_code": status_code,
|
||||
"headers": headers,
|
||||
"body": body,
|
||||
|
|
@ -5738,6 +5831,7 @@ var lib_plankton;
|
|||
((request.query === null)
|
||||
? ""
|
||||
: request.query));
|
||||
// console.info({target,options});
|
||||
switch (options.implementation) {
|
||||
default: {
|
||||
return Promise.reject("invalid implementation: " + options.implementation);
|
||||
|
|
@ -5757,7 +5851,6 @@ var lib_plankton;
|
|||
case http.enum_method.head: return "HEAD";
|
||||
}
|
||||
})(request.method)),
|
||||
"headers": request.headers,
|
||||
"redirect": (options.follow_redirects ? "follow" : "manual"),
|
||||
"signal": (signal ?? undefined),
|
||||
})
|
||||
|
|
@ -5768,7 +5861,7 @@ var lib_plankton;
|
|||
.then((response_raw) => (response_raw.text()
|
||||
.then((body) => Promise.resolve({
|
||||
// TODO
|
||||
"version": null,
|
||||
"version": "HTTP/1.1",
|
||||
"status_code": response_raw.status,
|
||||
"headers": ((headers_raw => {
|
||||
let headers = {};
|
||||
|
|
@ -5827,7 +5920,7 @@ var lib_plankton;
|
|||
res.on("end", () => {
|
||||
resolve({
|
||||
// TODO
|
||||
"version": null,
|
||||
"version": "HTTP/1.1",
|
||||
"status_code": res.statusCode,
|
||||
"headers": res.headers,
|
||||
"body": response_body,
|
||||
|
|
@ -5926,145 +6019,3 @@ var lib_plankton;
|
|||
http.class_http_response = class_http_response;
|
||||
})(http = lib_plankton.http || (lib_plankton.http = {}));
|
||||
})(lib_plankton || (lib_plankton = {}));
|
||||
/*
|
||||
This file is part of »bacterio-plankton:sqlite«.
|
||||
|
||||
Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||
<info@greenscale.de>
|
||||
|
||||
»bacterio-plankton:sqlite« is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
»bacterio-plankton:sqlite« 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 Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with »bacterio-plankton:sqlite«. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
var lib_plankton;
|
||||
(function (lib_plankton) {
|
||||
var sqlite;
|
||||
(function (sqlite) {
|
||||
/**
|
||||
*/
|
||||
function get_connection(database_path) {
|
||||
return (new Promise((resolve, reject) => {
|
||||
const nm_sqlite3 = require("sqlite3");
|
||||
const handle = new nm_sqlite3.Database(database_path, (nm_sqlite3.OPEN_READWRITE
|
||||
|
|
||||
nm_sqlite3.OPEN_CREATE
|
||||
|
|
||||
nm_sqlite3.OPEN_FULLMUTEX), (error) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
}
|
||||
else {
|
||||
resolve({
|
||||
"handle": handle,
|
||||
});
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
sqlite.get_connection = get_connection;
|
||||
/**
|
||||
*/
|
||||
function drop_connection(connection) {
|
||||
return (new Promise((resolve, reject) => {
|
||||
connection.handle.close(() => {
|
||||
resolve(undefined);
|
||||
});
|
||||
}));
|
||||
}
|
||||
sqlite.drop_connection = drop_connection;
|
||||
/**
|
||||
*/
|
||||
function query_transform(query_raw) {
|
||||
return {
|
||||
"template": query_raw.template,
|
||||
"arguments": Object.fromEntries(Object.entries(query_raw.arguments)
|
||||
.map(([key, value]) => ([(":" + key), value]))),
|
||||
};
|
||||
}
|
||||
/**
|
||||
* for CREATE TABLE, DROP TABLE, etc.
|
||||
*/
|
||||
async function query_set(connection, query_raw) {
|
||||
const query_transformed = query_transform(query_raw);
|
||||
return (new Promise((resolve, reject) => {
|
||||
connection.handle.run(query_transformed.template, query_transformed.arguments, (error) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
}
|
||||
else {
|
||||
resolve(undefined);
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
sqlite.query_set = query_set;
|
||||
/**
|
||||
* for INSERT, UPDATE, DELETE
|
||||
*/
|
||||
async function query_put(connection, query_raw) {
|
||||
const query_transformed = query_transform(query_raw);
|
||||
return (new Promise((resolve, reject) => {
|
||||
connection.handle.run(query_transformed.template, query_transformed.arguments,
|
||||
// must be a classic function due the special use of "this"
|
||||
function (error) {
|
||||
if (error) {
|
||||
reject(error);
|
||||
}
|
||||
else {
|
||||
resolve({
|
||||
"id": this.lastID,
|
||||
"affected": this.changes,
|
||||
});
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
sqlite.query_put = query_put;
|
||||
/**
|
||||
* for SELECT
|
||||
*
|
||||
* @todo rather use handle procedure for rows instead of returning an array
|
||||
*/
|
||||
async function query_get(connection, query_raw) {
|
||||
const query_transformed = query_transform(query_raw);
|
||||
return (new Promise((resolve, reject) => {
|
||||
connection.handle.all(query_transformed.template, query_transformed.arguments, (error, rows) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
}
|
||||
else {
|
||||
resolve(rows);
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
sqlite.query_get = query_get;
|
||||
/**
|
||||
* for SELECT
|
||||
*
|
||||
* @todo rather use handle procedure for rows instead of returning an array
|
||||
*/
|
||||
function query_probe(connection, query_raw, handler) {
|
||||
const query_transformed = query_transform(query_raw);
|
||||
connection.handle.each(query_transformed.template, query_transformed.arguments, function (error, row) {
|
||||
if (error) {
|
||||
// do nothing
|
||||
// log?
|
||||
}
|
||||
else {
|
||||
handler(row);
|
||||
}
|
||||
});
|
||||
}
|
||||
sqlite.query_probe = query_probe;
|
||||
})(sqlite = lib_plankton.sqlite || (lib_plankton.sqlite = {}));
|
||||
})(lib_plankton || (lib_plankton = {}));
|
||||
|
|
|
|||
15
license.txt
15
license.txt
|
|
@ -1,15 +0,0 @@
|
|||
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||
<info@greenscale.de>
|
||||
|
||||
»heimdall« is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
»heimdall« is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with »heimdall«. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
### Eigene Skripte
|
||||
|
||||
Mittels der Prüfungs-Art `script`, kann man selbst definierte Prüf-Funktionen schreiben. Diese Skripte sollen durch exit-Codes das Ergebnis der Prüfung kommunizieren:
|
||||
Mittels den Prüfungs-Art `script`, kann man selbst definierte Prüf-Funktionen schreiben. Diese Skripte sollen durch exit-Codes das Ergebnis der Prüfung kommunizieren:
|
||||
|
||||
- `0`: alles prima
|
||||
- `1`: Warnung
|
||||
|
|
@ -42,9 +42,9 @@ Die Konfiguration erfolgt in Form einer JSON-Datei gemäß des Schemas `doc/hmdl
|
|||
|
||||
### Manuell
|
||||
|
||||
- für einen einzelnen Ablauf: `build/heimdall examples/test.hdml.json` ausführen
|
||||
- für ein einzelnen Ablauf: `build/heimdall -c examples/test.hdml.json` ausführen
|
||||
- zum allgemeinenen Rumspielen:
|
||||
- `watch -n 10 build/heimdall examples/test.hdml.json`
|
||||
- `watch -n 10 build/heimdall -c examples/test.hdml.json`
|
||||
- `touch /tmp/test` ausführen
|
||||
- Werte in `examples/test.hdml.json` ändern
|
||||
|
||||
|
|
|
|||
|
|
@ -1,326 +0,0 @@
|
|||
/*
|
||||
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||
<info@greenscale.de>
|
||||
|
||||
»heimdall« is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
»heimdall« is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with »heimdall«. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
async function main(
|
||||
) : Promise<void>
|
||||
{
|
||||
await _heimdall.init();
|
||||
|
||||
// consts
|
||||
const version : string = "0.9";
|
||||
|
||||
// args
|
||||
const arg_handler : lib_plankton.args.class_handler = new lib_plankton.args.class_handler(
|
||||
{
|
||||
"order_path": new lib_plankton.args.class_argument(
|
||||
{
|
||||
"name": "order_path",
|
||||
"type": lib_plankton.args.enum_type.string,
|
||||
"kind": lib_plankton.args.enum_kind.positional,
|
||||
"mode": lib_plankton.args.enum_mode.replace,
|
||||
"default": "monitoring.hmdl.json",
|
||||
"parameters": {
|
||||
"index": 0,
|
||||
},
|
||||
"info": lib_plankton.translate.get("help.args.order_path"),
|
||||
}
|
||||
),
|
||||
"show_help": new lib_plankton.args.class_argument(
|
||||
{
|
||||
"name": "help",
|
||||
"type": lib_plankton.args.enum_type.boolean,
|
||||
"kind": lib_plankton.args.enum_kind.volatile,
|
||||
"mode": lib_plankton.args.enum_mode.replace,
|
||||
"default": false,
|
||||
"parameters": {
|
||||
"indicators_long": ["help"],
|
||||
"indicators_short": ["h"],
|
||||
},
|
||||
"info": lib_plankton.translate.get("help.args.show_help"),
|
||||
}
|
||||
),
|
||||
"show_version": new lib_plankton.args.class_argument(
|
||||
{
|
||||
"name": "version",
|
||||
"type": lib_plankton.args.enum_type.boolean,
|
||||
"kind": lib_plankton.args.enum_kind.volatile,
|
||||
"mode": lib_plankton.args.enum_mode.replace,
|
||||
"default": false,
|
||||
"parameters": {
|
||||
"indicators_long": ["version"],
|
||||
"indicators_short": ["r"],
|
||||
},
|
||||
"info": lib_plankton.translate.get("help.args.show_version"),
|
||||
}
|
||||
),
|
||||
"show_schema": new lib_plankton.args.class_argument(
|
||||
{
|
||||
"name": "schema",
|
||||
"type": lib_plankton.args.enum_type.boolean,
|
||||
"kind": lib_plankton.args.enum_kind.volatile,
|
||||
"mode": lib_plankton.args.enum_mode.replace,
|
||||
"default": false,
|
||||
"parameters": {
|
||||
"indicators_long": ["schema"],
|
||||
"indicators_short": ["s"],
|
||||
},
|
||||
"info": lib_plankton.translate.get("help.args.show_schema"),
|
||||
}
|
||||
),
|
||||
"expose_full_order": new lib_plankton.args.class_argument(
|
||||
{
|
||||
"name": "expose_full_order",
|
||||
"type": lib_plankton.args.enum_type.boolean,
|
||||
"kind": lib_plankton.args.enum_kind.volatile,
|
||||
"mode": lib_plankton.args.enum_mode.replace,
|
||||
"default": false,
|
||||
"parameters": {
|
||||
"indicators_long": ["expose-full-order"],
|
||||
"indicators_short": ["e"],
|
||||
},
|
||||
"info": lib_plankton.translate.get("help.args.expose_full_order"),
|
||||
}
|
||||
),
|
||||
"erase_state": new lib_plankton.args.class_argument(
|
||||
{
|
||||
"name": "erase_state",
|
||||
"type": lib_plankton.args.enum_type.boolean,
|
||||
"kind": lib_plankton.args.enum_kind.volatile,
|
||||
"mode": lib_plankton.args.enum_mode.replace,
|
||||
"default": false,
|
||||
"parameters": {
|
||||
"indicators_long": ["erase-state"],
|
||||
"indicators_short": ["x"],
|
||||
},
|
||||
"info": lib_plankton.translate.get("help.args.erase_state"),
|
||||
}
|
||||
),
|
||||
"database_path": new lib_plankton.args.class_argument(
|
||||
{
|
||||
"name": "database_path",
|
||||
"type": lib_plankton.args.enum_type.string,
|
||||
"kind": lib_plankton.args.enum_kind.volatile,
|
||||
"mode": lib_plankton.args.enum_mode.replace,
|
||||
"default": null,
|
||||
"parameters": {
|
||||
"indicators_long": ["database-path"],
|
||||
"indicators_short": ["d"],
|
||||
},
|
||||
"info": lib_plankton.translate.get("help.args.database_path"),
|
||||
}
|
||||
),
|
||||
"mutex_path": new lib_plankton.args.class_argument(
|
||||
{
|
||||
"name": "mutex_path",
|
||||
"type": lib_plankton.args.enum_type.string,
|
||||
"kind": lib_plankton.args.enum_kind.volatile,
|
||||
"mode": lib_plankton.args.enum_mode.replace,
|
||||
"default": "/tmp/heimdall.lock",
|
||||
"parameters": {
|
||||
"indicators_long": ["mutex-path"],
|
||||
"indicators_short": ["m"],
|
||||
},
|
||||
"info": lib_plankton.translate.get("help.args.mutex_path"),
|
||||
}
|
||||
),
|
||||
"send_ok_notifications": new lib_plankton.args.class_argument(
|
||||
{
|
||||
"name": "send_ok_notifications",
|
||||
"type": lib_plankton.args.enum_type.boolean,
|
||||
"kind": lib_plankton.args.enum_kind.volatile,
|
||||
"mode": lib_plankton.args.enum_mode.replace,
|
||||
"default": false,
|
||||
"parameters": {
|
||||
"indicators_long": ["send-ok-notifications"],
|
||||
"indicators_short": ["y"],
|
||||
},
|
||||
"info": lib_plankton.translate.get(
|
||||
"help.args.send_ok_notifications",
|
||||
{
|
||||
"condition_name": lib_plankton.translate.get("conditions.ok"),
|
||||
}
|
||||
),
|
||||
}
|
||||
),
|
||||
"language": new lib_plankton.args.class_argument(
|
||||
{
|
||||
"name": "language",
|
||||
"type": lib_plankton.args.enum_type.string,
|
||||
"kind": lib_plankton.args.enum_kind.volatile,
|
||||
"mode": lib_plankton.args.enum_mode.replace,
|
||||
"default": null,
|
||||
"parameters": {
|
||||
"indicators_long": ["language"],
|
||||
"indicators_short": ["l"],
|
||||
},
|
||||
"info": lib_plankton.translate.get("help.args.language"),
|
||||
}
|
||||
),
|
||||
"time_to_live": new lib_plankton.args.class_argument(
|
||||
{
|
||||
"name": "time_to_live",
|
||||
"type": lib_plankton.args.enum_type.float,
|
||||
"kind": lib_plankton.args.enum_kind.volatile,
|
||||
"mode": lib_plankton.args.enum_mode.replace,
|
||||
"default": (60 * 60 * 24 * 7),
|
||||
"parameters": {
|
||||
"indicators_long": ["time-to-live"],
|
||||
"indicators_short": ["t"],
|
||||
},
|
||||
"info": lib_plankton.translate.get("help.args.time_to_live"),
|
||||
}
|
||||
),
|
||||
"working_directory": new lib_plankton.args.class_argument(
|
||||
{
|
||||
"name": "working_directory",
|
||||
"type": lib_plankton.args.enum_type.string,
|
||||
"kind": lib_plankton.args.enum_kind.volatile,
|
||||
"mode": lib_plankton.args.enum_mode.replace,
|
||||
"default": ".",
|
||||
"parameters": {
|
||||
"indicators_long": ["working-directory"],
|
||||
"indicators_short": ["w"],
|
||||
},
|
||||
"info": lib_plankton.translate.get("help.args.working_directory"),
|
||||
}
|
||||
),
|
||||
"verbosity": new lib_plankton.args.class_argument(
|
||||
{
|
||||
"name": "verbosity",
|
||||
"type": lib_plankton.args.enum_type.integer,
|
||||
"kind": lib_plankton.args.enum_kind.volatile,
|
||||
"mode": lib_plankton.args.enum_mode.replace,
|
||||
"default": 1,
|
||||
"parameters": {
|
||||
"indicators_long": ["verbosity"],
|
||||
"indicators_short": ["v"],
|
||||
},
|
||||
"info": lib_plankton.translate.get("help.args.verbosity"),
|
||||
}
|
||||
),
|
||||
}
|
||||
);
|
||||
const args : Record<string, any> = arg_handler.read(
|
||||
lib_plankton.args.enum_environment.cli,
|
||||
process.argv.slice(2).join(" ")
|
||||
);
|
||||
|
||||
// setup logging
|
||||
lib_plankton.log.conf_push(
|
||||
[
|
||||
new lib_plankton.log.class_channel_minlevel(
|
||||
new lib_plankton.log.class_channel_stdout(),
|
||||
[
|
||||
lib_plankton.log.enum_level.debug,
|
||||
lib_plankton.log.enum_level.info,
|
||||
lib_plankton.log.enum_level.notice,
|
||||
lib_plankton.log.enum_level.warning,
|
||||
lib_plankton.log.enum_level.error,
|
||||
][Math.min(4, args["verbosity"])]
|
||||
),
|
||||
]
|
||||
);
|
||||
|
||||
// exec
|
||||
if (args.show_help) {
|
||||
process.stdout.write(
|
||||
arg_handler.generate_help(
|
||||
{
|
||||
"programname": "heimdall",
|
||||
"description": lib_plankton.translate.get("help.title"),
|
||||
"executable": "heimdall",
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
else {
|
||||
if (args["show_version"]) {
|
||||
process.stdout.write(version + "\n");
|
||||
}
|
||||
else {
|
||||
if (args["show_schema"]) {
|
||||
process.stdout.write(
|
||||
lib_plankton.json.encode(
|
||||
_heimdall.order.schema_root(
|
||||
),
|
||||
true
|
||||
)
|
||||
+
|
||||
"\n"
|
||||
)
|
||||
}
|
||||
else {
|
||||
const order_path : string = (
|
||||
args["order_path"].startsWith("/")
|
||||
? args["order_path"]
|
||||
: (args["working_directory"] + "/" + args["order_path"])
|
||||
);
|
||||
const nm_path = require("path");
|
||||
const nm_fs = require("fs");
|
||||
if (! nm_fs.existsSync(order_path)) {
|
||||
lib_plankton.log.error(
|
||||
lib_plankton.translate.get("misc.order_file_not_found"),
|
||||
{
|
||||
"path": args["order_path"],
|
||||
}
|
||||
);
|
||||
}
|
||||
else {
|
||||
const order : _heimdall.type_order = await _heimdall.order.load(
|
||||
nm_path.normalize(order_path)
|
||||
);
|
||||
if (args["expose_full_order"]) {
|
||||
process.stdout.write(lib_plankton.json.encode(order, true) + "\n");
|
||||
}
|
||||
else {
|
||||
await _heimdall.master.wrap_mutex(
|
||||
args["mutex_path"],
|
||||
() => _heimdall.master.wrap_database(
|
||||
args["database_path"],
|
||||
args["order_path"],
|
||||
async () => {
|
||||
await _heimdall.master.clean(
|
||||
{
|
||||
"time_to_live": args["time_to_live"],
|
||||
"erase_state": args["erase_state"],
|
||||
}
|
||||
);
|
||||
await _heimdall.master.run(
|
||||
order,
|
||||
{
|
||||
"send_ok_notifications": args["send_ok_notifications"],
|
||||
}
|
||||
);
|
||||
}
|
||||
)
|
||||
)
|
||||
.catch(
|
||||
() => {process.exit(2);}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
main();
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||
<info@greenscale.de>
|
||||
|
||||
»heimdall« is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
»heimdall« is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with »heimdall«. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
namespace _heimdall
|
||||
{
|
||||
|
||||
/**
|
||||
*/
|
||||
export async function init(
|
||||
) : Promise<void>
|
||||
{
|
||||
const workdir : string = __dirname;
|
||||
|
||||
// translation
|
||||
{
|
||||
const language_order : Array<string> = ["de", "en"];
|
||||
await lib_plankton.translate.initialize_promise(
|
||||
{
|
||||
"verbosity": 1,
|
||||
"order": language_order,
|
||||
"packages": await Promise.all(
|
||||
[
|
||||
{"identifier": "de", "path": (workdir + "/localization/de.json")},
|
||||
{"identifier": "en", "path": (workdir + "/localization/en.json")},
|
||||
]
|
||||
.map(
|
||||
(entry) => (
|
||||
lib_plankton.file.read(entry.path)
|
||||
.then(content => Promise.resolve(JSON.parse(content)))
|
||||
.then(tree => Promise.resolve({"meta": {"identifier": entry.identifier}, "tree": tree}))
|
||||
)
|
||||
)
|
||||
),
|
||||
}
|
||||
);
|
||||
const env_language : (null | string) = _heimdall.helpers.misc.get_env_language();
|
||||
if (
|
||||
! (
|
||||
(env_language !== null)
|
||||
&&
|
||||
language_order.includes(env_language)
|
||||
)
|
||||
) {
|
||||
// do nothing
|
||||
}
|
||||
else {
|
||||
lib_plankton.translate.promote(env_language);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -16,7 +16,6 @@
|
|||
"help.args.show_schema": "nur das hmdl-JSON-Schema zur Standard-Ausgabe schreiben und beenden",
|
||||
"help.args.expose_full_order": "nur den Pfad zur Datenbank-Datei zur Standard-Ausgabe schreiben und beenden (nützlich für Fehlersuche)",
|
||||
"help.args.show_version": "nur die Version zur Standard-Ausgabe schreiben und beenden",
|
||||
"help.args.working_directory": "Verzichnis in welchem die Auftrags-Datei zu finden ist, falls mit relativem Pfad angegeben",
|
||||
"help.args.verbosity": "Schwellwert für Log-Ausgaben",
|
||||
"checks.script.execution_failed": "Ausführung gescheitert",
|
||||
"checks.script.invalid_return_code": "ungültiger Rückgabe-Code",
|
||||
|
|
@ -38,5 +37,5 @@
|
|||
"misc.check_procedure_failed": "Prüfungs-Prozedur fehlgeschlagen",
|
||||
"misc.still_running": "läuft bereits/noch",
|
||||
"misc.cleanup_info": "{{count}} alte Ergebnis-Datensätze gelöscht",
|
||||
"misc.order_file_not_found": "Auftrags-Datei nicht gefunden"
|
||||
"misc.order_file_not_found": "Auftrags-Datei nicht gefunden: {{path}}"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
"help.args.show_schema": "print the hmdl JSON schema to stdout and exit",
|
||||
"help.args.expose_full_order": "only print the extended order to stdout and exit (useful for debugging)",
|
||||
"help.args.show_version": "only print the version to stdout and exit",
|
||||
"help.args.working_directory": "directory to loof for the order file, in case its path is specified relatively",
|
||||
"help.args.verbosity": "threshold for log outputs",
|
||||
"checks.script.execution_failed": "execution failed",
|
||||
"checks.script.invalid_return_code": "invalid return code",
|
||||
|
|
@ -38,5 +37,5 @@
|
|||
"misc.check_procedure_failed": "check procedure failed",
|
||||
"misc.still_running": "already/still running",
|
||||
"misc.cleanup_info": "removed {{count}} old result entries",
|
||||
"misc.order_file_not_found": "order file not found"
|
||||
"misc.order_file_not_found": "order file not found: {{path}}"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +1,3 @@
|
|||
/*
|
||||
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||
<info@greenscale.de>
|
||||
|
||||
»heimdall« is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
»heimdall« is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with »heimdall«. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @todo outsource
|
||||
*/
|
||||
12
source/logic/check_kinds/_abstract.ts
Normal file
12
source/logic/check_kinds/_abstract.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
namespace _heimdall.check_kinds
|
||||
{
|
||||
|
||||
/**
|
||||
*/
|
||||
export type type_check_kind = {
|
||||
parameters_schema : (() => _heimdall.helpers.json_schema.type_schema);
|
||||
normalize_order_node : ((node : any) => any);
|
||||
run : (parameters) => Promise<_heimdall.type_result>;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
/*
|
||||
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||
<info@greenscale.de>
|
||||
|
||||
»heimdall« is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
»heimdall« is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with »heimdall«. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
namespace _heimdall.check_kinds
|
||||
{
|
||||
|
||||
/**
|
||||
*/
|
||||
export type type_check_kind = {
|
||||
parameters_schema : (
|
||||
()
|
||||
=>
|
||||
_heimdall.helpers.json_schema.type_schema
|
||||
);
|
||||
normalize_order_node : (
|
||||
(node : any)
|
||||
=>
|
||||
any
|
||||
);
|
||||
run : (
|
||||
(parameters)
|
||||
=>
|
||||
Promise<_heimdall.type_result>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
var _implementations : Record<string, type_check_kind> = {};
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
export function register_implementation(
|
||||
name : string,
|
||||
check_kind : type_check_kind
|
||||
) : void
|
||||
{
|
||||
_implementations[name] = check_kind;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
export function get_implementation(
|
||||
name : string
|
||||
) : type_check_kind
|
||||
{
|
||||
return _implementations[name];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
export function get_implementations(
|
||||
) : Record<string, type_check_kind>
|
||||
{
|
||||
return _implementations;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,22 +1,3 @@
|
|||
/*
|
||||
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||
<info@greenscale.de>
|
||||
|
||||
»heimdall« is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
»heimdall« is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with »heimdall«. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
namespace _heimdall.check_kinds.file_state
|
||||
{
|
||||
|
||||
|
|
@ -385,13 +366,14 @@ namespace _heimdall.check_kinds.file_state
|
|||
|
||||
/**
|
||||
*/
|
||||
register_implementation(
|
||||
"file_state",
|
||||
{
|
||||
export function check_kind_implementation(
|
||||
) : type_check_kind
|
||||
{
|
||||
return {
|
||||
"parameters_schema": parameters_schema,
|
||||
"normalize_order_node": normalize_order_node,
|
||||
"run": run,
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +1,3 @@
|
|||
/*
|
||||
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||
<info@greenscale.de>
|
||||
|
||||
»heimdall« is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
»heimdall« is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with »heimdall«. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
namespace _heimdall.check_kinds.generic_remote
|
||||
{
|
||||
|
||||
|
|
@ -189,23 +170,19 @@ namespace _heimdall.check_kinds.generic_remote
|
|||
outer_command_parts.push(lib_plankton.string.coin("{{host}}", {"host": parameters["host"]}));
|
||||
}
|
||||
if (parameters["ssh_port"] !== null) {
|
||||
outer_command_parts.push(lib_plankton.string.coin("-p", {}));
|
||||
outer_command_parts.push(lib_plankton.string.coin("{{port}}", {"port": parameters["ssh_port"].toFixed(0)}));
|
||||
outer_command_parts.push(lib_plankton.string.coin("-p {{port}}", {"port": parameters["ssh_port"].toFixed(0)}));
|
||||
}
|
||||
if (parameters["ssh_user"] !== null) {
|
||||
outer_command_parts.push(lib_plankton.string.coin("-l", {}));
|
||||
outer_command_parts.push(lib_plankton.string.coin("{{user}}", {"user": parameters["ssh_user"]}));
|
||||
outer_command_parts.push(lib_plankton.string.coin("-l {{user}}", {"user": parameters["ssh_user"]}));
|
||||
}
|
||||
if (parameters["ssh_key"] !== null) {
|
||||
outer_command_parts.push(lib_plankton.string.coin("-i", {}));
|
||||
outer_command_parts.push(lib_plankton.string.coin("{{key}}", {"key": parameters["ssh_key"]}));
|
||||
outer_command_parts.push(lib_plankton.string.coin("-i {{key}}", {"key": parameters["ssh_key"]}));
|
||||
}
|
||||
if (true) {
|
||||
outer_command_parts.push(lib_plankton.string.coin("-o", {}));
|
||||
outer_command_parts.push(lib_plankton.string.coin("BatchMode=yes", {}));
|
||||
outer_command_parts.push(lib_plankton.string.coin("-o BatchMode=yes", {}));
|
||||
}
|
||||
if (true) {
|
||||
outer_command_parts.push(lib_plankton.string.coin("{{inner_command}}", {"inner_command": inner_command}));
|
||||
outer_command_parts.push(lib_plankton.string.coin("'{{inner_command}}'", {"inner_command": inner_command}));
|
||||
}
|
||||
const outer_command : string = outer_command_parts.join(" ");
|
||||
|
||||
|
|
@ -218,7 +195,6 @@ namespace _heimdall.check_kinds.generic_remote
|
|||
return {
|
||||
"condition": _heimdall.enum_condition.unknown,
|
||||
"info": {
|
||||
"command": outer_command,
|
||||
"error": shell_exec_result.stderr,
|
||||
}
|
||||
};
|
||||
|
|
@ -266,13 +242,14 @@ namespace _heimdall.check_kinds.generic_remote
|
|||
|
||||
/**
|
||||
*/
|
||||
register_implementation(
|
||||
"generic_remote",
|
||||
{
|
||||
export function check_kind_implementation(
|
||||
) : type_check_kind
|
||||
{
|
||||
return {
|
||||
"parameters_schema": parameters_schema,
|
||||
"normalize_order_node": normalize_order_node,
|
||||
"run": run,
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +1,3 @@
|
|||
/*
|
||||
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||
<info@greenscale.de>
|
||||
|
||||
»heimdall« is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
»heimdall« is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with »heimdall«. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
namespace _heimdall.check_kinds.http_request
|
||||
{
|
||||
|
||||
|
|
@ -259,13 +240,7 @@ namespace _heimdall.check_kinds.http_request
|
|||
"info": {
|
||||
"request": parameters.request,
|
||||
"faults": [
|
||||
lib_plankton.translate.get(
|
||||
"checks.http_request.request_failed",
|
||||
{
|
||||
// "reason": error.toString(),
|
||||
"reason": JSON.stringify(error),
|
||||
}
|
||||
),
|
||||
lib_plankton.translate.get("checks.http_request.request_failed", {"reason": error.toString()}),
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -338,7 +313,7 @@ namespace _heimdall.check_kinds.http_request
|
|||
"checks.http_request.header_value_mismatch",
|
||||
{
|
||||
"key": header_key,
|
||||
"value_actual": http_response.headers[header_key.toLowerCase()],
|
||||
"value_actual": http_response.headers[header_key],
|
||||
"value_expected": header_value,
|
||||
}
|
||||
)
|
||||
|
|
@ -405,13 +380,14 @@ namespace _heimdall.check_kinds.http_request
|
|||
|
||||
/**
|
||||
*/
|
||||
register_implementation(
|
||||
"http_request",
|
||||
{
|
||||
export function check_kind_implementation(
|
||||
) : type_check_kind
|
||||
{
|
||||
return {
|
||||
"parameters_schema": parameters_schema,
|
||||
"normalize_order_node": normalize_order_node,
|
||||
"run": run,
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +1,3 @@
|
|||
/*
|
||||
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||
<info@greenscale.de>
|
||||
|
||||
»heimdall« is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
»heimdall« is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with »heimdall«. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
namespace _heimdall.check_kinds.script
|
||||
{
|
||||
|
||||
|
|
@ -137,13 +118,14 @@ namespace _heimdall.check_kinds.script
|
|||
|
||||
/**
|
||||
*/
|
||||
register_implementation(
|
||||
"script",
|
||||
{
|
||||
export function check_kind_implementation(
|
||||
) : type_check_kind
|
||||
{
|
||||
return {
|
||||
"parameters_schema": parameters_schema,
|
||||
"normalize_order_node": normalize_order_node,
|
||||
"run": run,
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +1,3 @@
|
|||
/*
|
||||
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||
<info@greenscale.de>
|
||||
|
||||
»heimdall« is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
»heimdall« is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with »heimdall«. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
namespace _heimdall.check_kinds.tls_certificate
|
||||
{
|
||||
|
||||
|
|
@ -256,13 +237,14 @@ namespace _heimdall.check_kinds.tls_certificate
|
|||
|
||||
/**
|
||||
*/
|
||||
register_implementation(
|
||||
"tls_certificate",
|
||||
{
|
||||
export function check_kind_implementation(
|
||||
) : type_check_kind
|
||||
{
|
||||
return {
|
||||
"parameters_schema": parameters_schema,
|
||||
"normalize_order_node": normalize_order_node,
|
||||
"run": run,
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +1,3 @@
|
|||
/*
|
||||
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||
<info@greenscale.de>
|
||||
|
||||
»heimdall« is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
»heimdall« is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with »heimdall«. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
namespace _heimdall.helpers.json_schema
|
||||
{
|
||||
|
||||
|
|
@ -1,41 +1,6 @@
|
|||
/*
|
||||
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||
<info@greenscale.de>
|
||||
|
||||
»heimdall« is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
»heimdall« is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with »heimdall«. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
namespace _heimdall.helpers.misc
|
||||
{
|
||||
|
||||
/**
|
||||
*/
|
||||
export function get_env_language(
|
||||
) : (null | string)
|
||||
{
|
||||
const env_lang : (undefined | string) = process.env["LANG"];
|
||||
if (env_lang === undefined) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
const locale : string = env_lang.split(".")[0];
|
||||
const language : string = locale.split("_")[0];
|
||||
return language;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
export function format_bytes(
|
||||
176
source/logic/helpers/sqlite.ts
Normal file
176
source/logic/helpers/sqlite.ts
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
namespace _heimdall.helpers.sqlite
|
||||
{
|
||||
|
||||
/**
|
||||
*/
|
||||
export type type_query_raw = {
|
||||
template : string;
|
||||
arguments : Record<string, any>;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
type type_query_transformed = {
|
||||
template : string;
|
||||
arguments : Record<string, any>;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
function query_transform(
|
||||
query_raw : type_query_raw
|
||||
) : type_query_transformed
|
||||
{
|
||||
return {
|
||||
"template": query_raw.template,
|
||||
"arguments": lib_plankton.call.convey(
|
||||
query_raw.arguments,
|
||||
[
|
||||
x => Object.entries(x),
|
||||
x => (
|
||||
x.map(
|
||||
([key, value]) => ([
|
||||
(":" + key),
|
||||
value
|
||||
])
|
||||
)
|
||||
),
|
||||
x => Object.fromEntries(x),
|
||||
]
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
function execute(
|
||||
database_path : string,
|
||||
action : ((handle) => Promise<void>),
|
||||
) : Promise<void>
|
||||
{
|
||||
return (
|
||||
new Promise<void>(
|
||||
async (resolve, reject) => {
|
||||
const nm_sqlite3 = require("sqlite3");
|
||||
const handle = new nm_sqlite3.Database(database_path);
|
||||
try {
|
||||
await action(handle);
|
||||
handle.close();
|
||||
resolve(undefined);
|
||||
}
|
||||
catch (error) {
|
||||
handle.close();
|
||||
reject(error);
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* for CREATE TABLE, DROP TABLE, etc.
|
||||
*/
|
||||
export async function query_set(
|
||||
database_path : string,
|
||||
query_raw : type_query_raw
|
||||
) : Promise<any>
|
||||
{
|
||||
const query_transformed : type_query_transformed = query_transform(query_raw);
|
||||
await execute(
|
||||
database_path,
|
||||
(handle) => new Promise<void>(
|
||||
(resolve, reject) => {
|
||||
handle.run(
|
||||
query_transformed.template,
|
||||
query_transformed.arguments,
|
||||
(error) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
}
|
||||
else {
|
||||
resolve(undefined);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* for INSERT, UPDATE, DELETE
|
||||
*/
|
||||
export async function query_put(
|
||||
database_path : string,
|
||||
query_raw : type_query_raw
|
||||
) : Promise<{id : (null | int); affected : (null | int);}>
|
||||
{
|
||||
let result : {id : (null | int); affected : (null | int);};
|
||||
const query_transformed : type_query_transformed = query_transform(query_raw);
|
||||
await execute(
|
||||
database_path,
|
||||
(handle) => new Promise<void>(
|
||||
(resolve, reject) => {
|
||||
handle.run(
|
||||
query_transformed.template,
|
||||
query_transformed.arguments,
|
||||
function (error) {
|
||||
if (error) {
|
||||
reject(error);
|
||||
}
|
||||
else {
|
||||
result = {
|
||||
"id": this.lastID,
|
||||
"affected": this.changes,
|
||||
};
|
||||
resolve(undefined);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* for SELECT
|
||||
*/
|
||||
export async function query_get(
|
||||
database_path : string,
|
||||
query_raw : type_query_raw
|
||||
) : Promise<Array<Array<any>>>
|
||||
{
|
||||
const query_transformed : type_query_transformed = query_transform(query_raw);
|
||||
let rows : Array<Array<any>> = [];
|
||||
await execute(
|
||||
database_path,
|
||||
(handle) => new Promise<void>(
|
||||
(resolve, reject) => {
|
||||
handle.all(
|
||||
query_transformed.template,
|
||||
query_transformed.arguments,
|
||||
(error, row) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
}
|
||||
else {
|
||||
rows.push(row);
|
||||
resolve(undefined);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
return rows;
|
||||
}
|
||||
|
||||
}
|
||||
569
source/logic/main.ts
Normal file
569
source/logic/main.ts
Normal file
|
|
@ -0,0 +1,569 @@
|
|||
async function main(
|
||||
) : Promise<void>
|
||||
{
|
||||
// consts
|
||||
const version : string = "0.9";
|
||||
const workdir : string = __dirname;
|
||||
|
||||
// init translations
|
||||
// TODO: use env language
|
||||
await lib_plankton.translate.initialize_promise(
|
||||
{
|
||||
"verbosity": 1,
|
||||
"order": ["de", "en"],
|
||||
"packages": await Promise.all(
|
||||
[
|
||||
{"identifier": "de", "path": (workdir + "/localization/de.json")},
|
||||
{"identifier": "en", "path": (workdir + "/localization/en.json")},
|
||||
]
|
||||
.map(
|
||||
(entry) => (
|
||||
lib_plankton.file.read(entry.path)
|
||||
.then(content => Promise.resolve(JSON.parse(content)))
|
||||
.then(tree => Promise.resolve({"meta": {"identifier": entry.identifier}, "tree": tree}))
|
||||
)
|
||||
)
|
||||
),
|
||||
}
|
||||
);
|
||||
|
||||
// args
|
||||
const arg_handler : lib_plankton.args.class_handler = new lib_plankton.args.class_handler(
|
||||
{
|
||||
"order_path": new lib_plankton.args.class_argument(
|
||||
{
|
||||
"name": "order_path",
|
||||
"type": lib_plankton.args.enum_type.string,
|
||||
"kind": lib_plankton.args.enum_kind.positional,
|
||||
"mode": lib_plankton.args.enum_mode.replace,
|
||||
"default": "monitoring.hmdl.json",
|
||||
"parameters": {
|
||||
"index": 0,
|
||||
},
|
||||
"info": lib_plankton.translate.get("help.args.order_path"),
|
||||
}
|
||||
),
|
||||
"show_help": new lib_plankton.args.class_argument(
|
||||
{
|
||||
"name": "help",
|
||||
"type": lib_plankton.args.enum_type.boolean,
|
||||
"kind": lib_plankton.args.enum_kind.volatile,
|
||||
"mode": lib_plankton.args.enum_mode.replace,
|
||||
"default": false,
|
||||
"parameters": {
|
||||
"indicators_long": ["help"],
|
||||
"indicators_short": ["h"],
|
||||
},
|
||||
"info": lib_plankton.translate.get("help.args.show_help"),
|
||||
}
|
||||
),
|
||||
"show_version": new lib_plankton.args.class_argument(
|
||||
{
|
||||
"name": "version",
|
||||
"type": lib_plankton.args.enum_type.boolean,
|
||||
"kind": lib_plankton.args.enum_kind.volatile,
|
||||
"mode": lib_plankton.args.enum_mode.replace,
|
||||
"default": false,
|
||||
"parameters": {
|
||||
"indicators_long": ["version"],
|
||||
"indicators_short": ["r"],
|
||||
},
|
||||
"info": lib_plankton.translate.get("help.args.show_version"),
|
||||
}
|
||||
),
|
||||
"show_schema": new lib_plankton.args.class_argument(
|
||||
{
|
||||
"name": "schema",
|
||||
"type": lib_plankton.args.enum_type.boolean,
|
||||
"kind": lib_plankton.args.enum_kind.volatile,
|
||||
"mode": lib_plankton.args.enum_mode.replace,
|
||||
"default": false,
|
||||
"parameters": {
|
||||
"indicators_long": ["schema"],
|
||||
"indicators_short": ["s"],
|
||||
},
|
||||
"info": lib_plankton.translate.get("help.args.show_schema"),
|
||||
}
|
||||
),
|
||||
"expose_full_order": new lib_plankton.args.class_argument(
|
||||
{
|
||||
"name": "expose_full_order",
|
||||
"type": lib_plankton.args.enum_type.boolean,
|
||||
"kind": lib_plankton.args.enum_kind.volatile,
|
||||
"mode": lib_plankton.args.enum_mode.replace,
|
||||
"default": false,
|
||||
"parameters": {
|
||||
"indicators_long": ["expose-full-order"],
|
||||
"indicators_short": ["e"],
|
||||
},
|
||||
"info": lib_plankton.translate.get("help.args.expose_full_order"),
|
||||
}
|
||||
),
|
||||
"erase_state": new lib_plankton.args.class_argument(
|
||||
{
|
||||
"name": "erase_state",
|
||||
"type": lib_plankton.args.enum_type.boolean,
|
||||
"kind": lib_plankton.args.enum_kind.volatile,
|
||||
"mode": lib_plankton.args.enum_mode.replace,
|
||||
"default": false,
|
||||
"parameters": {
|
||||
"indicators_long": ["erase-state"],
|
||||
"indicators_short": ["x"],
|
||||
},
|
||||
"info": lib_plankton.translate.get("help.args.erase_state"),
|
||||
}
|
||||
),
|
||||
"database_path": new lib_plankton.args.class_argument(
|
||||
{
|
||||
"name": "database_path",
|
||||
"type": lib_plankton.args.enum_type.string,
|
||||
"kind": lib_plankton.args.enum_kind.volatile,
|
||||
"mode": lib_plankton.args.enum_mode.replace,
|
||||
"default": null,
|
||||
"parameters": {
|
||||
"indicators_long": ["database-path"],
|
||||
"indicators_short": ["d"],
|
||||
},
|
||||
"info": lib_plankton.translate.get("help.args.database_path"),
|
||||
}
|
||||
),
|
||||
"mutex_path": new lib_plankton.args.class_argument(
|
||||
{
|
||||
"name": "mutex_path",
|
||||
"type": lib_plankton.args.enum_type.string,
|
||||
"kind": lib_plankton.args.enum_kind.volatile,
|
||||
"mode": lib_plankton.args.enum_mode.replace,
|
||||
"default": "/tmp/heimdall.lock",
|
||||
"parameters": {
|
||||
"indicators_long": ["mutex-path"],
|
||||
"indicators_short": ["m"],
|
||||
},
|
||||
"info": lib_plankton.translate.get("help.args.mutex_path"),
|
||||
}
|
||||
),
|
||||
"send_ok_notifications": new lib_plankton.args.class_argument(
|
||||
{
|
||||
"name": "send_ok_notifications",
|
||||
"type": lib_plankton.args.enum_type.boolean,
|
||||
"kind": lib_plankton.args.enum_kind.volatile,
|
||||
"mode": lib_plankton.args.enum_mode.replace,
|
||||
"default": false,
|
||||
"parameters": {
|
||||
"indicators_long": ["send-ok-notifications"],
|
||||
"indicators_short": ["y"],
|
||||
},
|
||||
"info": lib_plankton.translate.get(
|
||||
"help.args.send_ok_notifications",
|
||||
{
|
||||
"condition_name": lib_plankton.translate.get("conditions.ok"),
|
||||
}
|
||||
),
|
||||
}
|
||||
),
|
||||
"language": new lib_plankton.args.class_argument(
|
||||
{
|
||||
"name": "language",
|
||||
"type": lib_plankton.args.enum_type.string,
|
||||
"kind": lib_plankton.args.enum_kind.volatile,
|
||||
"mode": lib_plankton.args.enum_mode.replace,
|
||||
"default": null,
|
||||
"parameters": {
|
||||
"indicators_long": ["language"],
|
||||
"indicators_short": ["l"],
|
||||
},
|
||||
"info": lib_plankton.translate.get("help.args.language"),
|
||||
}
|
||||
),
|
||||
"time_to_live": new lib_plankton.args.class_argument(
|
||||
{
|
||||
"name": "time_to_live",
|
||||
"type": lib_plankton.args.enum_type.float,
|
||||
"kind": lib_plankton.args.enum_kind.volatile,
|
||||
"mode": lib_plankton.args.enum_mode.replace,
|
||||
"default": (60 * 60 * 24 * 7),
|
||||
"parameters": {
|
||||
"indicators_long": ["time-to-live"],
|
||||
"indicators_short": ["t"],
|
||||
},
|
||||
"info": lib_plankton.translate.get("help.args.time_to_live"),
|
||||
}
|
||||
),
|
||||
"verbosity": new lib_plankton.args.class_argument(
|
||||
{
|
||||
"name": "verbosity",
|
||||
"type": lib_plankton.args.enum_type.integer,
|
||||
"kind": lib_plankton.args.enum_kind.volatile,
|
||||
"mode": lib_plankton.args.enum_mode.replace,
|
||||
"default": 1,
|
||||
"parameters": {
|
||||
"indicators_long": ["verbosity"],
|
||||
"indicators_short": ["v"],
|
||||
},
|
||||
"info": lib_plankton.translate.get("help.args.verbosity"),
|
||||
}
|
||||
),
|
||||
}
|
||||
);
|
||||
const args : Record<string, any> = arg_handler.read(
|
||||
lib_plankton.args.enum_environment.cli,
|
||||
process.argv.slice(2).join(" ")
|
||||
);
|
||||
|
||||
// setup logging
|
||||
lib_plankton.log.conf_push(
|
||||
[
|
||||
new lib_plankton.log.class_channel_minlevel(
|
||||
new lib_plankton.log.class_channel_stdout(),
|
||||
[
|
||||
lib_plankton.log.enum_level.debug,
|
||||
lib_plankton.log.enum_level.info,
|
||||
lib_plankton.log.enum_level.notice,
|
||||
lib_plankton.log.enum_level.warning,
|
||||
lib_plankton.log.enum_level.error,
|
||||
][Math.min(4, args["verbosity"])]
|
||||
),
|
||||
]
|
||||
);
|
||||
|
||||
// exec
|
||||
if (args.show_help) {
|
||||
process.stdout.write(
|
||||
arg_handler.generate_help(
|
||||
{
|
||||
"programname": "heimdall",
|
||||
"description": lib_plankton.translate.get("help.title"),
|
||||
"executable": "heimdall",
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
else {
|
||||
if (args["show_version"]) {
|
||||
process.stdout.write(version + "\n");
|
||||
}
|
||||
else {
|
||||
const notification_kind_implementations : Record<string, _heimdall.notification_kinds.type_notification_kind> = {
|
||||
"console": _heimdall.notification_kinds.console.notification_kind_implementation(),
|
||||
"email": _heimdall.notification_kinds.email.notification_kind_implementation(),
|
||||
"libnotify": _heimdall.notification_kinds.libnotify.notification_kind_implementation(),
|
||||
};
|
||||
const check_kind_implementations : Record<string, _heimdall.check_kinds.type_check_kind> = {
|
||||
"script": _heimdall.check_kinds.script.check_kind_implementation(),
|
||||
"http_request": _heimdall.check_kinds.http_request.check_kind_implementation(),
|
||||
"file_state": _heimdall.check_kinds.file_state.check_kind_implementation(),
|
||||
"tls_certificate": _heimdall.check_kinds.tls_certificate.check_kind_implementation(),
|
||||
"generic_remote": _heimdall.check_kinds.generic_remote.check_kind_implementation(),
|
||||
};
|
||||
if (args["show_schema"]) {
|
||||
process.stdout.write(
|
||||
lib_plankton.json.encode(
|
||||
_heimdall.order.schema_root(
|
||||
check_kind_implementations,
|
||||
notification_kind_implementations
|
||||
),
|
||||
true
|
||||
)
|
||||
+
|
||||
"\n"
|
||||
)
|
||||
}
|
||||
else {
|
||||
const nm_path = require("path");
|
||||
const nm_fs = require("fs");
|
||||
if (! nm_fs.existsSync(args["order_path"])) {
|
||||
process.stderr.write(
|
||||
lib_plankton.translate.get(
|
||||
"misc.order_file_not_found",
|
||||
{
|
||||
"path": args["order_path"],
|
||||
}
|
||||
)
|
||||
+
|
||||
"\n"
|
||||
);
|
||||
}
|
||||
else {
|
||||
// get order data
|
||||
const order = await _heimdall.order.load(
|
||||
check_kind_implementations,
|
||||
notification_kind_implementations,
|
||||
nm_path.normalize(args["order_path"])
|
||||
);
|
||||
|
||||
if (args["expose_full_order"]) {
|
||||
process.stdout.write(lib_plankton.json.encode(order, true) + "\n");
|
||||
}
|
||||
else {
|
||||
const database_path : string = (
|
||||
(args["database_path"] !== null)
|
||||
? args["database_path"]
|
||||
: nm_path.join(
|
||||
// TODO get path from fs or path module?
|
||||
"/tmp",
|
||||
lib_plankton.string.coin(
|
||||
"monitoring-state-{{id}}.sqlite",
|
||||
{
|
||||
"id": lib_plankton.call.convey(
|
||||
args["order_path"],
|
||||
[
|
||||
nm_path.normalize,
|
||||
// encode(ascii),
|
||||
x => lib_plankton.sha256.get(x),
|
||||
x => x.slice(0, 8),
|
||||
]
|
||||
),
|
||||
}
|
||||
)
|
||||
)
|
||||
);
|
||||
lib_plankton.log.info(
|
||||
lib_plankton.translate.get("misc.state_file_path"),
|
||||
{
|
||||
"database_path": database_path,
|
||||
}
|
||||
);
|
||||
|
||||
// mutex check
|
||||
if (nm_fs.existsSync(args["mutex_path"])) {
|
||||
lib_plankton.log.error(
|
||||
lib_plankton.translate.get("misc.still_running"),
|
||||
{
|
||||
"mutex_path": args["mutex_path"],
|
||||
}
|
||||
);
|
||||
process.exit(2);
|
||||
}
|
||||
else {
|
||||
await _heimdall.state_repository.setup(database_path);
|
||||
const clean_count : int = await _heimdall.state_repository.clean(
|
||||
database_path,
|
||||
args["time_to_live"],
|
||||
args["erase_state"]
|
||||
);
|
||||
|
||||
// create mutex file
|
||||
await lib_plankton.file.write(args["mutex_path"], "");
|
||||
|
||||
for await (const check of order.checks) {
|
||||
if (! check.active) {
|
||||
// do nothing
|
||||
}
|
||||
else {
|
||||
let old_item_state : (null | _heimdall.type_item_state);
|
||||
|
||||
const last_notification_timestamp : (null | int) = await _heimdall.state_repository.get_last_notification_timestamp(
|
||||
database_path,
|
||||
check.name
|
||||
);
|
||||
|
||||
const rows : Array<
|
||||
{
|
||||
timestamp : int;
|
||||
condition : _heimdall.enum_condition;
|
||||
notification_sent : boolean;
|
||||
}
|
||||
> = await _heimdall.state_repository.probe(
|
||||
database_path,
|
||||
check.name,
|
||||
(check.threshold + 1),
|
||||
);
|
||||
if (rows.length <= 0) {
|
||||
old_item_state = null;
|
||||
}
|
||||
else {
|
||||
let count : int = 1;
|
||||
rows.slice(1).some(
|
||||
(row) => {
|
||||
if (row.condition === rows[0].condition) {
|
||||
count += 1;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
);
|
||||
if (count > check.threshold) {
|
||||
count = null;
|
||||
}
|
||||
else {
|
||||
// do nothing
|
||||
}
|
||||
old_item_state = {
|
||||
"timestamp": rows[0].timestamp,
|
||||
"condition": rows[0].condition,
|
||||
"count": count,
|
||||
"last_notification_timestamp": last_notification_timestamp,
|
||||
}
|
||||
|
||||
const timestamp : int = _heimdall.get_current_timestamp();
|
||||
const due : boolean = (
|
||||
(old_item_state === null)
|
||||
||
|
||||
(old_item_state.condition !== _heimdall.enum_condition.ok)
|
||||
||
|
||||
((timestamp - old_item_state.timestamp) >= check.schedule.regular_interval)
|
||||
||
|
||||
(
|
||||
(! (old_item_state.count === null))
|
||||
&&
|
||||
((timestamp - old_item_state.timestamp) >= check.schedule.attentive_interval)
|
||||
)
|
||||
);
|
||||
if (! due) {
|
||||
// do nothing
|
||||
}
|
||||
else {
|
||||
process.stderr.write(
|
||||
lib_plankton.string.coin(
|
||||
"-- {{check_name}}\n",
|
||||
{
|
||||
"check_name": check.name,
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
// execute check and set new state
|
||||
let result;
|
||||
try {
|
||||
result = await check_kind_implementations[check.kind].run(check.parameters);
|
||||
}
|
||||
catch (error) {
|
||||
result = {
|
||||
"condition": _heimdall.enum_condition.unknown,
|
||||
"info": {
|
||||
"cause": lib_plankton.translate.get("misc.check_procedure_failed"),
|
||||
"error": error.toString(),
|
||||
},
|
||||
}
|
||||
}
|
||||
const count : (null | int) = (
|
||||
(
|
||||
(old_item_state === null)
|
||||
||
|
||||
(old_item_state.condition !== result.condition)
|
||||
)
|
||||
? 1
|
||||
: (
|
||||
(
|
||||
(! (old_item_state.count === null))
|
||||
&&
|
||||
((old_item_state.count + 1) <= check.threshold)
|
||||
)
|
||||
? (old_item_state.count + 1)
|
||||
: null
|
||||
)
|
||||
)
|
||||
const shall_send_notification : boolean = (
|
||||
(
|
||||
(
|
||||
(! (count === null))
|
||||
&&
|
||||
(count === check.threshold)
|
||||
)
|
||||
||
|
||||
(
|
||||
(count === null)
|
||||
&&
|
||||
check.annoy
|
||||
)
|
||||
||
|
||||
(
|
||||
(count === null)
|
||||
&&
|
||||
(
|
||||
(! (old_item_state === null))
|
||||
&&
|
||||
(! (old_item_state.last_notification_timestamp === null))
|
||||
&&
|
||||
(! (check.schedule.reminding_interval === null))
|
||||
&&
|
||||
(
|
||||
(timestamp - old_item_state.last_notification_timestamp)
|
||||
>=
|
||||
check.schedule.reminding_interval
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
&&
|
||||
(
|
||||
(result.condition !== _heimdall.enum_condition.ok)
|
||||
||
|
||||
args["send_ok_notifications"]
|
||||
)
|
||||
)
|
||||
const new_item_state : _heimdall.type_item_state = {
|
||||
"timestamp": timestamp,
|
||||
"condition": result.condition,
|
||||
"count": count,
|
||||
"last_notification_timestamp": (
|
||||
shall_send_notification
|
||||
? timestamp
|
||||
: (
|
||||
(old_item_state === null)
|
||||
? null
|
||||
: old_item_state.last_notification_timestamp
|
||||
)
|
||||
),
|
||||
}
|
||||
await _heimdall.state_repository.feed(
|
||||
database_path,
|
||||
check.name,
|
||||
timestamp,
|
||||
result.condition,
|
||||
shall_send_notification,
|
||||
result.info
|
||||
);
|
||||
|
||||
// send notifications
|
||||
if (! shall_send_notification) {
|
||||
// do nothing
|
||||
}
|
||||
else {
|
||||
check.notifications.forEach(
|
||||
notification => {
|
||||
notification_kind_implementations[notification.kind].notify(
|
||||
notification.parameters,
|
||||
check.name,
|
||||
check,
|
||||
new_item_state,
|
||||
Object.assign(
|
||||
(
|
||||
(check.custom === null)
|
||||
? {}
|
||||
: {"custom": check.custom}
|
||||
),
|
||||
result.info
|
||||
)
|
||||
)
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// drop mutex file
|
||||
await (
|
||||
new Promise<void>(
|
||||
(resolve, reject) => {
|
||||
nm_fs.unlink(
|
||||
args["mutex_path"],
|
||||
() => {
|
||||
resolve(undefined);
|
||||
}
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
|
|
@ -1,389 +0,0 @@
|
|||
/*
|
||||
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||
<info@greenscale.de>
|
||||
|
||||
»heimdall« is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
»heimdall« is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with »heimdall«. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
namespace _heimdall.master
|
||||
{
|
||||
|
||||
/**
|
||||
* @todo automated tests
|
||||
*/
|
||||
export function determine_due(
|
||||
check : _heimdall.type_check,
|
||||
old_item_state : (null | _heimdall.type_item_state),
|
||||
options : {
|
||||
timestamp ?: int;
|
||||
} = {}
|
||||
) : boolean
|
||||
{
|
||||
options = Object.assign(
|
||||
{
|
||||
"timestamp": _heimdall.get_current_timestamp(),
|
||||
},
|
||||
options
|
||||
);
|
||||
|
||||
return (
|
||||
check.active
|
||||
&&
|
||||
(
|
||||
(old_item_state === null)
|
||||
||
|
||||
((options.timestamp - old_item_state.timestamp) >= check.schedule.regular_interval)
|
||||
||
|
||||
(
|
||||
(old_item_state.count !== null)
|
||||
&&
|
||||
(old_item_state.condition !== _heimdall.enum_condition.ok)
|
||||
&&
|
||||
((options.timestamp - old_item_state.timestamp) >= check.schedule.attentive_interval)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @todo automated tests
|
||||
*/
|
||||
export function determine_shall_send_notification(
|
||||
check : _heimdall.type_check,
|
||||
send_ok_notifications : boolean,
|
||||
count : (null | int),
|
||||
timestamp : int,
|
||||
old_item_state : (null | _heimdall.type_item_state),
|
||||
result : _heimdall.type_result
|
||||
) : boolean
|
||||
{
|
||||
return (
|
||||
(
|
||||
(
|
||||
(! (count === null))
|
||||
&&
|
||||
(count === check.threshold)
|
||||
)
|
||||
||
|
||||
(
|
||||
(count === null)
|
||||
&&
|
||||
check.annoy
|
||||
)
|
||||
||
|
||||
(
|
||||
(count === null)
|
||||
&&
|
||||
(
|
||||
(! (old_item_state === null))
|
||||
&&
|
||||
(! (old_item_state.last_notification_timestamp === null))
|
||||
&&
|
||||
(! (check.schedule.reminding_interval === null))
|
||||
&&
|
||||
(
|
||||
(timestamp - old_item_state.last_notification_timestamp)
|
||||
>=
|
||||
check.schedule.reminding_interval
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
&&
|
||||
(
|
||||
(result.condition !== _heimdall.enum_condition.ok)
|
||||
||
|
||||
send_ok_notifications
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
export async function clean(
|
||||
options : {
|
||||
time_to_live ?: int;
|
||||
erase_state ?: boolean;
|
||||
} = {}
|
||||
) : Promise<void>
|
||||
{
|
||||
options = Object.assign(
|
||||
{
|
||||
"time_to_live": (7 * 24 * 60 * 60),
|
||||
"erase_state": false,
|
||||
},
|
||||
options
|
||||
);
|
||||
|
||||
const count : int = await _heimdall.state_repository.clean(
|
||||
options.time_to_live,
|
||||
options.erase_state
|
||||
);
|
||||
lib_plankton.log.info(
|
||||
lib_plankton.translate.get(
|
||||
"misc.cleanup_info",
|
||||
{
|
||||
"count": count.toFixed(0),
|
||||
}
|
||||
),
|
||||
{
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
export async function wrap_database(
|
||||
database_path_raw : (null | string),
|
||||
order_path : string,
|
||||
procedure : (() => Promise<void>)
|
||||
) : Promise<void>
|
||||
{
|
||||
const nm_path = require("path");
|
||||
const database_path : string = (
|
||||
(database_path_raw !== null)
|
||||
? database_path_raw
|
||||
: nm_path.join(
|
||||
// TODO get path from fs or path module?
|
||||
"/tmp",
|
||||
lib_plankton.string.coin(
|
||||
"monitoring-state-{{id}}.sqlite",
|
||||
{
|
||||
"id": lib_plankton.call.convey(
|
||||
order_path,
|
||||
[
|
||||
nm_path.normalize,
|
||||
// encode(ascii),
|
||||
x => lib_plankton.sha256.get(x),
|
||||
x => x.slice(0, 8),
|
||||
]
|
||||
),
|
||||
}
|
||||
)
|
||||
)
|
||||
);
|
||||
lib_plankton.log.info(
|
||||
lib_plankton.translate.get("misc.state_file_path"),
|
||||
{
|
||||
"database_path": database_path,
|
||||
}
|
||||
);
|
||||
await _heimdall.state_repository.init(database_path);
|
||||
await procedure();
|
||||
await _heimdall.state_repository.kill();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @todo outsource?
|
||||
*/
|
||||
export async function wrap_mutex(
|
||||
mutex_path : string,
|
||||
procedure : (() => Promise<void>)
|
||||
) : Promise<void>
|
||||
{
|
||||
const nm_fs = require("fs");
|
||||
if (nm_fs.existsSync(mutex_path)) {
|
||||
lib_plankton.log.error(
|
||||
lib_plankton.translate.get("misc.still_running"),
|
||||
{
|
||||
"mutex_path": mutex_path,
|
||||
}
|
||||
);
|
||||
return Promise.reject();
|
||||
}
|
||||
else {
|
||||
await lib_plankton.file.write(mutex_path, "");
|
||||
await procedure();
|
||||
await lib_plankton.file.delete_(mutex_path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* central processing procedure
|
||||
*/
|
||||
export async function run(
|
||||
order : _heimdall.type_order,
|
||||
options : {
|
||||
send_ok_notifications ?: boolean;
|
||||
} = {}
|
||||
) : Promise<void>
|
||||
{
|
||||
options = Object.assign(
|
||||
{
|
||||
"send_ok_notifications": false
|
||||
},
|
||||
options
|
||||
);
|
||||
|
||||
const notification_kind_implementations : Record<string, _heimdall.notification_kinds.type_notification_kind> = _heimdall.notification_kinds.get_implementations();
|
||||
const check_kind_implementations : Record<string, _heimdall.check_kinds.type_check_kind> = _heimdall.check_kinds.get_implementations();
|
||||
for await (const check of order.checks) {
|
||||
if (! check.active) {
|
||||
// do nothing
|
||||
}
|
||||
else {
|
||||
let old_item_state : (null | _heimdall.type_item_state);
|
||||
|
||||
const last_notification_timestamp : (null | int) = await _heimdall.state_repository.get_last_notification_timestamp(
|
||||
check.name
|
||||
);
|
||||
|
||||
const rows : Array<
|
||||
{
|
||||
timestamp : int;
|
||||
condition : _heimdall.enum_condition;
|
||||
notification_sent : boolean;
|
||||
}
|
||||
> = await _heimdall.state_repository.probe(
|
||||
check.name,
|
||||
(check.threshold + 1)
|
||||
);
|
||||
if (rows.length <= 0) {
|
||||
old_item_state = null;
|
||||
}
|
||||
else {
|
||||
let index : int = 1;
|
||||
while (index < rows.length) {
|
||||
if (rows[index].condition === rows[0].condition) {
|
||||
index += 1;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
old_item_state = {
|
||||
"timestamp": rows[0].timestamp,
|
||||
"condition": rows[0].condition,
|
||||
"count": ((index < check.threshold) ? index : null),
|
||||
"last_notification_timestamp": last_notification_timestamp,
|
||||
};
|
||||
}
|
||||
const timestamp : int = _heimdall.get_current_timestamp();
|
||||
const due : boolean = determine_due(
|
||||
check,
|
||||
old_item_state,
|
||||
{
|
||||
"timestamp": timestamp,
|
||||
}
|
||||
);
|
||||
if (! due) {
|
||||
// do nothing
|
||||
}
|
||||
else {
|
||||
process.stderr.write(
|
||||
lib_plankton.string.coin(
|
||||
"-- {{check_name}}\n",
|
||||
{
|
||||
"check_name": check.name,
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
// execute check and set new state
|
||||
let result : _heimdall.type_result;
|
||||
try {
|
||||
result = await check_kind_implementations[check.kind].run(check.parameters);
|
||||
}
|
||||
catch (error) {
|
||||
result = {
|
||||
"condition": _heimdall.enum_condition.unknown,
|
||||
"info": {
|
||||
"cause": lib_plankton.translate.get("misc.check_procedure_failed"),
|
||||
"error": error.toString(),
|
||||
},
|
||||
};
|
||||
}
|
||||
const count : (null | int) = (
|
||||
(
|
||||
(old_item_state === null)
|
||||
||
|
||||
(old_item_state.condition !== result.condition)
|
||||
)
|
||||
? 1
|
||||
: (
|
||||
(
|
||||
(! (old_item_state.count === null))
|
||||
&&
|
||||
((old_item_state.count + 1) <= check.threshold)
|
||||
)
|
||||
? (old_item_state.count + 1)
|
||||
: null
|
||||
)
|
||||
);
|
||||
const shall_send_notification : boolean = determine_shall_send_notification(
|
||||
check,
|
||||
options.send_ok_notifications,
|
||||
count,
|
||||
timestamp,
|
||||
old_item_state,
|
||||
result
|
||||
);
|
||||
const new_item_state : _heimdall.type_item_state = {
|
||||
"timestamp": timestamp,
|
||||
"condition": result.condition,
|
||||
"count": count,
|
||||
"last_notification_timestamp": (
|
||||
shall_send_notification
|
||||
? timestamp
|
||||
: (
|
||||
(old_item_state === null)
|
||||
? null
|
||||
: old_item_state.last_notification_timestamp
|
||||
)
|
||||
),
|
||||
}
|
||||
await _heimdall.state_repository.feed(
|
||||
check.name,
|
||||
timestamp,
|
||||
result.condition,
|
||||
shall_send_notification,
|
||||
result.info
|
||||
);
|
||||
|
||||
// send notifications
|
||||
if (! shall_send_notification) {
|
||||
// do nothing
|
||||
}
|
||||
else {
|
||||
check.notifications.forEach(
|
||||
notification => {
|
||||
notification_kind_implementations[notification.kind].notify(
|
||||
notification.parameters,
|
||||
check.name,
|
||||
check,
|
||||
new_item_state,
|
||||
Object.assign(
|
||||
(
|
||||
(check.custom === null)
|
||||
? {}
|
||||
: {"custom": check.custom}
|
||||
),
|
||||
result.info
|
||||
)
|
||||
)
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
18
source/logic/notification_kinds/_abstract.ts
Normal file
18
source/logic/notification_kinds/_abstract.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
namespace _heimdall.notification_kinds
|
||||
{
|
||||
|
||||
/**
|
||||
*/
|
||||
export type type_notification_kind = {
|
||||
parameters_schema : (() => _heimdall.helpers.json_schema.type_schema);
|
||||
normalize_order_node : ((node : any) => any);
|
||||
notify : (
|
||||
parameters : any,
|
||||
name : string,
|
||||
data : type_check,
|
||||
state : type_item_state,
|
||||
info : any
|
||||
) => Promise<void>;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
/*
|
||||
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||
<info@greenscale.de>
|
||||
|
||||
»heimdall« is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
»heimdall« is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with »heimdall«. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
namespace _heimdall.notification_kinds
|
||||
{
|
||||
|
||||
/**
|
||||
*/
|
||||
export type type_notification_kind = {
|
||||
parameters_schema : (
|
||||
()
|
||||
=>
|
||||
_heimdall.helpers.json_schema.type_schema
|
||||
);
|
||||
normalize_order_node : (
|
||||
(node : any)
|
||||
=>
|
||||
any
|
||||
);
|
||||
notify : (
|
||||
(
|
||||
parameters : any,
|
||||
name : string,
|
||||
data : type_check,
|
||||
state : type_item_state,
|
||||
info : any
|
||||
)
|
||||
=>
|
||||
Promise<void>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
var _implementations : Record<string, type_notification_kind> = {};
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
export function register_implementation(
|
||||
name : string,
|
||||
notification_kind : type_notification_kind
|
||||
) : void
|
||||
{
|
||||
_implementations[name] = notification_kind;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
export function get_implementation(
|
||||
name : string
|
||||
) : type_notification_kind
|
||||
{
|
||||
return _implementations[name];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
export function get_implementations(
|
||||
) : Record<string, type_notification_kind>
|
||||
{
|
||||
return _implementations;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,22 +1,3 @@
|
|||
/*
|
||||
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||
<info@greenscale.de>
|
||||
|
||||
»heimdall« is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
»heimdall« is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with »heimdall«. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
namespace _heimdall.notification_kinds.console
|
||||
{
|
||||
|
||||
|
|
@ -76,13 +57,14 @@ namespace _heimdall.notification_kinds.console
|
|||
|
||||
/**
|
||||
*/
|
||||
register_implementation(
|
||||
"console",
|
||||
{
|
||||
export function notification_kind_implementation(
|
||||
) : type_notification_kind
|
||||
{
|
||||
return {
|
||||
"parameters_schema": parameters_schema,
|
||||
"normalize_order_node": normalize_order_node,
|
||||
"notify": notify,
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +1,3 @@
|
|||
/*
|
||||
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||
<info@greenscale.de>
|
||||
|
||||
»heimdall« is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
»heimdall« is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with »heimdall«. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
namespace _heimdall.notification_kinds.email
|
||||
{
|
||||
|
||||
|
|
@ -147,13 +128,14 @@ namespace _heimdall.notification_kinds.email
|
|||
|
||||
/**
|
||||
*/
|
||||
register_implementation(
|
||||
"email",
|
||||
{
|
||||
export function notification_kind_implementation(
|
||||
) : type_notification_kind
|
||||
{
|
||||
return {
|
||||
"parameters_schema": parameters_schema,
|
||||
"normalize_order_node": normalize_order_node,
|
||||
"notify": notify,
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +1,3 @@
|
|||
/*
|
||||
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||
<info@greenscale.de>
|
||||
|
||||
»heimdall« is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
»heimdall« is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with »heimdall«. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
namespace _heimdall.notification_kinds.libnotify
|
||||
{
|
||||
|
||||
|
|
@ -133,13 +114,14 @@ namespace _heimdall.notification_kinds.libnotify
|
|||
|
||||
/**
|
||||
*/
|
||||
register_implementation(
|
||||
"libnotify",
|
||||
{
|
||||
export function notification_kind_implementation(
|
||||
) : type_notification_kind
|
||||
{
|
||||
return {
|
||||
"parameters_schema": parameters_schema,
|
||||
"normalize_order_node": normalize_order_node,
|
||||
"notify": notify,
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +1,3 @@
|
|||
/*
|
||||
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||
<info@greenscale.de>
|
||||
|
||||
»heimdall« is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
»heimdall« is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with »heimdall«. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
namespace _heimdall.order
|
||||
{
|
||||
|
||||
|
|
@ -126,9 +107,9 @@ namespace _heimdall.order
|
|||
/**
|
||||
*/
|
||||
function schema_notifications(
|
||||
notification_kind_implementations : Record<string, _heimdall.notification_kinds.type_notification_kind>
|
||||
) : _heimdall.helpers.json_schema.type_schema
|
||||
{
|
||||
const notification_kind_implementations = _heimdall.notification_kinds.get_implementations();
|
||||
return {
|
||||
"type": "array",
|
||||
"items": {
|
||||
|
|
@ -168,9 +149,10 @@ namespace _heimdall.order
|
|||
/**
|
||||
*/
|
||||
export function schema_root(
|
||||
check_kind_implementations : Record<string, _heimdall.check_kinds.type_check_kind>,
|
||||
notification_kind_implementations : Record<string, _heimdall.notification_kinds.type_notification_kind>,
|
||||
) : _heimdall.helpers.json_schema.type_schema
|
||||
{
|
||||
const check_kind_implementations = _heimdall.check_kinds.get_implementations();
|
||||
return {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
|
|
@ -184,7 +166,7 @@ namespace _heimdall.order
|
|||
"threshold": schema_threshold(),
|
||||
"annoy": schema_annoy(),
|
||||
"schedule": schema_schedule(),
|
||||
"notifications": schema_notifications(),
|
||||
"notifications": schema_notifications(notification_kind_implementations),
|
||||
},
|
||||
"required": [
|
||||
],
|
||||
|
|
@ -216,7 +198,7 @@ namespace _heimdall.order
|
|||
"threshold": schema_threshold(),
|
||||
"annoy": schema_annoy(),
|
||||
"schedule": schema_schedule(),
|
||||
"notifications": schema_notifications(),
|
||||
"notifications": schema_notifications(notification_kind_implementations),
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
|
|
@ -319,10 +301,10 @@ namespace _heimdall.order
|
|||
/**
|
||||
*/
|
||||
function normalize_notification(
|
||||
notification_kind_implementations : Record<string, _heimdall.notification_kinds.type_notification_kind>,
|
||||
node : any
|
||||
) : type_notification
|
||||
{
|
||||
const notification_kind_implementations = _heimdall.notification_kinds.get_implementations();
|
||||
if (! (node["kind"] in notification_kind_implementations)) {
|
||||
throw new Error("invalid notification kind: " + node["kind"]);
|
||||
}
|
||||
|
|
@ -338,6 +320,7 @@ namespace _heimdall.order
|
|||
/**
|
||||
*/
|
||||
function normalize_defaults(
|
||||
notification_kind_implementations : Record<string, _heimdall.notification_kinds.type_notification_kind>,
|
||||
node : any
|
||||
) : type_check_common
|
||||
{
|
||||
|
|
@ -363,7 +346,7 @@ namespace _heimdall.order
|
|||
"schedule": node_["schedule"],
|
||||
"notifications": (
|
||||
node_["notifications"]
|
||||
.map(x => normalize_notification(x))
|
||||
.map(x => normalize_notification(notification_kind_implementations, x))
|
||||
),
|
||||
};
|
||||
}
|
||||
|
|
@ -372,6 +355,8 @@ namespace _heimdall.order
|
|||
/**
|
||||
*/
|
||||
function normalize_check(
|
||||
check_kind_implementations : Record<string, _heimdall.check_kinds.type_check_kind>,
|
||||
notification_kind_implementations : Record<string, _heimdall.notification_kinds.type_notification_kind>,
|
||||
defaults : type_check_common,
|
||||
node : {
|
||||
name : string;
|
||||
|
|
@ -379,8 +364,6 @@ namespace _heimdall.order
|
|||
}
|
||||
) : type_check
|
||||
{
|
||||
const check_kind_implementations = _heimdall.check_kinds.get_implementations();
|
||||
const notification_kind_implementations = _heimdall.notification_kinds.get_implementations();
|
||||
if (! ("name" in node)) {
|
||||
throw new Error("missing mandatory field in 'check' node: 'name'");
|
||||
}
|
||||
|
|
@ -393,8 +376,8 @@ namespace _heimdall.order
|
|||
throw new Error("invalid check kind: " + node.kind);
|
||||
}
|
||||
else {
|
||||
const node_ : type_check = (Object.assign(
|
||||
lib_plankton.object.patched(
|
||||
const node_ : type_check = Object.assign(
|
||||
Object.assign(
|
||||
defaults,
|
||||
{
|
||||
"title": node.name,
|
||||
|
|
@ -403,7 +386,7 @@ namespace _heimdall.order
|
|||
},
|
||||
),
|
||||
node
|
||||
) as type_check);
|
||||
);
|
||||
let check : type_check = {
|
||||
"name": node_.name,
|
||||
"title": node_.title,
|
||||
|
|
@ -427,7 +410,7 @@ namespace _heimdall.order
|
|||
check.notifications = (
|
||||
node_["notifications"]
|
||||
.map(
|
||||
x => normalize_notification(x),
|
||||
x => normalize_notification(notification_kind_implementations, x),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
@ -444,6 +427,8 @@ namespace _heimdall.order
|
|||
/**
|
||||
*/
|
||||
function normalize_root(
|
||||
check_kind_implementations : Record<string, _heimdall.check_kinds.type_check_kind>,
|
||||
notification_kind_implementations : Record<string, _heimdall.notification_kinds.type_notification_kind>,
|
||||
node : any,
|
||||
options : {
|
||||
use_implicit_default_values ?: boolean;
|
||||
|
|
@ -455,8 +440,7 @@ namespace _heimdall.order
|
|||
"use_implicit_default_values": true,
|
||||
},
|
||||
options
|
||||
);
|
||||
|
||||
)
|
||||
let counts : Record<string, int> = {};
|
||||
const checks_raw : Array<any> = (
|
||||
("checks" in node)
|
||||
|
|
@ -492,19 +476,20 @@ namespace _heimdall.order
|
|||
("defaults" in node)
|
||||
? node["defaults"]
|
||||
: {}
|
||||
);
|
||||
)
|
||||
const defaults : type_check_common = (
|
||||
options.use_implicit_default_values
|
||||
? normalize_defaults(
|
||||
notification_kind_implementations,
|
||||
defaults_raw
|
||||
)
|
||||
: defaults_raw
|
||||
);
|
||||
)
|
||||
const includes : Array<string> = (
|
||||
("includes" in node)
|
||||
? node["includes"]
|
||||
: []
|
||||
);
|
||||
)
|
||||
return {
|
||||
"defaults": defaults,
|
||||
"includes": includes,
|
||||
|
|
@ -512,6 +497,8 @@ namespace _heimdall.order
|
|||
checks_raw
|
||||
.map(
|
||||
node_ => normalize_check(
|
||||
check_kind_implementations,
|
||||
notification_kind_implementations,
|
||||
defaults,
|
||||
node_
|
||||
)
|
||||
|
|
@ -525,6 +512,8 @@ namespace _heimdall.order
|
|||
/**
|
||||
*/
|
||||
export async function load(
|
||||
check_kind_implementations : Record<string, _heimdall.check_kinds.type_check_kind>,
|
||||
notification_kind_implementations : Record<string, _heimdall.notification_kinds.type_notification_kind>,
|
||||
path : string,
|
||||
options : {
|
||||
root ?: boolean;
|
||||
|
|
@ -540,8 +529,7 @@ namespace _heimdall.order
|
|||
"already_included": [],
|
||||
},
|
||||
options
|
||||
);
|
||||
|
||||
)
|
||||
if (options.already_included.includes(path)) {
|
||||
throw new Error("circular dependency detected")
|
||||
}
|
||||
|
|
@ -558,6 +546,8 @@ namespace _heimdall.order
|
|||
for (let index = 0; index < includes.length; index += 1) {
|
||||
const path_ : string = includes[index];
|
||||
const sub_order : type_order = await load(
|
||||
check_kind_implementations,
|
||||
notification_kind_implementations,
|
||||
(
|
||||
nm_path.isAbsolute(path_)
|
||||
? path_
|
||||
|
|
@ -592,6 +582,8 @@ namespace _heimdall.order
|
|||
order_raw.includes = [];
|
||||
}
|
||||
return normalize_root(
|
||||
check_kind_implementations,
|
||||
notification_kind_implementations,
|
||||
order_raw,
|
||||
{
|
||||
"use_implicit_default_values": options["root"],
|
||||
|
|
|
|||
|
|
@ -1,30 +1,6 @@
|
|||
/*
|
||||
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||
<info@greenscale.de>
|
||||
|
||||
»heimdall« is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
»heimdall« is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with »heimdall«. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
namespace _heimdall.state_repository
|
||||
{
|
||||
|
||||
/**
|
||||
*/
|
||||
var _connection : (null | lib_plankton.sqlite.type_connection) = null;
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
function condition_decode(
|
||||
|
|
@ -57,32 +33,12 @@ namespace _heimdall.state_repository
|
|||
|
||||
/**
|
||||
*/
|
||||
export async function init(
|
||||
export async function setup(
|
||||
database_path : string
|
||||
) : Promise<void>
|
||||
{
|
||||
_connection = await lib_plankton.sqlite.get_connection(database_path);
|
||||
await setup();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
export async function kill(
|
||||
) : Promise<void>
|
||||
{
|
||||
await lib_plankton.sqlite.drop_connection(_connection);
|
||||
_connection = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
export async function setup(
|
||||
) : Promise<void>
|
||||
{
|
||||
const result = await lib_plankton.sqlite.query_set(
|
||||
_connection,
|
||||
const result = await _heimdall.helpers.sqlite.query_set(
|
||||
database_path,
|
||||
{
|
||||
"template": "CREATE TABLE IF NOT EXISTS results(check_name TEXT NOT NULL, timestamp INTEGER NOT NULL, condition TEXT NOT NULL, notification_sent BOOLEAN NOT NULL, info TEXT NOT NULL);",
|
||||
"arguments": {
|
||||
|
|
@ -95,12 +51,13 @@ namespace _heimdall.state_repository
|
|||
/**
|
||||
*/
|
||||
export async function clean(
|
||||
database_path : string,
|
||||
time_to_live : int,
|
||||
erase_state : boolean
|
||||
) : Promise<int>
|
||||
{
|
||||
const result = await lib_plankton.sqlite.query_put(
|
||||
_connection,
|
||||
const result = await _heimdall.helpers.sqlite.query_put(
|
||||
database_path,
|
||||
{
|
||||
"template": "DELETE FROM results WHERE ((timestamp < :timestamp_min) OR :erase_state);",
|
||||
"arguments": {
|
||||
|
|
@ -116,6 +73,7 @@ namespace _heimdall.state_repository
|
|||
/**
|
||||
*/
|
||||
export async function probe(
|
||||
database_path : string,
|
||||
check_name : string,
|
||||
threshold : int
|
||||
) : Promise<
|
||||
|
|
@ -128,8 +86,8 @@ namespace _heimdall.state_repository
|
|||
>
|
||||
>
|
||||
{
|
||||
const rows : Array<Record<string, any>> = await lib_plankton.sqlite.query_get(
|
||||
_connection,
|
||||
const rows : Array<Array<any>> = await _heimdall.helpers.sqlite.query_get(
|
||||
database_path,
|
||||
{
|
||||
"template": "SELECT timestamp, condition, notification_sent FROM results WHERE (check_name = :check_name) ORDER BY timestamp DESC LIMIT :limit;",
|
||||
"arguments": {
|
||||
|
|
@ -142,9 +100,9 @@ namespace _heimdall.state_repository
|
|||
rows
|
||||
.map(
|
||||
row => ({
|
||||
"timestamp": row["timestamp"],
|
||||
"condition": condition_decode(row["condition"]),
|
||||
"notification_sent": row["notification_sent"],
|
||||
"timestamp": row[0],
|
||||
"condition": condition_decode(row[1]),
|
||||
"notification_sent": row[2],
|
||||
})
|
||||
)
|
||||
);
|
||||
|
|
@ -154,25 +112,27 @@ namespace _heimdall.state_repository
|
|||
/**
|
||||
*/
|
||||
export async function get_last_notification_timestamp(
|
||||
database_path : string,
|
||||
check_name : string
|
||||
) : Promise<(null | int)>
|
||||
{
|
||||
const rows : Array<Record<string, any>> = await lib_plankton.sqlite.query_get(
|
||||
_connection,
|
||||
const rows : Array<Array<any>> = await _heimdall.helpers.sqlite.query_get(
|
||||
database_path,
|
||||
{
|
||||
"template": "SELECT MAX(timestamp) AS max_timestamp FROM results WHERE (check_name = :check_name) AND (notification_sent = TRUE);",
|
||||
"template": "SELECT MAX(timestamp) FROM results WHERE (check_name = :check_name) AND (notification_sent = TRUE);",
|
||||
"arguments": {
|
||||
"check_name": check_name,
|
||||
},
|
||||
}
|
||||
);
|
||||
return rows[0]["max_timestamp"];
|
||||
return rows[0][0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
export async function feed(
|
||||
database_path : string,
|
||||
check_name : string,
|
||||
timestamp : int,
|
||||
condition : _heimdall.enum_condition,
|
||||
|
|
@ -180,8 +140,8 @@ namespace _heimdall.state_repository
|
|||
info : any
|
||||
) : Promise<void>
|
||||
{
|
||||
await lib_plankton.sqlite.query_put(
|
||||
_connection,
|
||||
await _heimdall.helpers.sqlite.query_put(
|
||||
database_path,
|
||||
{
|
||||
"template": "INSERT INTO results(check_name, timestamp, condition, notification_sent, info) VALUES (:check_name, :timestamp, :condition, :notification_sent, :info);",
|
||||
"arguments": {
|
||||
|
|
|
|||
|
|
@ -1,314 +0,0 @@
|
|||
{
|
||||
"parameters": {
|
||||
"check": {
|
||||
"active": true,
|
||||
"threshold": 1,
|
||||
"schedule": {
|
||||
"attentive_interval": 120,
|
||||
"regular_interval": 3600,
|
||||
"reminding_interval": 86400
|
||||
},
|
||||
"notifications": [],
|
||||
"name": "test",
|
||||
"title": "Test",
|
||||
"kind": "BOGUS",
|
||||
"parameters": {},
|
||||
"custom": null,
|
||||
"annoy": false
|
||||
},
|
||||
"old_item_state": {
|
||||
"timestamp": "2023-01-15T11:00:00",
|
||||
"last_notification_timestamp": "2023-01-15T10:00:00"
|
||||
}
|
||||
},
|
||||
"cases": [
|
||||
{
|
||||
"name": "{\"condition\":\"unknown\",\"threshold_reached\":false,\"passed\":\"none\"}",
|
||||
"input": {
|
||||
"condition": "unknown",
|
||||
"threshold_reached": false,
|
||||
"passed": "none"
|
||||
},
|
||||
"output": false
|
||||
},
|
||||
{
|
||||
"name": "{\"condition\":\"unknown\",\"threshold_reached\":false,\"passed\":\"attentive\"}",
|
||||
"input": {
|
||||
"condition": "unknown",
|
||||
"threshold_reached": false,
|
||||
"passed": "attentive"
|
||||
},
|
||||
"output": true
|
||||
},
|
||||
{
|
||||
"name": "{\"condition\":\"unknown\",\"threshold_reached\":false,\"passed\":\"regular\"}",
|
||||
"input": {
|
||||
"condition": "unknown",
|
||||
"threshold_reached": false,
|
||||
"passed": "regular"
|
||||
},
|
||||
"output": true
|
||||
},
|
||||
{
|
||||
"name": "{\"condition\":\"unknown\",\"threshold_reached\":false,\"passed\":\"reminding\"}",
|
||||
"input": {
|
||||
"condition": "unknown",
|
||||
"threshold_reached": false,
|
||||
"passed": "reminding"
|
||||
},
|
||||
"output": true
|
||||
},
|
||||
{
|
||||
"name": "{\"condition\":\"unknown\",\"threshold_reached\":true,\"passed\":\"none\"}",
|
||||
"input": {
|
||||
"condition": "unknown",
|
||||
"threshold_reached": true,
|
||||
"passed": "none"
|
||||
},
|
||||
"output": false
|
||||
},
|
||||
{
|
||||
"name": "{\"condition\":\"unknown\",\"threshold_reached\":true,\"passed\":\"attentive\"}",
|
||||
"input": {
|
||||
"condition": "unknown",
|
||||
"threshold_reached": true,
|
||||
"passed": "attentive"
|
||||
},
|
||||
"output": false
|
||||
},
|
||||
{
|
||||
"name": "{\"condition\":\"unknown\",\"threshold_reached\":true,\"passed\":\"regular\"}",
|
||||
"input": {
|
||||
"condition": "unknown",
|
||||
"threshold_reached": true,
|
||||
"passed": "regular"
|
||||
},
|
||||
"output": true
|
||||
},
|
||||
{
|
||||
"name": "{\"condition\":\"unknown\",\"threshold_reached\":true,\"passed\":\"reminding\"}",
|
||||
"input": {
|
||||
"condition": "unknown",
|
||||
"threshold_reached": true,
|
||||
"passed": "reminding"
|
||||
},
|
||||
"output": true
|
||||
},
|
||||
{
|
||||
"name": "{\"condition\":\"ok\",\"threshold_reached\":false,\"passed\":\"none\"}",
|
||||
"input": {
|
||||
"condition": "ok",
|
||||
"threshold_reached": false,
|
||||
"passed": "none"
|
||||
},
|
||||
"output": false
|
||||
},
|
||||
{
|
||||
"name": "{\"condition\":\"ok\",\"threshold_reached\":false,\"passed\":\"attentive\"}",
|
||||
"input": {
|
||||
"condition": "ok",
|
||||
"threshold_reached": false,
|
||||
"passed": "attentive"
|
||||
},
|
||||
"output": false
|
||||
},
|
||||
{
|
||||
"name": "{\"condition\":\"ok\",\"threshold_reached\":false,\"passed\":\"regular\"}",
|
||||
"input": {
|
||||
"condition": "ok",
|
||||
"threshold_reached": false,
|
||||
"passed": "regular"
|
||||
},
|
||||
"output": true
|
||||
},
|
||||
{
|
||||
"name": "{\"condition\":\"ok\",\"threshold_reached\":false,\"passed\":\"reminding\"}",
|
||||
"input": {
|
||||
"condition": "ok",
|
||||
"threshold_reached": false,
|
||||
"passed": "reminding"
|
||||
},
|
||||
"output": true
|
||||
},
|
||||
{
|
||||
"name": "{\"condition\":\"ok\",\"threshold_reached\":true,\"passed\":\"none\"}",
|
||||
"input": {
|
||||
"condition": "ok",
|
||||
"threshold_reached": true,
|
||||
"passed": "none"
|
||||
},
|
||||
"output": false
|
||||
},
|
||||
{
|
||||
"name": "{\"condition\":\"ok\",\"threshold_reached\":true,\"passed\":\"attentive\"}",
|
||||
"input": {
|
||||
"condition": "ok",
|
||||
"threshold_reached": true,
|
||||
"passed": "attentive"
|
||||
},
|
||||
"output": false
|
||||
},
|
||||
{
|
||||
"name": "{\"condition\":\"ok\",\"threshold_reached\":true,\"passed\":\"regular\"}",
|
||||
"input": {
|
||||
"condition": "ok",
|
||||
"threshold_reached": true,
|
||||
"passed": "regular"
|
||||
},
|
||||
"output": true
|
||||
},
|
||||
{
|
||||
"name": "{\"condition\":\"ok\",\"threshold_reached\":true,\"passed\":\"reminding\"}",
|
||||
"input": {
|
||||
"condition": "ok",
|
||||
"threshold_reached": true,
|
||||
"passed": "reminding"
|
||||
},
|
||||
"output": true
|
||||
},
|
||||
{
|
||||
"name": "{\"condition\":\"concerning\",\"threshold_reached\":false,\"passed\":\"none\"}",
|
||||
"input": {
|
||||
"condition": "concerning",
|
||||
"threshold_reached": false,
|
||||
"passed": "none"
|
||||
},
|
||||
"output": false
|
||||
},
|
||||
{
|
||||
"name": "{\"condition\":\"concerning\",\"threshold_reached\":false,\"passed\":\"attentive\"}",
|
||||
"input": {
|
||||
"condition": "concerning",
|
||||
"threshold_reached": false,
|
||||
"passed": "attentive"
|
||||
},
|
||||
"output": true
|
||||
},
|
||||
{
|
||||
"name": "{\"condition\":\"concerning\",\"threshold_reached\":false,\"passed\":\"regular\"}",
|
||||
"input": {
|
||||
"condition": "concerning",
|
||||
"threshold_reached": false,
|
||||
"passed": "regular"
|
||||
},
|
||||
"output": true
|
||||
},
|
||||
{
|
||||
"name": "{\"condition\":\"concerning\",\"threshold_reached\":false,\"passed\":\"reminding\"}",
|
||||
"input": {
|
||||
"condition": "concerning",
|
||||
"threshold_reached": false,
|
||||
"passed": "reminding"
|
||||
},
|
||||
"output": true
|
||||
},
|
||||
{
|
||||
"name": "{\"condition\":\"concerning\",\"threshold_reached\":true,\"passed\":\"none\"}",
|
||||
"input": {
|
||||
"condition": "concerning",
|
||||
"threshold_reached": true,
|
||||
"passed": "none"
|
||||
},
|
||||
"output": false
|
||||
},
|
||||
{
|
||||
"name": "{\"condition\":\"concerning\",\"threshold_reached\":true,\"passed\":\"attentive\"}",
|
||||
"input": {
|
||||
"condition": "concerning",
|
||||
"threshold_reached": true,
|
||||
"passed": "attentive"
|
||||
},
|
||||
"output": false
|
||||
},
|
||||
{
|
||||
"name": "{\"condition\":\"concerning\",\"threshold_reached\":true,\"passed\":\"regular\"}",
|
||||
"input": {
|
||||
"condition": "concerning",
|
||||
"threshold_reached": true,
|
||||
"passed": "regular"
|
||||
},
|
||||
"output": true
|
||||
},
|
||||
{
|
||||
"name": "{\"condition\":\"concerning\",\"threshold_reached\":true,\"passed\":\"reminding\"}",
|
||||
"input": {
|
||||
"condition": "concerning",
|
||||
"threshold_reached": true,
|
||||
"passed": "reminding"
|
||||
},
|
||||
"output": true
|
||||
},
|
||||
{
|
||||
"name": "{\"condition\":\"critical\",\"threshold_reached\":false,\"passed\":\"none\"}",
|
||||
"input": {
|
||||
"condition": "critical",
|
||||
"threshold_reached": false,
|
||||
"passed": "none"
|
||||
},
|
||||
"output": false
|
||||
},
|
||||
{
|
||||
"name": "{\"condition\":\"critical\",\"threshold_reached\":false,\"passed\":\"attentive\"}",
|
||||
"input": {
|
||||
"condition": "critical",
|
||||
"threshold_reached": false,
|
||||
"passed": "attentive"
|
||||
},
|
||||
"output": true
|
||||
},
|
||||
{
|
||||
"name": "{\"condition\":\"critical\",\"threshold_reached\":false,\"passed\":\"regular\"}",
|
||||
"input": {
|
||||
"condition": "critical",
|
||||
"threshold_reached": false,
|
||||
"passed": "regular"
|
||||
},
|
||||
"output": true
|
||||
},
|
||||
{
|
||||
"name": "{\"condition\":\"critical\",\"threshold_reached\":false,\"passed\":\"reminding\"}",
|
||||
"input": {
|
||||
"condition": "critical",
|
||||
"threshold_reached": false,
|
||||
"passed": "reminding"
|
||||
},
|
||||
"output": true
|
||||
},
|
||||
{
|
||||
"name": "{\"condition\":\"critical\",\"threshold_reached\":true,\"passed\":\"none\"}",
|
||||
"input": {
|
||||
"condition": "critical",
|
||||
"threshold_reached": true,
|
||||
"passed": "none"
|
||||
},
|
||||
"output": false
|
||||
},
|
||||
{
|
||||
"name": "{\"condition\":\"critical\",\"threshold_reached\":true,\"passed\":\"attentive\"}",
|
||||
"input": {
|
||||
"condition": "critical",
|
||||
"threshold_reached": true,
|
||||
"passed": "attentive"
|
||||
},
|
||||
"output": false
|
||||
},
|
||||
{
|
||||
"name": "{\"condition\":\"critical\",\"threshold_reached\":true,\"passed\":\"regular\"}",
|
||||
"input": {
|
||||
"condition": "critical",
|
||||
"threshold_reached": true,
|
||||
"passed": "regular"
|
||||
},
|
||||
"output": true
|
||||
},
|
||||
{
|
||||
"name": "{\"condition\":\"critical\",\"threshold_reached\":true,\"passed\":\"reminding\"}",
|
||||
"input": {
|
||||
"condition": "critical",
|
||||
"threshold_reached": true,
|
||||
"passed": "reminding"
|
||||
},
|
||||
"output": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -1,167 +0,0 @@
|
|||
/*
|
||||
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
||||
<info@greenscale.de>
|
||||
|
||||
»heimdall« is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
»heimdall« is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with »heimdall«. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
const nm_assert = require("assert");
|
||||
const nm_fs = require("fs");
|
||||
|
||||
declare var describe;
|
||||
declare var it;
|
||||
|
||||
_heimdall.init();
|
||||
describe(
|
||||
"heimdall",
|
||||
() => {
|
||||
function datetimestring_to_timestamp(datetimestring) {
|
||||
return Math.floor((new Date(datetimestring)).getTime() / 1000);
|
||||
};
|
||||
function resolve_condition(condition_raw) {
|
||||
return {
|
||||
"unknown": _heimdall.enum_condition.unknown,
|
||||
"ok": _heimdall.enum_condition.ok,
|
||||
"concerning": _heimdall.enum_condition.concerning,
|
||||
"critical": _heimdall.enum_condition.critical,
|
||||
}[condition_raw];
|
||||
};
|
||||
const data = JSON.parse(nm_fs.readFileSync("./test-data.json"));
|
||||
describe(
|
||||
"master.determine_due",
|
||||
() => {
|
||||
data.cases.forEach(
|
||||
case_ => {
|
||||
it(
|
||||
case_.name,
|
||||
() => {
|
||||
// setup
|
||||
const check : _heimdall.type_check = Object.assign(
|
||||
data.parameters["check"],
|
||||
{
|
||||
"annoy": false,
|
||||
}
|
||||
);
|
||||
const old_item_state : _heimdall.type_item_state = {
|
||||
"timestamp": datetimestring_to_timestamp(data.parameters["old_item_state"]["timestamp"]),
|
||||
"condition": resolve_condition(case_.input["condition"]),
|
||||
"count": (case_.input["threshold_reached"] ? null : 0),
|
||||
"last_notification_timestamp": datetimestring_to_timestamp(data.parameters["old_item_state"]["last_notification_timestamp"]),
|
||||
};
|
||||
const timestamp : int = (
|
||||
datetimestring_to_timestamp(
|
||||
data.parameters["old_item_state"]["timestamp"]
|
||||
)
|
||||
+
|
||||
(
|
||||
{
|
||||
"none": 0,
|
||||
"attentive": data.parameters["check"]["schedule"]["attentive_interval"],
|
||||
"regular": data.parameters["check"]["schedule"]["regular_interval"],
|
||||
"reminding": data.parameters["check"]["schedule"]["reminding_interval"]
|
||||
}[case_.input["passed"]]
|
||||
)
|
||||
+
|
||||
60
|
||||
);
|
||||
|
||||
// execution
|
||||
const result : boolean = _heimdall.master.determine_due(
|
||||
check,
|
||||
old_item_state,
|
||||
{
|
||||
"timestamp": timestamp,
|
||||
}
|
||||
);
|
||||
|
||||
// assertions
|
||||
nm_assert.equal(result, case_.output);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
/*
|
||||
describe(
|
||||
"master.determine_shall_send_notification",
|
||||
() => {
|
||||
it(
|
||||
"test",
|
||||
() => {
|
||||
// setup
|
||||
const check : _heimdall.type_check = {
|
||||
"name": "iks.web.2",
|
||||
"title": "web.2",
|
||||
"kind": "http_request",
|
||||
"parameters": {
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"target": "https://iks-sachsen.de"
|
||||
},
|
||||
"timeout": 5,
|
||||
"follow_redirects": true,
|
||||
"response": {
|
||||
"status_code": 200
|
||||
},
|
||||
"critical": true
|
||||
},
|
||||
"custom": null,
|
||||
"active": false,
|
||||
"threshold": 3,
|
||||
"annoy": false,
|
||||
"schedule": {
|
||||
"regular_interval": 60,
|
||||
"attentive_interval": 10,
|
||||
"reminding_interval": 86400
|
||||
},
|
||||
"notifications": [
|
||||
{
|
||||
"kind": "console",
|
||||
"parameters": {
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
const old_item_state : _heimdall.type_item_state = {
|
||||
"timestamp": 1693493942,
|
||||
"condition": _heimdall.enum_condition.critical,
|
||||
"count": 2,
|
||||
"last_notification_timestamp": 1693493942,
|
||||
};
|
||||
const timestamp : int = 1693495622;
|
||||
|
||||
// execution
|
||||
const result : boolean = _heimdall.master.determine_shall_send_notification(
|
||||
check,
|
||||
false,
|
||||
3,
|
||||
timestamp,
|
||||
old_item_state,
|
||||
{
|
||||
"condition": _heimdall.enum_condition.critical,
|
||||
"info": {},
|
||||
}
|
||||
);
|
||||
|
||||
// assertions
|
||||
nm_assert.equal(result, false);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
*/
|
||||
}
|
||||
);
|
||||
105
source/test/test.py
Normal file
105
source/test/test.py
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
definitions = [
|
||||
{
|
||||
"name": "lib.string_coin",
|
||||
"procedure": lambda input_: string_coin(input_["template"], input_["arguments"]),
|
||||
"cases": [
|
||||
{
|
||||
"input": {
|
||||
"template": "{{sachen}} sind {{farbe}}",
|
||||
"arguments": {
|
||||
"farbe": "rot",
|
||||
},
|
||||
},
|
||||
"output": "{{sachen}} sind rot"
|
||||
},
|
||||
{
|
||||
"input": {
|
||||
"template": "{{sachen}} sind {{farbe}}",
|
||||
"arguments": {
|
||||
},
|
||||
},
|
||||
"output": "{{sachen}} sind {{farbe}}"
|
||||
},
|
||||
{
|
||||
"input": {
|
||||
"template": "{{sachen}} sind {{farbe}}",
|
||||
"arguments": {
|
||||
"sachen": "rosen",
|
||||
"farbe": "rot",
|
||||
},
|
||||
},
|
||||
"output": "rosen sind rot"
|
||||
},
|
||||
{
|
||||
"input": {
|
||||
"template": "{{sachen}} sind {{farbe}}",
|
||||
"arguments": {
|
||||
"sachen": "rosen",
|
||||
"farbe": "rot",
|
||||
"ort": "frankreich",
|
||||
},
|
||||
},
|
||||
"output": "rosen sind rot"
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "lib.format_bytes",
|
||||
"procedure": lambda input_: format_bytes(input_),
|
||||
"cases": [
|
||||
{
|
||||
"input": 999,
|
||||
"output": "999 B",
|
||||
},
|
||||
{
|
||||
"input": 1000,
|
||||
"output": "1.0 KB",
|
||||
},
|
||||
{
|
||||
"input": 1000000,
|
||||
"output": "1.0 MB",
|
||||
},
|
||||
{
|
||||
"input": 1000000000,
|
||||
"output": "1.0 GB",
|
||||
},
|
||||
{
|
||||
"input": 1000000000000,
|
||||
"output": "1.0 TB",
|
||||
},
|
||||
{
|
||||
"input": 1000000000000000,
|
||||
"output": "1.0 PB",
|
||||
},
|
||||
{
|
||||
"input": 1000000000000000000,
|
||||
"output": "1000.0 PB",
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
for definition in definitions:
|
||||
fails = 0
|
||||
for index in range(len(definition["cases"])):
|
||||
case = definition["cases"][index]
|
||||
output_actual = definition["procedure"](case["input"])
|
||||
output_expected = case["output"]
|
||||
passed = (output_actual == output_expected)
|
||||
fails += (0 if passed else 1)
|
||||
info = {
|
||||
"input": case["input"],
|
||||
"output_expected": output_expected,
|
||||
"output_actual": output_actual,
|
||||
}
|
||||
_sys.stderr.write(
|
||||
"[%s] %s.%u%s\n"
|
||||
% (
|
||||
("+" if passed else "x"),
|
||||
definition["name"],
|
||||
index,
|
||||
("" if passed else (": " + _json.dumps(info))),
|
||||
)
|
||||
)
|
||||
_sys.exit(1 if (fails > 0) else 0)
|
||||
4
todo.md
4
todo.md
|
|
@ -1,10 +1,10 @@
|
|||
- neu schreiben in TypeScript (und plankton dafür nutzen?)
|
||||
- Benachrichtigungen versenden, wenn ein Zustand sich wieder normalisiert hat (aber vorher über dem Schwellwert oft nicht OK war)
|
||||
- Selbst-Test
|
||||
- Benachrichtigungs-Kanäle:
|
||||
- Matrix
|
||||
- evtl. die Kanäle ganz auslagern und nur als Library anbinden
|
||||
- Möglichkeit dauerhaft laufen zu lassen (evtl. als systemd-Dienst)
|
||||
- Möglichkeit dauerhaft laufen zulassen (evtl. als systemd-Dienst)
|
||||
- Versionierung
|
||||
- Test-Routinen
|
||||
- ein paar der Kommandozeilen-Argumente in Konfiguration auslagern
|
||||
- Zustand 'ok' in 'good' umbenennen
|
||||
|
|
|
|||
75
tools/build
75
tools/build
|
|
@ -1,69 +1,14 @@
|
|||
#!/usr/bin/env python3
|
||||
#!/usr/bin/env sh
|
||||
|
||||
import os as _os
|
||||
import shutil as _shutil
|
||||
import argparse as _argparse
|
||||
## vars
|
||||
|
||||
path_prj_from=tools/heimdall.prj.json
|
||||
path_prj_to=heimdall.prj.json
|
||||
|
||||
|
||||
def file_copy(
|
||||
path_from,
|
||||
path_to
|
||||
):
|
||||
_shutil.copyfile(path_from, path_to)
|
||||
## exec
|
||||
|
||||
|
||||
def file_remove(
|
||||
path
|
||||
):
|
||||
_os.remove(path)
|
||||
|
||||
|
||||
def shell_execute(
|
||||
command
|
||||
):
|
||||
_os.system(command)
|
||||
|
||||
|
||||
|
||||
def main(
|
||||
):
|
||||
## args
|
||||
|
||||
argument_parser = _argparse.ArgumentParser()
|
||||
argument_parser.add_argument(
|
||||
"-t",
|
||||
"--include-tests",
|
||||
action = "store_true"
|
||||
)
|
||||
args = argument_parser.parse_args()
|
||||
|
||||
|
||||
## consts
|
||||
|
||||
path_prj_core_from = "tools/heimdall-core.prj.json"
|
||||
path_prj_core_to = "heimdall-core.prj.json"
|
||||
path_prj_app_from = "tools/heimdall-app.prj.json"
|
||||
path_prj_app_to = "heimdall-app.prj.json"
|
||||
path_prj_test_from = "tools/heimdall-test.prj.json"
|
||||
path_prj_test_to = "heimdall-test.prj.json"
|
||||
|
||||
|
||||
## exec
|
||||
|
||||
file_copy(path_prj_core_from, path_prj_core_to)
|
||||
file_copy(path_prj_app_from, path_prj_app_to)
|
||||
file_copy(path_prj_test_from, path_prj_test_to)
|
||||
|
||||
shell_execute("tools/koralle --execute %s" % path_prj_app_to)
|
||||
shell_execute("chmod +r build/heimdall")
|
||||
if (not args.include_tests):
|
||||
pass
|
||||
else:
|
||||
shell_execute("koralle --execute %s" % path_prj_test_to)
|
||||
|
||||
file_remove(path_prj_test_to)
|
||||
file_remove(path_prj_app_to)
|
||||
file_remove(path_prj_core_to)
|
||||
|
||||
|
||||
main()
|
||||
cp ${path_prj_from} ${path_prj_to}
|
||||
koralle --execute ${path_prj_to}
|
||||
chmod +r build/heimdall
|
||||
rm ${path_prj_to}
|
||||
|
|
|
|||
68
tools/deploy
68
tools/deploy
|
|
@ -1,59 +1,19 @@
|
|||
#!/usr/bin/env python3
|
||||
#!/usr/bin/env sh
|
||||
|
||||
import sys as _sys
|
||||
import os as _os
|
||||
import argparse as _argparse
|
||||
## args
|
||||
|
||||
if [ $# -ge 1 ] ; then target_ssh_handle=$1 && shift ; else target_ssh_handle="gs-monitoring" ; fi
|
||||
|
||||
|
||||
def main():
|
||||
## args
|
||||
argument_parser = _argparse.ArgumentParser()
|
||||
argument_parser.add_argument(
|
||||
type = str,
|
||||
dest = "target_system",
|
||||
metavar = "<target-system>",
|
||||
help = "either 'localhost' or SSH handle of the target system",
|
||||
)
|
||||
argument_parser.add_argument(
|
||||
"-t",
|
||||
"--target-directory",
|
||||
type = str,
|
||||
dest = "target_directory",
|
||||
default = "/opt/heimdall",
|
||||
metavar = "<target-directory>",
|
||||
help = "directory on the target system, where the files shall be put; default: /opt/heimdall",
|
||||
)
|
||||
argument_parser.add_argument(
|
||||
"-b",
|
||||
"--build-directory",
|
||||
type = str,
|
||||
dest = "build_directory",
|
||||
default = "build",
|
||||
metavar = "<build-directory>",
|
||||
help = "directory to where the build was put",
|
||||
)
|
||||
args = argument_parser.parse_args()
|
||||
|
||||
## exec
|
||||
if (not _os.path.exists(args.build_directory)):
|
||||
_sys.stderr.write("-- build directory not found; probably you need to run /tools/build\n")
|
||||
_sys.exit(1)
|
||||
else:
|
||||
_os.system(
|
||||
" ".join([
|
||||
"rsync",
|
||||
"--recursive",
|
||||
"--update",
|
||||
"--verbose",
|
||||
("%s/" % args.build_directory),
|
||||
(
|
||||
("%s" % args.target_directory)
|
||||
if (args.target_system == "localhost") else
|
||||
("%s:%s" % (args.target_system, args.target_directory, ))
|
||||
),
|
||||
])
|
||||
)
|
||||
|
||||
## exec
|
||||
|
||||
main()
|
||||
rsync \
|
||||
--rsh=ssh \
|
||||
--recursive \
|
||||
--update \
|
||||
--delete \
|
||||
--exclude 'node_modules' \
|
||||
--verbose \
|
||||
build/ \
|
||||
${target_ssh_handle}:/opt/heimdall
|
||||
|
||||
|
|
|
|||
|
|
@ -1,57 +0,0 @@
|
|||
{
|
||||
"name": "heimdall-app",
|
||||
"dependencies": [
|
||||
"heimdall-core.prj.json"
|
||||
],
|
||||
"roottask": {
|
||||
"name": "all",
|
||||
"type": "group",
|
||||
"sub": [
|
||||
{
|
||||
"name": "postprocess",
|
||||
"sub": [
|
||||
{
|
||||
"name": "link",
|
||||
"sub": [
|
||||
{
|
||||
"name": "compile",
|
||||
"type": "typescript",
|
||||
"parameters": {
|
||||
"inputs": [
|
||||
"lib/plankton/plankton.d.ts",
|
||||
"temp/heimdall-core.d.ts",
|
||||
"source/app/cli.ts"
|
||||
],
|
||||
"target": "es2020",
|
||||
"strict": true,
|
||||
"output": "temp/heimdall-app.raw.js"
|
||||
}
|
||||
}
|
||||
],
|
||||
"type": "concat",
|
||||
"parameters": {
|
||||
"inputs": [
|
||||
"source/misc/head.js",
|
||||
"lib/plankton/plankton.js",
|
||||
"temp/heimdall-core.js",
|
||||
"temp/heimdall-app.raw.js"
|
||||
],
|
||||
"output": "temp/heimdall-app.js"
|
||||
}
|
||||
}
|
||||
],
|
||||
"type": "script",
|
||||
"parameters": {
|
||||
"path": "tools/postprocess",
|
||||
"interpreter": null,
|
||||
"inputs": [
|
||||
"temp/heimdall-app.js"
|
||||
],
|
||||
"outputs": [
|
||||
"build/heimdall"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
{
|
||||
"name": "heimdall-core",
|
||||
"dependencies": [
|
||||
],
|
||||
"roottask": {
|
||||
"name": "all",
|
||||
"type": "group",
|
||||
"sub": [
|
||||
{
|
||||
"name": "compile",
|
||||
"type": "typescript",
|
||||
"parameters": {
|
||||
"inputs": [
|
||||
"lib/plankton/plankton.d.ts",
|
||||
"source/base.ts",
|
||||
"source/helpers/json_schema.ts",
|
||||
"source/helpers/misc.ts",
|
||||
"source/logic/state_repository.ts",
|
||||
"source/logic/notification_kinds/_base.ts",
|
||||
"source/logic/notification_kinds/console.ts",
|
||||
"source/logic/notification_kinds/email.ts",
|
||||
"source/logic/notification_kinds/libnotify.ts",
|
||||
"source/logic/check_kinds/_base.ts",
|
||||
"source/logic/check_kinds/script.ts",
|
||||
"source/logic/check_kinds/http_request.ts",
|
||||
"source/logic/check_kinds/file_state.ts",
|
||||
"source/logic/check_kinds/tls_certificate.ts",
|
||||
"source/logic/check_kinds/generic_remote.ts",
|
||||
"source/logic/order.ts",
|
||||
"source/logic/master.ts",
|
||||
"source/init.ts"
|
||||
],
|
||||
"target": "es2020",
|
||||
"strict": true,
|
||||
"output": "temp/heimdall-core.js",
|
||||
"declaration": "temp/heimdall-core.d.ts"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "node_modules",
|
||||
"type": "copy",
|
||||
"parameters": {
|
||||
"folder": true,
|
||||
"input": "lib/node/node_modules/",
|
||||
"output": "build/node_modules/"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "localization",
|
||||
"type": "copy",
|
||||
"parameters": {
|
||||
"folder": true,
|
||||
"input": "source/localization/",
|
||||
"output": "build/localization/"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
{
|
||||
"name": "heimdall-test",
|
||||
"dependencies": [
|
||||
"heimdall-core.prj.json"
|
||||
],
|
||||
"roottask": {
|
||||
"name": "all",
|
||||
"type": "group",
|
||||
"sub": [
|
||||
{
|
||||
"name": "link",
|
||||
"sub": [
|
||||
{
|
||||
"name": "compile",
|
||||
"type": "typescript",
|
||||
"parameters": {
|
||||
"inputs": [
|
||||
"lib/plankton/plankton.d.ts",
|
||||
"temp/heimdall-core.d.ts",
|
||||
"source/test/test.mocha.ts"
|
||||
],
|
||||
"target": "es2020",
|
||||
"strict": true,
|
||||
"output": "temp/heimdall-test.mocha.raw.js"
|
||||
}
|
||||
}
|
||||
],
|
||||
"type": "concat",
|
||||
"parameters": {
|
||||
"inputs": [
|
||||
"lib/plankton/plankton.js",
|
||||
"temp/heimdall-core.js",
|
||||
"temp/heimdall-test.mocha.raw.js"
|
||||
],
|
||||
"output": "build/heimdall-test.mocha.js"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"type": "copy",
|
||||
"parameters": {
|
||||
"input": "source/test/data.json",
|
||||
"output": "build/test-data.json"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
90
tools/heimdall.prj.json
Normal file
90
tools/heimdall.prj.json
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
{
|
||||
"name": "heimdall",
|
||||
"version": "0.8",
|
||||
"dependencies": [
|
||||
],
|
||||
"roottask": {
|
||||
"name": "logic",
|
||||
"type": "group",
|
||||
"sub": [
|
||||
{
|
||||
"name": "postprocess",
|
||||
"sub": [
|
||||
{
|
||||
"name": "link",
|
||||
"sub": [
|
||||
{
|
||||
"name": "compile",
|
||||
"type": "typescript",
|
||||
"parameters": {
|
||||
"inputs": [
|
||||
"lib/plankton/plankton.d.ts",
|
||||
"source/logic/base.ts",
|
||||
"source/logic/helpers/json_schema.ts",
|
||||
"source/logic/helpers/sqlite.ts",
|
||||
"source/logic/helpers/misc.ts",
|
||||
"source/logic/notification_kinds/_abstract.ts",
|
||||
"source/logic/notification_kinds/console.ts",
|
||||
"source/logic/notification_kinds/email.ts",
|
||||
"source/logic/notification_kinds/libnotify.ts",
|
||||
"source/logic/check_kinds/_abstract.ts",
|
||||
"source/logic/check_kinds/script.ts",
|
||||
"source/logic/check_kinds/http_request.ts",
|
||||
"source/logic/check_kinds/file_state.ts",
|
||||
"source/logic/check_kinds/tls_certificate.ts",
|
||||
"source/logic/check_kinds/generic_remote.ts",
|
||||
"source/logic/state_repository.ts",
|
||||
"source/logic/order.ts",
|
||||
"source/logic/main.ts"
|
||||
],
|
||||
"target": "es2020",
|
||||
"strict": true,
|
||||
"output": "temp/heimdall-unlinked"
|
||||
}
|
||||
}
|
||||
],
|
||||
"type": "concat",
|
||||
"parameters": {
|
||||
"inputs": [
|
||||
"source/misc/head.js",
|
||||
"lib/plankton/plankton.js",
|
||||
"temp/heimdall-unlinked"
|
||||
],
|
||||
"output": "temp/heimdall-raw"
|
||||
}
|
||||
}
|
||||
],
|
||||
"type": "script",
|
||||
"parameters": {
|
||||
"path": "tools/postprocess",
|
||||
"interpreter": null,
|
||||
"inputs": [
|
||||
"temp/heimdall-raw"
|
||||
],
|
||||
"outputs": [
|
||||
"build/heimdall"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"active": true,
|
||||
"name": "node_modules",
|
||||
"type": "copy",
|
||||
"parameters": {
|
||||
"folder": true,
|
||||
"input": "lib/node/node_modules/",
|
||||
"output": "build/node_modules/"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "localization",
|
||||
"type": "copy",
|
||||
"parameters": {
|
||||
"folder": true,
|
||||
"input": "source/localization/",
|
||||
"output": "build/localization/"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +1,8 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
## args
|
||||
mkdir -p /usr/local/bin/
|
||||
cp build/heimdall /usr/local/bin/heimdall
|
||||
|
||||
if [ $# -ge 1 ] ; then directory=$1 && shift ; else directory="/opt/heimdall" ; fi
|
||||
|
||||
|
||||
## exec
|
||||
|
||||
mkdir --parents ${directory}
|
||||
cp --recursive --update --verbose build/* ${directory}/
|
||||
|
||||
mkdir --parents /usr/local/bin/
|
||||
echo "NODE_PATH=\${NODE_PATH}:${directory} ${directory}/heimdall \$@" > /usr/local/bin/heimdall
|
||||
chmod +x /usr/local/bin/heimdall
|
||||
|
||||
mkdir --parents /usr/local/share/icons/
|
||||
mkdir -p /usr/local/share/icons/
|
||||
cp media/icon.png /usr/local/share/icons/heimdall.png
|
||||
|
||||
|
|
|
|||
16329
tools/koralle
16329
tools/koralle
File diff suppressed because it is too large
Load diff
14
tools/makefile
Normal file
14
tools/makefile
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
## consts
|
||||
|
||||
dir_lib := lib
|
||||
dir_source := source
|
||||
dir_build := build
|
||||
|
||||
cmd_mkdir := mkdir -p
|
||||
cmd_tsc := tsc
|
||||
cmd_chmod := chmod
|
||||
|
||||
|
||||
## rules
|
||||
|
||||
${dir_build}
|
||||
|
|
@ -19,7 +19,6 @@ modules="${modules} file"
|
|||
modules="${modules} translate"
|
||||
modules="${modules} args"
|
||||
modules="${modules} http"
|
||||
modules="${modules} sqlite"
|
||||
|
||||
|
||||
## exec
|
||||
|
|
|
|||
Loading…
Reference in a new issue