Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
configuration
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
configuration
Commits
904fed2a
Commit
904fed2a
authored
Sep 03, 2015
by
Edward Zarecor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip
parent
6e808107
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
8 deletions
+73
-8
playbooks/library/mms_alert.py
+73
-8
No files found.
playbooks/library/mms_alert.py
View file @
904fed2a
...
...
@@ -15,6 +15,7 @@ EXAMPLES = '''
from
ansible.module_utils.basic
import
*
import
json
from
json
import
JSONEncoder
import
requests
class
CloudManagerClient
(
object
):
...
...
@@ -31,15 +32,34 @@ class CloudManagerClient(object):
def
put
():
pass
def
post
():
pass
def
post
(
self
,
path
,
data
):
api_target
=
self
.
base_url
+
path
return
json
.
dumps
(
data
,
cls
=
MyEncoder
)
#r = requests.post(api_target, auth=self.http_digest_auth, data=data)
def
delete
():
pass
class
Alert
(
object
):
def
__init
(
self
,
id
,
group_id
,
alert_config_id
,
type_name
,
event_type_name
,
status
):
class
ArgumentError
(
Exception
):
pass
#
# TODO: make work recursively
# TODO: make export the models
#
class
CommonEqualityMixin
(
object
):
def
__eq__
(
self
,
other
):
return
(
isinstance
(
other
,
self
.
__class__
)
and
self
.
__dict__
==
other
.
__dict__
)
def
__ne__
(
self
,
other
):
return
not
self
.
__eq__
(
other
)
class
Alert
(
CommonEqualityMixin
):
def
__init__
(
self
,
id
,
group_id
,
alert_config_id
,
type_name
,
event_type_name
,
status
):
self
.
id
=
id
self
.
group_id
=
group_id
self
.
alert_config_id
=
alert_config_id
...
...
@@ -48,30 +68,75 @@ class Alert(object):
self
.
status
=
status
class
AlertConfiguration
(
object
):
class
AlertConfiguration
(
CommonEqualityMixin
):
def
__init__
(
self
,
group_id
,
type_name
,
event_type_name
,
enabled
,
matchers
,
notifications
):
self
.
group_id
=
group_id
self
.
type_name
=
type_name
self
.
event_type_name
=
event_type_name
self
.
enabled
=
enabled
self
.
matchers
=
matchers
self
.
notifications
=
notifications
class
AlertMatcher
(
CommonEqualityMixin
):
def
__init__
(
self
,
field_name
,
operator
,
value
):
self
.
field_name
=
field_name
self
.
operator
=
operator
self
.
value
=
value
class
AlertNotification
(
object
):
def
__init__
(
self
,
type_name
,
email_address
,
interval_min
,
delay_min
):
self
.
type_name
=
type_name
;
self
.
email_address
=
email_address
self
.
interval_min
=
interval_min
self
.
delay_min
=
delay_min
class
MyEncoder
(
JSONEncoder
):
def
default
(
self
,
o
):
return
o
.
__dict__
def
create_or_update_alert_config
(
client
):
matcher0
=
AlertMatcher
(
"foo"
,
"bar"
,
"baz"
)
notification0
=
AlertNotification
(
"EMAIL"
,
"ed@example.com"
,
60
,
5
)
alert0
=
AlertConfiguration
(
"foo"
,
"REPLICA_SET"
,
"RESYNC_REQUIRED"
,
True
,
[],
[])
class
ArgumentError
(
Exception
):
pass
matcher1
=
AlertMatcher
(
"foo"
,
"bar"
,
"baz"
)
notification1
=
AlertNotification
(
"EMAIL"
,
"ed@example.com"
,
60
,
5
)
alert1
=
AlertConfiguration
(
"foo"
,
"REPLICA_SET"
,
"RESYNC_REQUIRED"
,
True
,
[],
[])
raise
Exception
(
alert0
==
alert1
)
return
client
.
post
(
'/groups/1111/alertConfigs'
,
alert0
)
def
main
():
arg_spec
=
dict
(
state
=
dict
(
required
=
True
,
type
=
'str'
),
base_url
=
dict
(
required
=
True
,
type
=
'str'
),
group_id
=
dict
(
required
=
True
,
type
=
'str'
),
api_user
=
dict
(
required
=
True
,
type
=
'str'
),
api_key
=
dict
(
required
=
True
,
type
=
'str'
),
matchers
=
dict
(
type
=
'list'
),
notifications
=
dict
(
type
=
'list'
),
)
module
=
AnsibleModule
(
argument_spec
=
arg_spec
,
supports_check_mode
=
False
)
state
=
module
.
params
.
get
(
'state'
)
base_url
=
module
.
params
.
get
(
'base_url'
)
group_id
=
module
.
params
.
get
(
'group_id'
)
api_user
=
module
.
params
.
get
(
'api_user'
)
api_key
=
module
.
params
.
get
(
'api_key'
)
matchers
=
module
.
params
.
get
(
'matchers'
)
notifications
=
module
.
params
.
get
(
'notifications'
)
c
=
CloudManagerClient
(
base_url
,
group_id
,
api_user
,
api_key
)
module
.
exit_json
(
api_output
=
c
.
get
(
'/groups/{group_id}/alertConfigs'
.
format
(
group_id
=
group_id
)))
create_or_update_alert_config
(
c
)
#module.exit_json(api_output = c.get('/groups/{group_id}/alertConfigs'.format(group_id=group_id)))
module
.
exit_json
(
api_output
=
create_or_update_alert_config
(
c
))
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment