VMware Cloud Community
vdebaere
Contributor
Contributor
Jump to solution

Hyperic shell: alertdef create whitout questions?

Hi

Since there is no possibility yet to create group alerts, we are looking at scripting the creation of alerts in the hyperic shell. However, alertdef create prompts for values.

Is there a way of creating alerts without having to answer questions in the shell,kind of all-on-one line ?
0 Kudos
1 Solution

Accepted Solutions
john_hyperic
Hot Shot
Hot Shot
Jump to solution

You can script alert creation (and anything else) in the shell, that's
what it was designed for. To do that, create a text file with all the
commands and parameters and pipe it into the shell. Below is an example
of an alert creation in the shell.

hq-shell::hqadmin> alertdef create -platform 10001
Name [default 'New Alert']: test alert 1
Description [default '']: this alert was created using the HQ Shell
Choices:
1: ! - Low
2: !! - Medium
3: !!! - High
Priority [default '2']: 1
Choices:
1: true
2: false
Filter Notifications [default '2']: 2
Choices:
1: true
2: false
Filter Control Actions [default '2']: 2
Choices:
1: Measurement Threshold
2: Measurement Baseline
3: Control Action
4: Measurement Value Change
5: Alert Fired
6: Custom Property Value Change
7: Log Event
Alert Condition Type [default '4']: 1
[ID] NAME
[10142] Availability
[10160] MemFree
[10162] ActualMemFree
[10164] LoadAverage0
[10168] LoadAverage1
[10178] SwapUsed
[10188] TcpInboundConnections
[10190] TcpOutboundConnections
[10216] MemUsed
[10218] ActualMemUsed

