Login to the service account on the management server. Create a script called sv-errors (using vi) in the service home directory and paste the following in the file.
#!/usr/bin/expect -f
# connect to vplexcli
spawn vplexcli
# Look for login prompt
expect -re "Name:"
# Send login
send "service\r"
# Look for password prompt
expect -re "Password:"
# Send password - your password if different
send "Mi@Dim7T\r"
expect -re "VPlexcli:/> "
send "storage-volume summary \r"
expect -re "VPlexcli:/> "
expect eof
Set the permissions to executable (chmod 755 sv-errors).
Then run your new command (make sure your logged into the management server not the vplexcli)
./sv-errors | grep error
Note where I placed the command storage-volume summary. You can place any command or sequence of commands using my simple example.
Are you running metro or geo? Try using storage-volume summary -c cluster-1 (or 2) if running metro or geo. You could also sub in your command in my script. The key is the expect script. By using the script from the management server you are able to take advantage of the Linux utilities, like grep and awk to manipulate the output of the vplexcli commands.
doing this via expect is ok, but a better way is to use simple API calls. Though the API might be a little intimidating to a person experienced in shell scripting, it can be used to execute VPLEX CLI commands and feed the output to something for further processing.
I use curl as it is simple to implement once you know how. Below is an example introducing the topic for those of us not used to object programming with Perl or other languages that the API is better suited for.
First for simplicity, create a file called curl.cfg in your home dir. Inside that will be some basic curl options and API headers containing the authentication necessary to execute the API calls. Since the file contains authentication information, the permissions on the file should be so that only the appropriate user(s) can read or copy the file.
array_size=split($4,array,"\\\\n") # split on \n chars (not newline char)
for (outline = 1; outline <= array_size; outline++) {
gsub("\\\\t","\t",array[outline]) # replace \t chars with real tab char
if ( match (array[outline],SEARCH) > 0 ) { printf "%s\n",array[outline] }
}
printf "\n"
}
} ' SEARCH="error"
Note that the command is in the URL but the rest of the command line is in the POST data {"args":"-l ..."}.
Also, for compound commands like "export storage-view addvirtualvolume" would all be in the URL but the spaces would be replaced with "+" as in "export+storage-view+addvirtualvolume"
The output from successful commands is located in the custom-data response field. However, it appears as all one line with "\n" and "\t" strings signifying where newline and tab characters should be. The awk script replaces the strings for both tab and newline characters with the real character and then prints only the line which contains the search string specified at the closing of the awk script.
Note that you can use regex in the search string instead of just a string. For example you could look for specific storage volumes that contained a range of hex in it by changing "error" to "[ABC]38298" which could match A38298,B38298,or C38298. And if you weren't certain about case you could do "[AaBbCc]38298" Or, specify ranges like "[A-D]3829[3-8]"
Intech1
57 Posts
1867
1
Posted December 8th, 2012 17:00
Login to the service account on the management server. Create a script called sv-errors (using vi) in the service home directory and paste the following in the file.
#!/usr/bin/expect -f
# connect to vplexcli
spawn vplexcli
# Look for login prompt
expect -re "Name:"
# Send login
send "service\r"
# Look for password prompt
expect -re "Password:"
# Send password - your password if different
send "Mi@Dim7T\r"
expect -re "VPlexcli:/> "
send "storage-volume summary \r"
expect -re "VPlexcli:/> "
expect eof
Set the permissions to executable (chmod 755 sv-errors).
Then run your new command (make sure your logged into the management server not the vplexcli)
./sv-errors | grep error
Note where I placed the command storage-volume summary. You can place any command or sequence of commands using my simple example.