Giter Club home page Giter Club logo

vcenter-register-owner-alarm-script's Introduction

Register Owner or Creator of a Virtual Machine upon creation in VMware vSphere

This is a script for setting the owner and creation date of a Virtual Machine upon creation or deployment

The script is meant to be run by an alarm set in vCenter.

The script can be placed almost anywhere on your vCenter Appliance, but I recommend placing it in "/root/alarmscripts"

Prerequisites

You need to create a user that has access to set custom attributes vCenter tree. Normally set in the top of the tree (On the vCenter object) You should create a custom role for this limit the users permissions as much as possible in case the account gets compromised.

TODO

  • Create a Role in vCenter
  • Create a User or use existing user
  • Give the user access to set custom attributes by using the new role
  • Copy the script to vCenter
  • Change the username and password variables in the script to suit your needs or enable password obfuscation and run the script from the console to create the secrets file
  • Set the correct file rights on the file to prohibit non root users from reading the service account password
  • Create the custom attribute in vCenter. The script can do it automatically, but the default role does not have access
  • Create the trigger alarm
  • Test by Creating a new vm
  • Test by Deploying a new vm from a template or ovf

Notes

  • The alarm does not work for VM created from a clone.

vCenter Role - Example

Role Name Rule Privileges
Set Custom Attributes Global -> Set custom attribute

vCenter User - Example

Username Permission Path Role Propagate to children
[email protected] vCenter Object Set Custom Attributes YES

Setting Script Permisssions

chmod 700 /root/alarmscripts/vm.alarm.new-vm.py
chmod 700 /root/alarmscripts/retrieve_information.py

Alarm Comfigurations

Setting Value
Alarm Name Add Creator Information to Virtual Machine on Creation
Target Type Virtual Machines
Alarm 1 - Rule Trigger Creating VM
Alarm 1 - Trigger the alarm and Keep the target's current starte
Alarm 1 - Run Script Enabled
Alarm 1 - Run this Script /root/alarmscripts/vm.alarm.new-vm.py
Alarm 2 - Rule Trigger Deploying VM
Alarm 2 - Trigger the alarm and Keep the target's current starte
Alarm 2 - Run Script Enabled
Alarm 2 - Run this Script /root/alarmscripts/vm.alarm.new-vm.py

Troubleshooting

The custom attribute is not set, or does not exists on the VM. You need to manually crete the custom attribute in vCenter.

Credits

I did take inspiration from Bryan McClellan and MARK III SYSTEMS BLOG.

I just didn't like the python code, and I wanted to improve it a little. If you need inspiration building the alarms have a look at Mark's blog.

Links

vcenter-register-owner-alarm-script's People

Contributors

knutssondevelopment avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.