Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Appmonitor CLI client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
Appmonitor CLI client
Commits
56ca81ba
Commit
56ca81ba
authored
2 months ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
amcli v0.2 slack notification as hash from ini; check params can be an hash value or JSON
parent
c460fd11
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/amcli.php
+20
-16
20 additions, 16 deletions
src/amcli.php
src/simple.ini
+10
-8
10 additions, 8 deletions
src/simple.ini
with
30 additions
and
24 deletions
src/amcli.php
+
20
−
16
View file @
56ca81ba
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
*
*
* ---------------------------------------------------------------------
* ---------------------------------------------------------------------
* 2025-03-04 v0.1 Initial version
* 2025-03-04 v0.1 Initial version
* 2025-03-05 v0.2 slack notification as hash from ini; check params can be an hash value or JSON
* ======================================================================
* ======================================================================
*/
*/
...
@@ -181,9 +182,14 @@ if (!file_exists($inifile)) {
...
@@ -181,9 +182,14 @@ if (!file_exists($inifile)) {
exit
(
4
);
exit
(
4
);
}
}
$aIni
=
parse_ini_file
(
$inifile
,
true
);
try
{
if
(
!
is_array
(
$aIni
))
{
$aIni
=
parse_ini_file
(
$inifile
,
true
);
}
catch
(
Exception
$e
)
{
echo
"ERROR: INI File '
$inifile
' could not be parsed.
\n
"
;
echo
"ERROR: INI File '
$inifile
' could not be parsed.
\n
"
;
exit
(
5
);
}
if
(
!
is_array
(
$aIni
))
{
echo
"ERROR: INI File '
$inifile
' could not be parsed as array.
\n
"
;
exit
(
5
);
exit
(
5
);
}
}
...
@@ -199,12 +205,7 @@ _set("setTtl", $aIni['meta']['ttl'] ?? null);
...
@@ -199,12 +205,7 @@ _set("setTtl", $aIni['meta']['ttl'] ?? null);
foreach
(
$aIni
[
'notifications'
][
'email'
]
??
[]
as
$sValue
)
{
foreach
(
$aIni
[
'notifications'
][
'email'
]
??
[]
as
$sValue
)
{
_set
(
"addEmail"
,
$sValue
);
_set
(
"addEmail"
,
$sValue
);
}
}
foreach
(
$aIni
[
'notifications'
][
'slack'
]
??
[]
as
$sValue
)
{
foreach
(
$aIni
[
'notifications'
][
'slack'
]
??
[]
as
$sChannel
=>
$sWebhook
)
{
$aArray
=
json_decode
(
$sValue
,
1
);
$sChannel
=
array_keys
(
$aArray
)[
0
];
$sWebhook
=
array_values
(
$aArray
)[
0
];
_set
(
"addSlackWebhook"
,
$sChannel
,
$sWebhook
);
_set
(
"addSlackWebhook"
,
$sChannel
,
$sWebhook
);
}
}
...
@@ -215,16 +216,20 @@ $aChecks = $aIni;
...
@@ -215,16 +216,20 @@ $aChecks = $aIni;
unset
(
$aChecks
[
"meta"
]);
unset
(
$aChecks
[
"meta"
]);
unset
(
$aChecks
[
"notifications"
]);
unset
(
$aChecks
[
"notifications"
]);
$aArray
=
[];
foreach
(
$aChecks
as
$sKey
=>
$aCheck
)
{
foreach
(
$aChecks
as
$sKey
=>
$aCheck
)
{
$aChecks
[
$sKey
][
'name'
]
=
$aCheck
[
'name'
]
??
$sKey
;
$aChecks
[
$sKey
][
'name'
]
=
$aCheck
[
'name'
]
??
$sKey
;
if
(
$aCheck
[
'params'
])
{
$aArray
=
$aCheck
[
'params'
]
??
[];
$aArray
=
json_decode
(
$aCheck
[
'params'
],
1
);
if
(
$aArray
)
{
if
(
!
is_array
(
$aArray
))
{
if
(
!
is_array
(
$aCheck
[
'params'
])){
echo
"ERROR: key 'params' for check [
$sKey
] must be JSON.
\n
"
;
$aArray
=
json_decode
(
$aCheck
[
'params'
],
1
);
echo
"Value in
$inifile
:
$aCheck[params]
\n
"
;
if
(
!
is_array
(
$aArray
))
{
exit
(
6
);
echo
"ERROR: key 'params' for check [
$sKey
] must be JSON.
\n
"
;
echo
"Value in
$inifile
:
$aCheck[params]
\n
"
;
exit
(
6
);
}
}
}
}
else
{
$aArray
=
[];
}
}
$aAddCheck
=
[
$aAddCheck
=
[
...
@@ -242,7 +247,6 @@ foreach ($aChecks as $sKey => $aCheck) {
...
@@ -242,7 +247,6 @@ foreach ($aChecks as $sKey => $aCheck) {
}
}
_wd
(
"Execute Check '
$sKey
': "
.
print_r
(
$aAddCheck
,
1
));
_wd
(
"Execute Check '
$sKey
': "
.
print_r
(
$aAddCheck
,
1
));
$oMonitor
->
addCheck
(
$aAddCheck
);
$oMonitor
->
addCheck
(
$aAddCheck
);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/simple.ini
+
10
−
8
View file @
56ca81ba
...
@@ -27,20 +27,22 @@ email[]="support@example.com"
...
@@ -27,20 +27,22 @@ email[]="support@example.com"
email
[]
="webmaster@example.com"
email
[]
="webmaster@example.com"
; for slack use the following format
; for slack use the following format
; <channelname> + comma + <webhook url>
slack
["#support-channel"]
="https://hooks.slack.com/services/XXXXXX/YYYYYY/ZZZZZ"
; slack[]="#support-channel,https://hooks.slack.com/services/XXXXXX/YYYYYY/ZZZZZ"
slack
[]
='{
"
#support-channel": "https://hooks.slack.com/services/XXXXXX/YYYYYY/ZZZZZ" }'
; -----------------------------------------------------------------------
; -----------------------------------------------------------------------
; CHECKS
; CHECKS
; -----------------------------------------------------------------------
; -----------------------------------------------------------------------
["hello plugin"]
["hello plugin"]
description
=
"I
s
ust wann say hello"
description
=
"I
j
ust wann say hello"
function
=
"hello"
function
=
"hello"
params
=
'{
"message":
"Here
I
am"
; JSON example ... variables cannot be expanded
}'
; params='{
; "message": "Here I am"
; }'
;
; ... but in double quotes the expansion works
params
[message]
="Here
is
${USER}"
; -----------------------------------------------------------------------
; -----------------------------------------------------------------------
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment