Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
Imldeployment
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
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
Imldeployment
Commits
aa14b1ed
Commit
aa14b1ed
authored
6 years ago
by
hahn
Browse files
Options
Downloads
Patches
Plain Diff
update foreman class: fetch response infos for better debugging
parent
29df4d11
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
public_html/deployment/classes/foremanapi.class.php
+103
-4
103 additions, 4 deletions
public_html/deployment/classes/foremanapi.class.php
with
103 additions
and
4 deletions
public_html/deployment/classes/foremanapi.class.php
+
103
−
4
View file @
aa14b1ed
...
...
@@ -114,8 +114,18 @@ class ForemanApi {
);
/**
* last request
* @var type
*/
protected
$_aRequest
=
array
();
/**
* last response
* @var type
*/
protected
$_aResponse
=
array
();
// ----------------------------------------------------------------------
// constructor
...
...
@@ -144,8 +154,10 @@ class ForemanApi {
*/
protected
function
log
(
$sMessage
,
$sLevel
=
"info"
)
{
global
$oCLog
;
if
(
$oCLog
&&
method_exists
(
$oLog
,
'add'
)){
return
$oCLog
->
add
(
basename
(
__FILE__
)
.
" class "
.
__CLASS__
.
" - "
.
$sMessage
,
$sLevel
);
}
}
/**
* search url prefix in $this->_aAllowedUrls by given key
...
...
@@ -228,6 +240,7 @@ class ForemanApi {
if
(
$aRequest
){
$this
->
_aRequest
=
$aRequest
;
}
$this
->
_aResponse
=
array
();
$this
->
log
(
__FUNCTION__
.
" start <pre>"
.
print_r
(
$this
->
_aRequest
,
1
)
.
"</pre>"
);
if
(
!
function_exists
(
"curl_init"
))
{
die
(
"ERROR: PHP CURL module is not installed."
);
...
...
@@ -262,7 +275,6 @@ class ForemanApi {
$aReturn
=
array
(
'info'
=>
curl_getinfo
(
$ch
),
'error'
=>
curl_error
(
$ch
));
curl_close
(
$ch
);
$this
->
log
(
__FUNCTION__
.
" status "
.
$aReturn
[
'info'
][
'http_code'
]
.
' '
.
$this
->
_aRequest
[
'method'
]
.
"
$sFullUrl
"
);
$sHeader
=
substr
(
$res
,
0
,
$aReturn
[
'info'
][
'header_size'
]);
$aReturn
[
'header'
]
=
explode
(
"
\n
"
,
$sHeader
);
$aReturn
[
'body'
]
=
str_replace
(
$sHeader
,
""
,
$res
);
...
...
@@ -333,7 +345,7 @@ class ForemanApi {
// check status
$iStatuscode
=
$aReturn
[
'info'
][
'http_code'
];
if
(
$iStatuscode
===
0
){
$sStatus
=
'wrong host'
;
$sStatus
=
'wrong host
or no connect
'
;
}
if
(
$iStatuscode
>=
200
&&
$iStatuscode
<
400
){
$sStatus
=
'OK'
;
...
...
@@ -363,6 +375,7 @@ class ForemanApi {
$aReturn
[
'_OK'
]
=
$bOk
;
$aReturn
[
'_status'
]
=
$sStatus
;
$this
->
_writeDebug
(
__FUNCTION__
.
' result of request <pre>'
.
print_r
(
$aReturn
,
1
)
.
'</pre>'
);
$this
->
_aResponse
=
$aReturn
;
return
$aReturn
;
}
...
...
@@ -513,4 +526,90 @@ class ForemanApi {
*/
}
// ----------------------------------------------------------------------
// get response infos
// ----------------------------------------------------------------------
/**
* get curl info data from last response
* Array
(
[url] => https://foreman/api/hostgroups/?&per_page=1000
[content_type] => application/json; charset=utf-8
[http_code] => 200
[header_size] => 1034
[request_size] => 218
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 1.644417
[namelookup_time] => 0.007198
[connect_time] => 0.009012
[pretransfer_time] => 0.0332
[size_upload] => 0
[size_download] => 119602
[speed_download] => 72732
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => 0
[starttransfer_time] => 1.642775
[redirect_time] => 0
[redirect_url] =>
[primary_ip] => 10.0.2.10
[certinfo] => Array
(
)
[primary_port] => 443
[local_ip] => 10.0.2.15
[local_port] => 33906
)
* @param string $sKey get value of given key only
* @return any
*/
public
function
getResponseInfo
(
$sKey
=
false
){
if
(
$sKey
){
return
isset
(
$this
->
_aResponse
[
'info'
][
$sKey
])
?
$this
->
_aResponse
[
'info'
][
$sKey
]
:
false
;
}
return
isset
(
$this
->
_aResponse
[
'info'
])
?
$this
->
_aResponse
[
'info'
]
:
false
;
/*
return isset($sKey) && $sKey
? isset($this->_aResponse['info'][$sKey])
? $this->_aResponse['info'][$sKey]
: false
: isset($this->_aResponse['info'])
? $this->_aResponse['info']
: false
;
*/
}
/**
* get array of last http response header
* @return array
*/
public
function
getResponseHeader
(){
return
isset
(
$this
->
_aResponse
[
'header'
])
?
$this
->
_aResponse
[
'header'
]
:
false
;
}
/**
* get status of last request
* @return string
*/
public
function
getResponseStatus
(){
// print_r($this->_aResponse); die();
return
isset
(
$this
->
_aResponse
[
'_status'
])
?
$this
->
_aResponse
[
'_status'
]
:
false
;
}
}
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