|
| 1 | +#!/usr/bin/env python |
| 2 | +""" |
| 3 | +* ******************************************************* |
| 4 | +* Copyright (c) VMware, Inc. 2017. All Rights Reserved. |
| 5 | +* SPDX-License-Identifier: MIT |
| 6 | +* ******************************************************* |
| 7 | +* |
| 8 | +* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT |
| 9 | +* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN, |
| 10 | +* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED |
| 11 | +* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, |
| 12 | +* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. |
| 13 | +""" |
| 14 | + |
| 15 | +__author__ = 'VMware, Inc.' |
| 16 | +__copyright__ = 'Copyright 2017 VMware, Inc. All rights reserved.' |
| 17 | +__vcenter_version__ = '6.7+' |
| 18 | + |
| 19 | +from samples.vsphere.common import sample_cli |
| 20 | +from samples.vsphere.common import sample_util |
| 21 | +from samples.vsphere.common import vapiconnect |
| 22 | +from com.vmware.appliance_client import Health |
| 23 | +from com.vmware.vapi.std_client import LocalizableMessage |
| 24 | + |
| 25 | +class HealthMessages(object) : |
| 26 | + """ |
| 27 | + Demonstrates getting Health messages for various health items |
| 28 | +
|
| 29 | + Retrieves Health messages details from vCenter and prints the data |
| 30 | +
|
| 31 | + """ |
| 32 | + |
| 33 | + |
| 34 | + def __init__(self): |
| 35 | + self.item = None |
| 36 | + self.stub_config = None |
| 37 | + |
| 38 | + def setup(self): |
| 39 | + parser = sample_cli.build_arg_parser() |
| 40 | + parser.add_argument( |
| 41 | + '--item', |
| 42 | + required=True, |
| 43 | + action='store', |
| 44 | + choices=['memory', 'cpu' , 'storage'], |
| 45 | + help='Specify the name of health item to view the messages') |
| 46 | + args = sample_util.process_cli_args(parser.parse_args()) |
| 47 | + self.item = args.item |
| 48 | + |
| 49 | + # Connect to vAPI services |
| 50 | + self.stub_config = vapiconnect.connect( |
| 51 | + host=args.server, |
| 52 | + user=args.username, |
| 53 | + pwd=args.password, |
| 54 | + skip_verification=args.skipverification) |
| 55 | + |
| 56 | + self.health_client = Health(self.stub_config) |
| 57 | + |
| 58 | + def run(self): |
| 59 | + message_list = self.health_client.messages(self.item) |
| 60 | + print(" Health Alarams") |
| 61 | + print("-------------------\n") |
| 62 | + if not message_list: |
| 63 | + print("No health alarms for : " + self.item) |
| 64 | + else: |
| 65 | + for message in message_list : |
| 66 | + print("Alert time : " + message.getTime()) |
| 67 | + print("Alert message Id: " + message.getId()) |
| 68 | + msg = message.getMessage() |
| 69 | + def_message = LocalizableMessage(msg.default_message) |
| 70 | + print("Alert message : "+ def_message) |
| 71 | + |
| 72 | + |
| 73 | +def main(): |
| 74 | + health_sample = HealthMessages() |
| 75 | + health_sample.setup() |
| 76 | + health_sample.run() |
| 77 | + |
| 78 | +if __name__ == '__main__': |
| 79 | + main() |
0 commit comments