Private GIT
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
centreon
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
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vlbox
centreon
Commits
983f457a
Commit
983f457a
authored
Aug 24, 2017
by
qgarnier
Committed by
Kev
Aug 24, 2017
Browse files
Options
Downloads
Patches
Plain Diff
fix(broker): fix generation of default broker values
External fields are now properly exported Refs: #5461
parent
2d8f70d9
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
www/class/config-generate/broker.class.php
+160
-0
160 additions, 0 deletions
www/class/config-generate/broker.class.php
with
160 additions
and
0 deletions
www/class/config-generate/broker.class.php
+
160
−
0
View file @
983f457a
...
@@ -81,9 +81,33 @@ class Broker extends AbstractObjectXML
...
@@ -81,9 +81,33 @@ class Broker extends AbstractObjectXML
protected
$stmt_broker
=
null
;
protected
$stmt_broker
=
null
;
protected
$stmt_broker_parameters
=
null
;
protected
$stmt_broker_parameters
=
null
;
protected
$stmt_engine_parameters
=
null
;
protected
$stmt_engine_parameters
=
null
;
protected
$cacheExternalValue
=
null
;
private
function
getExternalValues
()
{
global
$pearDB
;
if
(
!
is_null
(
$this
->
cacheExternalValue
))
{
return
;
}
$this
->
cacheExternalValue
=
array
();
$stmt
=
$this
->
backend_instance
->
db
->
prepare
(
"SELECT
CONCAT(cf.fieldname, '_', cttr.cb_tag_id, '_', ctfr.cb_type_id) as name, external FROM cb_field cf, cb_type_field_relation ctfr, cb_tag_type_relation cttr
WHERE cf.external IS NOT NULL
AND cf.cb_field_id = ctfr.cb_field_id
AND ctfr.cb_type_id = cttr.cb_type_id
"
);
$stmt
->
execute
();
while
((
$row
=
$stmt
->
fetch
(
PDO
::
FETCH_ASSOC
)))
{
$this
->
cacheExternalValue
[
$row
[
'name'
]]
=
$row
[
'external'
];
}
}
private
function
generate
(
$poller_id
,
$localhost
)
private
function
generate
(
$poller_id
,
$localhost
)
{
{
$this
->
getExternalValues
();
if
(
is_null
(
$this
->
stmt_broker
))
{
if
(
is_null
(
$this
->
stmt_broker
))
{
$this
->
stmt_broker
=
$this
->
backend_instance
->
db
->
prepare
(
"SELECT
$this
->
stmt_broker
=
$this
->
backend_instance
->
db
->
prepare
(
"SELECT
$this->attributes_select
$this->attributes_select
...
@@ -148,6 +172,15 @@ class Broker extends AbstractObjectXML
...
@@ -148,6 +172,15 @@ class Broker extends AbstractObjectXML
# Flow parameters
# Flow parameters
foreach
(
$resultParameters
as
$key
=>
$value
)
{
foreach
(
$resultParameters
as
$key
=>
$value
)
{
// We search the BlockId
$blockId
=
0
;
for
(
$i
=
count
(
$value
);
$i
>
0
;
$i
--
)
{
if
(
$value
[
$i
][
'config_key'
]
==
'blockId'
)
{
$blockId
=
$value
[
$i
][
'config_value'
];
break
;
}
}
foreach
(
$value
as
$subvalue
)
{
foreach
(
$value
as
$subvalue
)
{
if
(
!
isset
(
$subvalue
[
'fieldIndex'
])
||
if
(
!
isset
(
$subvalue
[
'fieldIndex'
])
||
$subvalue
[
'fieldIndex'
]
==
""
||
$subvalue
[
'fieldIndex'
]
==
""
||
...
@@ -168,6 +201,13 @@ class Broker extends AbstractObjectXML
...
@@ -168,6 +201,13 @@ class Broker extends AbstractObjectXML
}
else
{
}
else
{
$object
[
$subvalue
[
'config_group_id'
]][
$key
][
$subvalue
[
'config_key'
]]
=
$object
[
$subvalue
[
'config_group_id'
]][
$key
][
$subvalue
[
'config_key'
]]
=
$subvalue
[
'config_value'
];
$subvalue
[
'config_value'
];
// We override with external values
if
(
isset
(
$this
->
cacheExternalValue
[
$subvalue
[
'config_key'
]
.
'_'
.
$blockId
]))
{
$object
[
$subvalue
[
'config_group_id'
]][
$key
][
$subvalue
[
'config_key'
]]
=
$this
->
getInfoDb
(
$this
->
cacheExternalValue
[
$subvalue
[
'config_key'
]
.
'_'
.
$blockId
]);
}
// Let broker insert in index data in pollers
// Let broker insert in index data in pollers
if
(
$subvalue
[
'config_key'
]
==
'type'
&&
$subvalue
[
'config_value'
]
==
'storage'
if
(
$subvalue
[
'config_key'
]
==
'type'
&&
$subvalue
[
'config_value'
]
==
'storage'
&&
!
$localhost
)
{
&&
!
$localhost
)
{
...
@@ -230,4 +270,124 @@ class Broker extends AbstractObjectXML
...
@@ -230,4 +270,124 @@ class Broker extends AbstractObjectXML
{
{
$this
->
generate
(
$poller
[
'id'
],
$poller
[
'localhost'
]);
$this
->
generate
(
$poller
[
'id'
],
$poller
[
'localhost'
]);
}
}
/*
* Duplicate code from CentreonConfigCentreonBroker class.
* Need to remove it when we are going to have pdo system with a class
*/
private
function
getInfoDb
(
$string
)
{
/*
* Default values
*/
$s_db
=
"centreon"
;
$s_rpn
=
null
;
/*
* Parse string
*/
$configs
=
explode
(
':'
,
$string
);
foreach
(
$configs
as
$config
)
{
if
(
strpos
(
$config
,
'='
)
==
false
)
{
continue
;
}
list
(
$key
,
$value
)
=
explode
(
'='
,
$config
);
switch
(
$key
)
{
case
'D'
:
$s_db
=
$value
;
break
;
case
'T'
:
$s_table
=
$value
;
break
;
case
'C'
:
$s_column
=
$value
;
break
;
case
'F'
:
$s_filter
=
$value
;
break
;
case
'K'
:
$s_key
=
$value
;
break
;
case
'CK'
:
$s_column_key
=
$value
;
break
;
case
'RPN'
:
$s_rpn
=
$value
;
break
;
}
}
/*
* Construct query
*/
if
(
!
isset
(
$s_table
)
||
!
isset
(
$s_column
))
{
return
false
;
}
$query
=
"SELECT `"
.
$s_column
.
"` FROM `"
.
$s_table
.
"`"
;
if
(
isset
(
$s_column_key
)
&&
isset
(
$s_key
))
{
$query
.
=
" WHERE `"
.
$s_column_key
.
"` = '"
.
$s_key
.
"'"
;
}
/*
* Execute the query
*/
switch
(
$s_db
)
{
case
'centreon'
:
$db
=
$this
->
backend_instance
->
db
;
break
;
case
'centreon_storage'
:
$db
=
$this
->
backend_instance
->
db_cs
;
break
;
}
$stmt
=
$db
->
prepare
(
$query
);
$stmt
->
execute
();
$infos
=
array
();
while
((
$row
=
$stmt
->
fetch
(
PDO
::
FETCH_ASSOC
)))
{
$val
=
$row
[
$s_column
];
if
(
!
is_null
(
$s_rpn
))
{
$val
=
$this
->
rpnCalc
(
$s_rpn
,
$val
);
}
$infos
[]
=
$val
;
}
if
(
count
(
$infos
)
==
0
)
{
return
""
;
}
elseif
(
count
(
$infos
)
==
1
)
{
return
$infos
[
0
];
}
return
$infos
;
}
private
function
rpnCalc
(
$rpn
,
$val
)
{
if
(
!
is_numeric
(
$val
))
{
return
$val
;
}
try
{
$val
=
array_reduce
(
preg_split
(
'/\s+/'
,
$val
.
' '
.
$rpn
),
array
(
$this
,
'rpnOperation'
)
);
return
$val
[
0
];
}
catch
(
InvalidArgumentException
$e
)
{
return
$val
;
}
}
private
function
rpnOperation
(
$result
,
$item
)
{
if
(
in_array
(
$item
,
array
(
'+'
,
'-'
,
'*'
,
'/'
)))
{
if
(
count
(
$result
)
<
2
)
{
throw
new
InvalidArgumentException
(
'Not enough arguments to apply operator'
);
}
$a
=
$result
[
0
];
$b
=
$result
[
1
];
$result
=
array
();
$result
[
0
]
=
eval
(
"return
$a
$item
$b
;"
);
}
elseif
(
is_numeric
(
$item
))
{
$result
[]
=
$item
;
}
else
{
throw
new
InvalidArgumentException
(
'Unrecognized symbol '
.
$item
);
}
return
$result
;
}
}
}
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
sign in
to comment