===========< id
uid=1000(nutanix) gid=1000(nutanix) groups=1000(nutanix),160(snmp),600(java),990(docker)context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
===========< uname -a
Linux ntnx-20sm6k250202-c-cvm 3.10.0-1062.12.1.el7.nutanix.20200216.cvm.x86_64 #1 SMP Sun Feb 16 07:02:50 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
===========< hostssh date
============= 10.55.87.27 ============
Sat Dec 12 11:17:09 UTC 2020
============= 10.55.87.25 ============
Sat Dec 12 11:17:10 UTC 2020
============= 10.55.87.26 ============
Sat Dec 12 11:17:10 UTC 2020
===========< hostssh uptime
============= 10.55.87.27 ============
11:17:12 up 1 day, 9:40, 0 users, load average: 1.90, 2.36, 2.38
============= 10.55.87.25 ============
11:17:12 up 1 day, 9:41, 0 users, load average: 6.04, 6.07, 5.98
============= 10.55.87.26 ============
11:17:12 up 1 day, 9:41, 0 users, load average: 1.47, 1.69, 1.80
===========< ncli cluster info
Cluster Id : 0005b626-72dd-8051-3f5b-ac1f6b3d7d4b::4565431898213285195
Cluster Uuid : 0005b626-72dd-8051-3f5b-ac1f6b3d7d4b
Cluster Name : RTP-POC087
Cluster Version : 5.15
Cluster Full Version : el7.3-release-euphrates-5.15-stable-4fbdd4d9de331230bb468b3549f530e80ab53bb9
・ ・ ・ The following is omitted
Regarding the setting image of X-Play, you may be able to imagine the video around here as a demo. It would be nice to be able to create an automation mechanism without coding.
https://www.youtube.com/watch?v=UmAWG0UHpuU
The nice thing about Nutanix is that you can understand it even if you don't understand English.
X-Play can automatically take various actions triggered by alerts and schedules on Nutanix. You can also combine it.
Various things (typical). I can do more and more every day. When I saw it a while ago, it increased again.
VM power ON / Off
Take a snapshot of the VM
Add or remove resources
Send email / Notify Slack
Report creation
etc
Furthermore, you can execute scripts as shown below, so you can do anything depending on the combination. So for Linux, command from ssh. In the case of Windows, it feels like you can run Powershell, so you can kick python in it.
SSH to command execution
Run Powershell
Run REST API
The figure below is a playbook that "takes a backup (snapshot)", "adds CPU", and "emails the administrator" when the "VM CPU usage alert" goes up.
Just click from this list of actions
You can do this kind of flow. Super easy.
id
uname -a
hostssh date
hostssh uptime
ncli cluster info
ncli host ls
ncli cluster get-domain-fault-tolerance-status type=node
ncli alert history duration=14
ncli license get-license
ncli license get-allowances
cluster status
zeus_config_printer
nodetool -h 0 ring
.id
uname -a
/usr/local/nutanix/cluster/bin/hostssh date
/usr/local/nutanix/cluster/bin/hostssh uptime
/home/nutanix/prism/cli/ncli cluster info
/home/nutanix/prism/cli/ncli host ls
/home/nutanix/prism/cli/ncli cluster get-domain-fault-tolerance-status type=node
/home/nutanix/prism/cli/ncli alert history duration=14
/home/nutanix/prism/cli/ncli license get-license
/home/nutanix/prism/cli/ncli license get-allowances
/usr/local/nutanix/cluster/bin/cluster status
/usr/local/nutanix/bin/zeus_config_printer
Script overview
Get the list of commands listed from the Nutanix cluster
Divert the script created before https://qiita.com/matsumo2019/items/0713dd70bcdc91e2690f Prepare by referring to this page.
Preparation items (super omitted)
Python installation
Install paramiko
Script to create (Refer to the above article. The script is put at the end.)
get-cvm.py: Main processing
my_command.py: Classified paramiko processing
common.json (configuration file. CVM IP, ID, password)
command_list.txt (write a list of commands to be executed) * Basically edit only this file
By the way, I had never touched Python, but I could make it by looking at this book.
Learn the basics in just one day! Introduction to Python https://a.r10.to/hbHMiv
Setting flow
From Prism Central, select "Menu"> "Operations"> "Playbook"
"Create Playbook"
Trigger selection / setting
Action selection / setting
Repeat adding actions
This is a specific setting screen.
"Create Playbook"
Some are created by default, so you can refer to them.
"Trigger selection"
Select "Alerts Matching Criteria".
"Trigger selection"
Select "Alerts Matching Criteria" and select the alert condition.
"Select Action"
Select "VM Powershell".
Set the following.
Target VM: The server that executes the script * Username * Password
Path to Script: Specify the script on the server to be executed in the format including the path
Save and save with a playbook name.
Enable status if you want to enable it immediately
This completes the X-Play settings.
The command result was obtained with the alert as a trigger.
Execution result (Prism Central side)
You can check the execution result and error of the playbook.
You can also see the error. I'm having trouble connecting in this case (it was Windows Firewall ...)
Execution result (script server side)
When an event occurs like this, the execution result is automatically saved.
Contents of the execution result file (as expected)
id
uname -a
/usr/local/nutanix/cluster/bin/hostssh date
/usr/local/nutanix/cluster/bin/hostssh uptime
/home/nutanix/prism/cli/ncli cluster info
/home/nutanix/prism/cli/ncli host ls
/home/nutanix/prism/cli/ncli cluster get-domain-fault-tolerance-status type=node
/home/nutanix/prism/cli/ncli alert history duration=14
/home/nutanix/prism/cli/ncli license get-license
/home/nutanix/prism/cli/ncli license get-allowances
/usr/local/nutanix/cluster/bin/cluster status
/usr/local/nutanix/bin/zeus_config_printer
{
"cluster_address": "10.55.87.31",
"user_name": "nutanix",
"cvm_password": "nutanix/4u"
}
import json
import my_command
#Read file
fin = open('command_list.txt', 'r')
json_open = open('cvm_info.json', 'r')
#Read command list
fin = open('command_list.txt', 'r')
command = fin.readlines()
fin.close()
#Read server information
sv_info = json.load(json_open)
cluster_ip = sv_info['cluster_address']
user_name = sv_info['user_name']
password = sv_info['cvm_password']
##Command execution (main processing)
def main():
for name in command:
print('===========<', name)
remote_obj = my_command.RemoteCommand()
ret = remote_obj.get_df(cluster_ip, user_name, password, name)
print(ret)
##Main processing (magic)
if __name__ == '__main__':
main()
import paramiko
class RemoteCommand:
def get_df(self, ip, user, password, command):
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(ip, username=user, password=password, timeout=3.0)
(stdin, stdout, stderr) = client.exec_command(command, get_pty=True)
output = stdout.read().decode()
client.close()
return output
cmd.exe /c "c:\scripts\get_cvm_cmd.bat"
@echo off
set yyyy=%date:~0,4%
set mm=%date:~5,2%
set dd=%date:~8,2%
set time2=%time: =0%
set hh=%time2:~0,2%
set mn=%time2:~3,2%
set ss=%time2:~6,2%
set filename=%yyyy%-%mm%%dd%-%hh%%mn%%ss%
cmd.exe /c "c:\scripts\get_cvm_cmd.py > logs\log_%filename%.txt
Location
Just put it in the same place.
Reflection
I couldn't set the environment variables, so I'm embarrassed that I couldn't write with the full path or use allssh.
Around Powershell, I cut my hand ... Shame
Tell someone
Recommended Posts