Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
brian-polling-manager
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
geant-swd
brian
brian-polling-manager
Commits
26728296
Commit
26728296
authored
4 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
test env skeleton
parent
55bf5f85
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
brian_polling_manager/__init__.py
+0
-0
0 additions, 0 deletions
brian_polling_manager/__init__.py
brian_polling_manager/cli.py
+120
-0
120 additions, 0 deletions
brian_polling_manager/cli.py
brian_polling_manager/sensu.py
+41
-0
41 additions, 0 deletions
brian_polling_manager/sensu.py
with
161 additions
and
0 deletions
brian_polling_manager/__init__.py
0 → 100644
+
0
−
0
View file @
26728296
This diff is collapsed.
Click to expand it.
brian_polling_manager/cli.py
0 → 100644
+
120
−
0
View file @
26728296
import
json
import
logging
import
re
import
click
import
jsonschema
from
brian_polling_manager
import
sensu
logger
=
logging
.
getLogger
(
__name__
)
_DEFAULT_CONFIG
=
{
'
inventory
'
:
[
'
http://test-inventory-provider01.geant.org:8080
'
,
'
http://test-inventory-provider02.geant.org:8080
'
],
'
sensu
'
:
{
'
api-base
'
:
[
'
https://test-poller-sensu-agent01.geant.org:8080
'
,
'
https://test-poller-sensu-agent02.geant.org:8080
'
,
'
https://test-poller-sensu-agent03.geant.org:8080
'
],
'
token
'
:
'
696a815c-607e-4090-81de-58988c83033e
'
}
}
CONFIG_SCHEMA
=
{
'
$schema
'
:
'
http://json-schema.org/draft-07/schema#
'
,
'
definitions
'
:
{
'
sensu
'
:
{
'
type
'
:
'
object
'
,
'
properties
'
:
{
'
api-base
'
:
{
'
type
'
:
'
array
'
,
'
items
'
:
{
'
type
'
:
'
string
'
},
'
minItems
'
:
1
},
'
token
'
:
{
'
type
'
:
'
string
'
}
}
}
},
'
type
'
:
'
object
'
,
'
properties
'
:
{
'
inventory
'
:
{
'
type
'
:
'
array
'
,
'
items
'
:
{
'
type
'
:
'
string
'
},
'
minItems
'
:
1
},
'
sensu
'
:
{
'
$ref
'
:
'
#/definitions/sensu
'
}
},
'
required
'
:
[
'
inventory
'
,
'
sensu
'
],
'
additionalProperties
'
:
False
}
def
_validate_config
(
ctx
,
param
,
value
):
"""
loads, validates and returns configuration parameters
:param ctx:
:param param:
:param value: filename (string)
:return: a dict containing configuration parameters
"""
if
value
is
None
:
config
=
_DEFAULT_CONFIG
else
:
try
:
with
open
(
value
)
as
f
:
config
=
json
.
loads
(
f
.
read
())
except
(
json
.
JSONDecodeError
,
jsonschema
.
ValidationError
)
as
e
:
raise
click
.
BadParameter
(
str
(
e
))
try
:
jsonschema
.
validate
(
config
,
CONFIG_SCHEMA
)
except
jsonschema
.
ValidationError
as
e
:
raise
click
.
BadParameter
(
str
(
e
))
return
config
@click.command
()
@click.option
(
'
--config
'
,
default
=
None
,
type
=
click
.
STRING
,
callback
=
_validate_config
,
help
=
'
configuration filename
'
)
def
main
(
config
):
def
_categorize_ifc_check
(
check
):
name
=
check
[
'
metadata
'
][
'
name
'
]
m
=
re
.
match
(
r
'
^check-([^-]+\.geant\.net)-(.+)$
'
,
name
)
if
not
m
:
return
None
return
{
'
hostname
'
:
m
.
group
(
1
),
'
interface
'
:
m
.
group
(
2
),
'
check
'
:
check
}
ifc_checks
=
{}
for
check
in
filter
(
None
,
map
(
_categorize_ifc_check
,
sensu
.
load_all_checks
(
config
[
'
sensu
'
]))):
host_checks
=
ifc_checks
.
setdefault
(
check
[
'
hostname
'
],
{})
if
check
[
'
interface
'
]
in
host_checks
:
other_check
=
host_checks
[
check
[
'
interface
'
]]
other_name
=
other_check
[
'
metadata
'
][
'
name
'
]
this_name
=
check
[
'
metadata
'
][
'
name
'
]
logger
.
warning
(
f
'
found both
{
this_name
}
and
{
other_name
}
'
)
host_checks
[
check
[
'
interface
'
]]
=
check
[
'
check
'
]
for
host
,
interfaces
in
ifc_checks
.
items
():
print
(
host
)
for
ifc
,
check
in
interfaces
.
items
():
name
=
check
[
'
metadata
'
][
'
name
'
]
print
(
f
'
\t
{
ifc
}
:
{
name
}
'
)
if
__name__
==
'
__main__
'
:
main
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
brian_polling_manager/sensu.py
0 → 100644
+
41
−
0
View file @
26728296
"""
Sensu api utilities
"""
import
random
import
requests
def
load_all_checks
(
params
):
url
=
random
.
choice
(
params
[
'
api-base
'
])
# url = params['api-base'][0]
r
=
requests
.
get
(
f
'
{
url
}
/api/core/v2/namespaces/default/checks
'
,
headers
=
{
'
Authorization
'
:
f
'
Key
{
params
[
"
token
"
]
}
'
,
'
Accepts
'
:
'
application/json
'
,
})
r
.
raise_for_status
()
for
check
in
r
.
json
():
yield
check
#
# def snmp_counter_checks(all_checks):
# for c in all_checks:
#
# assert c['command']
# items = c['command'].split()
# if len(items) < 6:
# continue
# if not items.pop(0).endswith('counter2influx.sh'):
# continue
#
# yield {
# 'hostname': items[3],
# 'interface_name': items[4],
# 'interval': c['interval'],
# 'name': c['metadata']['name']
# }
#
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