New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issues57 - groundwork for monitoring #429
Closed
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
666ca1e
added in the monitor manager and cli module. only basic functionality…
allmightyspiff 098fbd3
cleaning up pep8 complaints
allmightyspiff 01f8ae3
cleaning up pep8 complaints
allmightyspiff d8b9a48
add virtual_guest status and tests
allmightyspiff 09b22cc
Merge branch 'master' into issues57
allmightyspiff fc1b6ce
more changes to make pep8 happy
allmightyspiff e4be3e0
making pep8 happy
allmightyspiff b199918
code cleanup
allmightyspiff 6dff823
Merge branch 'master' into issues57
allmightyspiff 82e4d1b
Merge branch 'master' of https://github.com/softlayer/softlayer-pytho…
allmightyspiff 041299e
cleaned up the monitor status, and merged in master
allmightyspiff f335a58
changed some formatting on the status output. fixed unit tests
allmightyspiff 532e783
improving monitoring unit tests
allmightyspiff 948dee4
Merge branch 'master' of https://github.com/softlayer/softlayer-pytho…
allmightyspiff e2e2a8d
refactoring monitor manager to have 2 distinct managers for virtual a…
allmightyspiff File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Monitoring""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
""" | ||
usage: sl monitor [<command>] [<args>...] [options] | ||
|
||
Manage Monitoring. | ||
|
||
The available commands are: | ||
status Show basic monitoring status of servers | ||
""" | ||
|
||
import click | ||
|
||
import SoftLayer | ||
from SoftLayer.CLI import environment | ||
from SoftLayer.CLI import formatting | ||
from SoftLayer import utils | ||
|
||
|
||
@click.command() | ||
@click.option('--only_hardware', is_flag=True, | ||
help="Show only physical servers") | ||
@click.option('--only_virtual', is_flag=True, | ||
help="Show only virtual servers") | ||
@environment.pass_env | ||
def cli(env, only_hardware=False, only_virtual=False): | ||
"""shows SERVER_PING status of all servers.""" | ||
|
||
table = formatting.Table([ | ||
'id', 'datacenter', 'FQDN', 'IP', | ||
'status', 'Type', 'last checked at' | ||
]) | ||
hw_manager = SoftLayer.HardwareMonitorManager(env.client) | ||
vs_manager = SoftLayer.VSMonitorManager(env.client) | ||
if only_virtual: | ||
hardware = [] | ||
guest = vs_manager.list_status() | ||
elif only_hardware: | ||
hardware = hw_manager.list_status() | ||
guest = [] | ||
else: | ||
hardware = hw_manager.list_status() | ||
guest = vs_manager.list_status() | ||
|
||
results = hardware + guest | ||
for server_object in results: | ||
server = utils.NestedDict(server_object) | ||
for monitor in server['networkMonitors']: | ||
try: | ||
res = monitor['lastResult']['responseStatus'] | ||
date = monitor['lastResult']['finishTime'] | ||
ip_address = monitor['ipAddress'] | ||
monitor_type = monitor['queryType']['name'] | ||
except KeyError: | ||
# if a monitor does't have the lastResult ususally it is | ||
# still being provisioned | ||
res = 0 | ||
date = "--" | ||
ip_address = None | ||
monitor_type = "--" | ||
|
||
status = 'UNKNOWN' | ||
status_color = None | ||
if res == 0: | ||
status = 'DOWN' | ||
status_color = 'red' | ||
elif res == 1: | ||
status = 'WARNING' | ||
status_color = 'yellow' | ||
elif res == 2: | ||
status = 'OK' | ||
status_color = 'green' | ||
|
||
table.add_row([ | ||
server['id'], | ||
server['datacenter']['name'] or formatting.blank(), | ||
server['fullyQualifiedDomainName'], | ||
ip_address or formatting.blank(), | ||
click.style(status, fg=status_color), | ||
monitor_type, | ||
date | ||
]) | ||
|
||
return table |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
""" | ||
SoftLayer.managers.monitor | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
:license: MIT, see LICENSE for more details. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
""" | ||
SoftLayer.monitor.hw_monitor | ||
~~~~~~~~~~~~~~~~~~ | ||
Monitoring Manager/helpers for Hardware_Server | ||
|
||
:license: MIT, see LICENSE for more details. | ||
""" | ||
|
||
|
||
class HardwareMonitorManager(object): | ||
"""Manages monitoring for Hardware Servers | ||
|
||
:param SoftLayer.API.CLient client: an API client instance | ||
""" | ||
|
||
def __init__(self, client): | ||
self.client = client | ||
self.account = self.client['Account'] | ||
self.server = self.client['Hardware_Server'] | ||
|
||
def list_status(self, **kwargs): | ||
"""List all hardware with their monitoring status | ||
|
||
:param dict \\*\\*kwargs: response-level options (mask, limit, filter) | ||
:returns: Retrns a list of dictionaries with server and monitoring | ||
information. | ||
""" | ||
|
||
vs_items = [ | ||
'id', | ||
'fullyQualifiedDomainName', | ||
'primaryBackendIpAddress', | ||
'primaryIpAddress', | ||
'datacenter', | ||
'networkMonitors[lastResult,queryType]' | ||
] | ||
|
||
kwargs['mask'] = ('[mask[%s]]' | ||
% (','.join(vs_items))) | ||
return self.account.call('getHardware', **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
""" | ||
SoftLayer.monitor.vs_monitor | ||
~~~~~~~~~~~~~~~~~~ | ||
Monitoring Manager/helpers for Virtual_Guest | ||
|
||
:license: MIT, see LICENSE for more details. | ||
""" | ||
|
||
|
||
class VSMonitorManager(object): | ||
"""Manages monitoring for Virtual Servers | ||
|
||
:param SoftLayer.API.CLient client: an API client instance | ||
""" | ||
|
||
def __init__(self, client): | ||
self.client = client | ||
self.account = self.client['Account'] | ||
self.server = self.client['Virtual_Guest'] | ||
|
||
def list_status(self, **kwargs): | ||
"""List all virtual guests with their monitoring status | ||
|
||
:param dict \\*\\*kwargs: response-level options (mask, limit, filter) | ||
:returns: Retrns a list of dictionaries with server and monitoring | ||
information. | ||
""" | ||
|
||
vs_items = [ | ||
'id', | ||
'fullyQualifiedDomainName', | ||
'primaryBackendIpAddress', | ||
'primaryIpAddress', | ||
'datacenter', | ||
'networkMonitors[lastResult,queryType]' | ||
] | ||
|
||
kwargs['mask'] = ('[mask[%s]]' | ||
% (','.join(vs_items))) | ||
return self.account.call('getVirtualGuests', **kwargs) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
""" | ||
SoftLayer.tests.managers.monitor_tests | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
:license: MIT, see LICENSE for more details. | ||
""" | ||
import SoftLayer | ||
from SoftLayer import testing | ||
|
||
|
||
class MonitorTests(testing.TestCase): | ||
|
||
def set_up(self): | ||
self.hw_monitor_manager = SoftLayer.HardwareMonitorManager(self.client) | ||
self.vs_monitor_manager = SoftLayer.VSMonitorManager(self.client) | ||
|
||
def test_list_status(self): | ||
result = self.run_command(['monitor', 'status']) | ||
self.assertEqual(result.exit_code, 0) | ||
self.assert_called_with('SoftLayer_Account', 'getVirtualGuests') | ||
self.assert_called_with('SoftLayer_Account', 'getHardware') | ||
|
||
def test_list_only_hardware(self): | ||
result = self.run_command(['monitor', 'status', '--only_hardware']) | ||
self.assert_called_with('SoftLayer_Account', 'getHardware') | ||
self.assertEqual(result.exit_code, 0) | ||
|
||
def test_list_only_virtual(self): | ||
result = self.run_command(['monitor', 'status', '--only_virtual']) | ||
self.assert_called_with('SoftLayer_Account', 'getVirtualGuests') | ||
self.assertEqual(result.exit_code, 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
""" | ||
SoftLayer.tests.managers.monitor_tests | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
:license: MIT, see LICENSE for more details. | ||
""" | ||
import SoftLayer | ||
from SoftLayer import testing | ||
from SoftLayer.testing import fixtures | ||
|
||
|
||
class MonitorTests(testing.TestCase): | ||
|
||
def set_up(self): | ||
self.hw_monitor_manager = SoftLayer.HardwareMonitorManager(self.client) | ||
self.vs_monitor_manager = SoftLayer.VSMonitorManager(self.client) | ||
|
||
def test_list_hardware_status(self): | ||
result = self.hw_monitor_manager.list_status() | ||
self.assertEqual(result, fixtures.SoftLayer_Account.getHardware) | ||
self.assert_called_with('SoftLayer_Account', 'getHardware') | ||
|
||
def test_list_guest_status(self): | ||
result = self.vs_monitor_manager.list_status() | ||
self.assertEqual(result, fixtures.SoftLayer_Account.getVirtualGuests) | ||
self.assert_called_with('SoftLayer_Account', 'getVirtualGuests') |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be more explicit, maybe it's better to do this instead:
The way it works now, a key error for another value could happen and subsequently hidden.