|
| 1 | +#!/usr/bin/env python |
| 2 | +""" |
| 3 | +* ******************************************************* |
| 4 | +* Copyright (c) VMware, Inc. 2019. 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 | +__vcenter_version__ = '6.7+' |
| 17 | + |
| 18 | +from vmware.vapi.vsphere.client import create_vsphere_client |
| 19 | + |
| 20 | +from samples.vsphere.common import (sample_cli, sample_util) |
| 21 | +from samples.vsphere.common.ssl_helper import get_unverified_session |
| 22 | + |
| 23 | + |
| 24 | +class HealthMessages(object): |
| 25 | + """ |
| 26 | + Demonstrates getting Health messages for memory, storage and cpu |
| 27 | +
|
| 28 | + Retrieves Health messages details from vCenter and prints the data |
| 29 | +
|
| 30 | + """ |
| 31 | + |
| 32 | + def __init__(self): |
| 33 | + parser = sample_cli.build_arg_parser() |
| 34 | + |
| 35 | + parser.add_argument( |
| 36 | + '--item', |
| 37 | + required=True, |
| 38 | + action='store', |
| 39 | + choices=['memory', 'cpu', 'storage'], |
| 40 | + help='Specify the name of health item to view the messages') |
| 41 | + |
| 42 | + args = sample_util.process_cli_args(parser.parse_args()) |
| 43 | + self.item = args.item |
| 44 | + # Connect to vAPI services |
| 45 | + session = get_unverified_session() if args.skipverification else None |
| 46 | + self.client = create_vsphere_client(server=args.server, |
| 47 | + username=args.username, |
| 48 | + password=args.password, |
| 49 | + session=session) |
| 50 | + |
| 51 | + def run(self): |
| 52 | + message_list = self.client.appliance.Health.messages(self.item) |
| 53 | + print("Health Alarams") |
| 54 | + print("-------------------\n") |
| 55 | + if not message_list: |
| 56 | + print("No health alarms for : " + self.item) |
| 57 | + else: |
| 58 | + for message in message_list: |
| 59 | + print("Alert time : {}".format(message.time)) |
| 60 | + print("Alert message Id: " + message.id) |
| 61 | + local_message = message.message |
| 62 | + default_msg = local_message.default_message |
| 63 | + print("Alert message : " + default_msg) |
| 64 | + |
| 65 | + |
| 66 | +def main(): |
| 67 | + health_sample = HealthMessages() |
| 68 | + health_sample.run() |
| 69 | + |
| 70 | + |
| 71 | +if __name__ == '__main__': |
| 72 | + main() |
0 commit comments