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
f78c0092
Commit
f78c0092
authored
4 weeks ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
v0.6 add meta tags, check count+visual; add _json2array()
parent
f832b925
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/amcli.php
+37
-15
37 additions, 15 deletions
src/amcli.php
tests/configs/apacheprocesses.ini
+1
-1
1 addition, 1 deletion
tests/configs/apacheprocesses.ini
tests/configs/metadata.ini
+2
-1
2 additions, 1 deletion
tests/configs/metadata.ini
with
40 additions
and
17 deletions
src/amcli.php
+
37
−
15
View file @
f78c0092
...
@@ -11,6 +11,8 @@
...
@@ -11,6 +11,8 @@
* 2025-03-05 v0.2 slack notification as hash from ini; check params can be an hash value or JSON
* 2025-03-05 v0.2 slack notification as hash from ini; check params can be an hash value or JSON
* 2025-03-07 v0.3 set argc and argv from $_SERVER; update help output
* 2025-03-07 v0.3 set argc and argv from $_SERVER; update help output
* 2025-03-09 v0.4 more colors in output of debug and help
* 2025-03-09 v0.4 more colors in output of debug and help
* 2025-03-14 v0.5 add build infos
* 2025-03-14 v0.6 add meta tags, check count+visual; add _json2array()
* ======================================================================
* ======================================================================
*/
*/
...
@@ -147,6 +149,25 @@ You find example snippets in the source code of this project in tests/config/.
...
@@ -147,6 +149,25 @@ You find example snippets in the source code of this project in tests/config/.
"
;
"
;
}
}
/**
* JSON helper:
* If a given value is a JSON string then return an array, otherwise return the value
*
* @param mixed $value
* @return mixed
*/
function
_json2array
(
mixed
$value
=
null
):
mixed
{
if
(
!
is_string
(
$value
))
{
return
$value
;
}
$aArray
=
json_decode
(
$value
,
1
);
if
(
is_array
(
$aArray
)){
_wd
(
"JSON found in
\n
$value
\n
... and was converted to an array: "
.
print_r
(
$aArray
,
1
));
}
return
is_array
(
$aArray
)
?
$aArray
:
$value
;
}
// --------------------------------------------------------------------
// --------------------------------------------------------------------
//
//
// MAIN
// MAIN
...
@@ -256,6 +277,10 @@ if (!is_array($aIni)) {
...
@@ -256,6 +277,10 @@ if (!is_array($aIni)) {
_wd
(
"Parsed INI data: "
.
print_r
(
$aIni
,
1
));
_wd
(
"Parsed INI data: "
.
print_r
(
$aIni
,
1
));
// loop over all values and detect JSON strings to convert
$aIni
[
'meta'
][
'tags'
]
=
_json2array
(
$aIni
[
'meta'
][
'tags'
]
??
null
);
$aIni
[
'notifications'
][
'email'
]
=
_json2array
(
$aIni
[
'notifications'
][
'email'
]
??
null
);
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
// set metadata
// set metadata
...
@@ -263,6 +288,10 @@ _set("setHost", $aIni['meta']['host'] ?? null);
...
@@ -263,6 +288,10 @@ _set("setHost", $aIni['meta']['host'] ?? null);
_set
(
"setWebsite"
,
$aIni
[
'meta'
][
'website'
]
??
null
);
_set
(
"setWebsite"
,
$aIni
[
'meta'
][
'website'
]
??
null
);
_set
(
"setTtl"
,
$aIni
[
'meta'
][
'ttl'
]
??
null
);
_set
(
"setTtl"
,
$aIni
[
'meta'
][
'ttl'
]
??
null
);
foreach
(
$aIni
[
'meta'
][
'tags'
]
??
[]
as
$sValue
)
{
_set
(
"addTag"
,
$sValue
);
}
foreach
(
$aIni
[
'notifications'
][
'email'
]
??
[]
as
$sValue
)
{
foreach
(
$aIni
[
'notifications'
][
'email'
]
??
[]
as
$sValue
)
{
_set
(
"addEmail"
,
$sValue
);
_set
(
"addEmail"
,
$sValue
);
}
}
...
@@ -279,19 +308,12 @@ unset($aChecks["notifications"]);
...
@@ -279,19 +308,12 @@ unset($aChecks["notifications"]);
foreach
(
$aChecks
as
$sKey
=>
$aCheck
)
{
foreach
(
$aChecks
as
$sKey
=>
$aCheck
)
{
$aChecks
[
$sKey
][
'name'
]
=
$aCheck
[
'name'
]
??
$sKey
;
$aChecks
[
$sKey
][
'name'
]
=
$aCheck
[
'name'
]
??
$sKey
;
$aArray
=
$aCheck
[
'params'
]
??
[];
$aParams
=
_json2array
(
$aCheck
[
'params'
]
??
[]);
if
(
$aArray
)
{
if
(
!
is_array
(
$aParams
))
{
if
(
!
is_array
(
$aCheck
[
'params'
]))
{
echo
"❌ ERROR: key 'params' for check [
$sKey
] must be
\n
- a hash or
\n
- valid JSON
\n
- not set
\n
"
;
$aArray
=
json_decode
(
$aCheck
[
'params'
],
1
);
echo
"Value in
$inifile
:
$aCheck[params]
\n
"
;
if
(
!
is_array
(
$aArray
))
{
echo
"Try to use multiple lines 'params[<KEY>]=<VALUE>'.
\n
"
;
echo
"❌ ERROR: key 'params' for check [
$sKey
] must be valid JSON.
\n
"
;
exit
(
6
);
echo
"Value in
$inifile
:
$aCheck[params]
\n
"
;
echo
"OR: Try to use multiple lines 'params[<KEY>]=<VALUE>' instead.
\n
"
;
exit
(
6
);
}
}
}
else
{
$aArray
=
[];
}
}
$aAddCheck
=
[
$aAddCheck
=
[
...
@@ -299,10 +321,10 @@ foreach ($aChecks as $sKey => $aCheck) {
...
@@ -299,10 +321,10 @@ foreach ($aChecks as $sKey => $aCheck) {
"description"
=>
$aCheck
[
'description'
]
??
""
,
"description"
=>
$aCheck
[
'description'
]
??
""
,
"check"
=>
[
"check"
=>
[
"function"
=>
$aCheck
[
'function'
],
"function"
=>
$aCheck
[
'function'
],
"params"
=>
$a
Array
??
[]
,
"params"
=>
$a
Params
,
],
],
];
];
foreach
([
"group"
,
"parent"
,
"worstresult"
]
as
$sCustomKey
)
{
foreach
([
"group"
,
"parent"
,
"worstresult"
,
"count"
,
"visual"
]
as
$sCustomKey
)
{
if
(
isset
(
$aCheck
[
$sCustomKey
]))
{
if
(
isset
(
$aCheck
[
$sCustomKey
]))
{
$aAddCheck
[
$sCustomKey
]
=
$aCheck
[
$sCustomKey
];
$aAddCheck
[
$sCustomKey
]
=
$aCheck
[
$sCustomKey
];
}
}
...
...
This diff is collapsed.
Click to expand it.
tests/configs/apacheprocesses.ini
+
1
−
1
View file @
f78c0092
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
["Apache status"]
["Apache status"]
description
=
"Worker status of Apache httpd"
description
=
"Worker status of Apache httpd"
function
=
"ApacheProcesses"
function
=
"ApacheProcesses"
params
=
;
params=
worstresult
=
0
worstresult
=
0
; -----------------------------------------------------------------------
; -----------------------------------------------------------------------
This diff is collapsed.
Click to expand it.
tests/configs/metadata.ini
+
2
−
1
View file @
f78c0092
...
@@ -19,7 +19,8 @@
...
@@ -19,7 +19,8 @@
host
=
"www.example.com"
host
=
"www.example.com"
website
=
"Company website"
website
=
"Company website"
ttl
=
300
ttl
=
300
tags
[]
="monitoring"
; tags[]="monitoring"
tags
=
'["monitoring"]'
[notifications]
[notifications]
...
...
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