Skip to content

A simple Bash program for retrieving basic information from ESXi hosts and writing the information to HTML file.

Notifications You must be signed in to change notification settings

iisti/esxi_info

Repository files navigation

ESXi Info

  • This is a simple Bash program for retrieving basic information from ESXi hosts and writing the information into a HTML file.
  • The program can connect both free and licensed ESXi hosts.
  • The project has been tested on couple different Linux distros and Windows Subsystem Linux.
  • Example output can be seen in https://htmlpreview.github.io/?https://github.com/iisti/esxi_info/blob/main/dev_tests/test_index.html
    • Yes, the output is a bit ugly duckling, but well there's a lot of basic information easily available, which makes managing ESXis easier if the vCenter is unavailable.

Example use cases

  1. Mikko has 4 servers running ESXI hypervisors. Some virtual machines are shutdown and some are powered on. Mikko's household has a power outage. After getting power back Mikko can easily check from the HTML file generated by this program what was running on which ESXi hosts.
  2. Olavi has 3 servers running ESXi hypervisors. Olavi is not sure which ESXi host has free memory and storage. Olavi can see from the generated HTML file which host(s) have free resources.
  3. Bob's vCenter has crashed and he doesn't know on which ESXi host the vCenter was running on. Bob can look from the HTML file on which ESXi the vCenter was running.

How to use

  • Tested with couple distors of Linux and WSL (Windows Sub-system Linux)
  1. Clone the repo in shell. If you want the HTML file to be easily accessed in Windows, it might be good idea to use path similar to /mnt/c/something.
    git clone https://github.com/iisti/esxi_info.git
    
  2. Edit config.conf file
    • Add the hostnames/IPs of ESXis.
    • (Optional) Add the paths of your SSH keys, both private and public.
  3. Run the script
    ./get_esxi_info.bash
    

Test run

  • You can check how the program works by running a test run with some example files.
  1. In esxi_info Git project folder, create configuration file config.conf with content:
    host: hostname1
    host: hostname2
    host: hostname3
    require_sudo: no
    
  2. Copy test content to esxi_infos directory.
    cp -r dev_test esxi_infos
    
  3. Run the script.
    ./get_esxi_info.bash
    
    • Output should be something like below.
      • There will be errors of SSH key files do not exist and that hostnames can't be resolved. This is expected behavior.
    Reading configuration from file:
        INFO: No esxi_output_path given. Using default: /mnt/c/esxi_info/esxi_infos/
    Parsed configuration:
        ESXis: hostname1 hostname2 hostname3
        SSH key:
        WWW dir: /mnt/c/esxi_info/www/
        ESXi output path: /mnt/c/esxi_info/esxi_infos/
        Require sudo: no
    Checking that ESXis can be connected via SSH
        hostname1
        ERROR: Warning: Identity file  not accessible: No such file or directory.
    ssh: Could not resolve hostname hostname1: Name or service not known
        hostname2
        ERROR: Warning: Identity file  not accessible: No such file or directory.
    ssh: Could not resolve hostname hostname2: Name or service not known
        hostname3
        ERROR: Warning: Identity file  not accessible: No such file or directory.
    ssh: Could not resolve hostname hostname3: Name or service not known
    Error: None of the ESXis configured in /mnt/c/esxi_info/config.conf could be connected!
    Retrieving and generating information of ESXis via SSH:
    Appending ESXi information to HTML page
        hostname1
        hostname2
        hostname3
    Using WSL (Windows Subsystem for Linux): 4.4.0-19041-Microsoft
    
  4. An example output of the HTML page can be seen in https://htmlpreview.github.io/?https://github.com/iisti/esxi_info/blob/main/dev_tests/test_index.html

Automation

  • You can automate program to run perodically by creating SSH keys for connecting to the ESXi hosts and creating a cronjob for running the program perodically.
  1. Create SSH keys, for example with command below

    sudo ssh-keygen -t rsa -b 4096 -C "user_or_whatever_is_wanted_for_identifying_the_key"
    
  2. Add the SSH keys to authorized_keys list on ESXis by running script add_sshkey_to_esxi.bash or you can add them manually also.

  3. Add to crontab, change the paths to whatever suits. This example is run on WSL.

    # You can also use some other text editor than vim, like nano.
    sudo vim /etc/crontab
    
    # Line to add to crontab. cron syntax can be found from https://en.wikipedia.org/wiki/Cron
    21 15 * * * root sudo /mnt/c/esxi_info/get_esxi_info.bash > /mnt/c/esxi_info/logs/log.txt
    #
    
  4. If using WSL (Windows Subsystem Linux), remember to start cron! One needs to have the WSL running all the time!

    # Start cron
    sudo service cron start
    # Check that cron is running
    pgrep cron
    

About

A simple Bash program for retrieving basic information from ESXi hosts and writing the information to HTML file.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published