Measurement ID [default '10001']: 10188
Choices:
1: <=
2: <<br/> 3: =
4: >
5: >=
6: !=
Comparison operator [default '4']: 5
Threshold value: 120
Do you wish to add additional conditions (Y/N)? n
[ Configure Email Actions ]
Recipient Type ([1] Emails [2] Users [3] Roles) [default '1']: 1
Recipients (comma-delimited Emails or ID's) [default '']: test@alert.com


Now to script that, you take all the things you typed and put each thing
on a line in a text file. So the script for the above would look like:

alertdef create -platform 10001
test alert 1
this alert was created using the HQ Shell
1
2
2
1
10188
5
120
n
1
test@alert.com


To run that script, simply pipe it into the shell like this:

./shell-2.7.x/hq-shell.sh < myscript.txt

Of course, for it to work you would need to add a line at the top to log
in to the shell. You can do that all in one line like this:

login username:password@hostname

Replacing username, password and hostname with the real values for your
environment.

View solution in original post

0 Kudos
11 Replies
john_hyperic
Hot Shot
Hot Shot
Jump to solution

You can script alert creation (and anything else) in the shell, that's
what it was designed for. To do that, create a text file with all the
commands and parameters and pipe it into the shell. Below is an example
of an alert creation in the shell.

hq-shell::hqadmin> alertdef create -platform 10001
Name [default 'New Alert']: test alert 1
Description [default '']: this alert was created using the HQ Shell
Choices:
1: ! - Low
2: !! - Medium
3: !!! - High
Priority [default '2']: 1
Choices:
1: true
2: false
Filter Notifications [default '2']: 2
Choices:
1: true
2: false
Filter Control Actions [default '2']: 2
Choices:
1: Measurement Threshold
2: Measurement Baseline
3: Control Action
4: Measurement Value Change
5: Alert Fired
6: Custom Property Value Change
7: Log Event
Alert Condition Type [default '4']: 1
[ID] NAME
[10142] Availability
[10160] MemFree
[10162] ActualMemFree
[10164] LoadAverage0
[10168] LoadAverage1
[10178] SwapUsed
[10188] TcpInboundConnections
[10190] TcpOutboundConnections
[10216] MemUsed
[10218] ActualMemUsed

Measurement ID [default '10001']: 10188
Choices:
1: <=
2: <<br/> 3: =
4: >
5: >=
6: !=
Comparison operator [default '4']: 5
Threshold value: 120
Do you wish to add additional conditions (Y/N)? n
[ Configure Email Actions ]
Recipient Type ([1] Emails [2] Users [3] Roles) [default '1']: 1
Recipients (comma-delimited Emails or ID's) [default '']: test@alert.com


Now to script that, you take all the things you typed and put each thing
on a line in a text file. So the script for the above would look like:

alertdef create -platform 10001
test alert 1
this alert was created using the HQ Shell
1
2
2
1
10188
5
120
n
1
test@alert.com


To run that script, simply pipe it into the shell like this:

./shell-2.7.x/hq-shell.sh < myscript.txt

Of course, for it to work you would need to add a line at the top to log
in to the shell. You can do that all in one line like this:

login username:password@hostname

Replacing username, password and hostname with the real values for your
environment.

0 Kudos
admin
Immortal
Immortal
Jump to solution

Hi Vincent,

There is also a policy-based alerting feature offered in our
enterprise subscription version that allows you to set alert
definitions for resource types. While it cannot be tailored to
groups, it allows for existing resources and new resources of the
same type to have alert definitions be automatically be created and
modified uniformly.

Charles


0 Kudos
vdebaere
Contributor
Contributor
Jump to solution

Thanks clee & john.

While I was awear of the way john suggested, I wanted to make sure there was no other way (which would not require the additional step of creating/sed'ing a file).

As far as the enterprise subscription version is concerned, it will be considered, but we're still in very early stages with this project... .

Vincent
0 Kudos
Kilka
Contributor
Contributor
Jump to solution

Hey folks,

I've tried this in windows to no avail. It would appear that after the alertdef command is called, the remaining values are not put in the shell, rather all of the defaults are selected because carriage return keeps getting fed to hq-shell.bat. I get the following error as alertdef is expecting an email address.

Recipients (comma-delimited Emails or ID's) [default '']: names must be at least 1 characters long

I suspect it's because alertdef prompts for values in a non-standard way..

Does anyone have any ideas? I have the same problem when I try and script this from ruby.

Cheers,
-Kilka
0 Kudos
john_hyperic
Hot Shot
Hot Shot
Jump to solution

Can you create the alertdef by hand? Does it work with the script if
you specify an email address?

0 Kudos
Kilka
Contributor
Contributor
Jump to solution

Hey John,

Thanks for the quick reply 🙂 hq-shell works fine if I put the values in manually, however when I try and pipe them in like so:

hq-shell.bat<input.txt

I get the error message:
Recipients (comma-delimited Emails or ID's) [default '']: names must be at least 1 characters long

It's like the first two commands being

login hqadmin:hqadmin@localhost
alertdef create -platform 10001

work, and the rest of the prompts are returned....hence the defaults and the blank name.

I'm really stumped here. I tried it on nix bash shell and I had the same problem.

Thanks,
-Kilka
0 Kudos
Kilka
Contributor
Contributor
Jump to solution

Well, it looks like I've found the problem. It would appear that piping the information in using<doesn't give the CLI enough time to react. alertdef takes a moment to prompt for a value, and hence everything was being fed to the console before alertdef could prompt for the values, as such everything was being lost.

I'm writing a script in ruby to deal with this, and it would appear that a sleep 1 command before putting the values into alertdef solves the problem.

Now it makes sense why I was having the same problem in windows and unix alike.

Kind Regards,
-Kilka
0 Kudos
john_hyperic
Hot Shot
Hot Shot
Jump to solution

Wow, good catch. I've never run into this problem myself and was
banging my head on the keyboard trying to figure out why it wasn't
working for you.

0 Kudos
admin
Immortal
Immortal
Jump to solution

Hi Kilka,

You might also script using "expect" in cygwin or on a Unix system so
that you don't have to use an artificial sleep command.

Charles


0 Kudos
Kilka
Contributor
Contributor
Jump to solution

It must be working for you if you have a faster machine...

I've been testing this out on slower machines, and things tend to be a little less than interactive 😐

Cheers,
-Kilka
0 Kudos
gurnani_sunny
Contributor
Contributor
Jump to solution

Hello
I am also having the same problem while running the alertdef command through input redirection.

Can you please send some information how can I code it in java or C#.

Yours Truly
Sunny Gurnani
0 Kudos