Suppose you want to run the following SQL insert statement as an alert action for Teradata system TEST1.
This example applies only to core hours.
INSERT INTO admin.sessionHist (TheTime, UserName, SessionCount) VALUES (CURRENT_TIMESTAMP, ${userName}, ${sessionsForUser})
This insert is to be performed when the session count for any user on the TEST1 system exceeds ten.
Notice the alert properties ${userName} and ${sessionsForUser} in the insert statement before. When you configure an alert action to run SQL statements using the SQL Queries delivery type, the text can include alert properties that replaces with runtime values. See Teradata Alert Metrics and Properties for a description of the alert properties available for Teradata Viewpoint alert types.
For this example, assume the target table (admin.sessionHist) has already been created on TEST1. For example:
CREATE TABLE admin.sessionHist (TheTime TIMESTAMP NOT NULL, UserName VARCHAR(256) NOT NULL, SessionCount INTEGER NOT NULL)
To configure an SQL statement as an alert action for a Teradata system, perform these steps.
- In the Alert Setup portlet, configure the login credentials for TEST1.
- From the Setup Options list, select Delivery Settings.
- From the Authentication list, select Teradata Login.
- Select next to Teradata Login.
- In the TDPID box, type the TDPID of the TEST1 system.
- Select the Enable login check box.
- Enter a login name and password.
- From the Session Character Set list, select UTF8.
- [Optional] From the Test Teradata Logon list, select JDBC.
- [Optional] Select Test to verify the login settings are correct.
- Click Apply.
- In the Alert Setup portlet, configure the SQL query for TEST1.
- From the Setup Options list, select Delivery Settings.
- From the Delivery Types list, select SQL Queries.
- Select next to SQL Queries
- In NAME, type insertSessionHistory.
- Select the Enable check box.
- In SQL, type:
INSERT INTO admin.sessionHist (TheTime, UserName, SessionCount) VALUES (CURRENT_TIMESTAMP, ${userName}, ${sessionsForUser})
- Click Apply.
- In the Alert Setup portlet, create an Action Set.
- From the Setup Options list, select Alert Presets.
- From the Preset Options list, select Action Sets.
- Select next to Action Sets.
- In Action Set Name, type runSessionCount.
- From the Times list, select the Core check box, and clear both the Evening and Weekend check boxes.
- Under Actions, make sure the Include in Alert Viewer check box is selected.This option is selected by default so you can view alerts for this action set in the Alert Viewer portlet.
- From the Actions list, select the SQL check box.
- From the Query list, select insertSessionHistory.
- From the TDPID list, select TEST1.
- Click Apply.
- In the Monitored Systems portlet for Teradata Viewpoint monitoring, configure TEST1.
- Next to Systems, select , then select Add Teradata System.
- In System Nickname, type TEST1.
- Select the Enable system check box to activate the TEST1 system for monitoring.
- In the TDPID box, type the TDPID of the TEST1 system.
- Enter a login name and password.
- Click Apply.
- In the Monitored Systems portlet, configure the data collectors.
- From the Systems list, select TEST1.
- From the Setup list, select Data Collectors.
- From the Data Collectors list, select Sessions.
- Select the Enable Sessions Collector check box and keep the default settings.
- Click Apply.
- In the Monitored Systems portlet, define alert rules.
- From the Systems list, select TEST1.
- From the Setup list, select Alerts.
- From the Alert Types list, select Session.
- Click next to Alerts.
- In Alert Name, type userSessionCountAlert.
- Select the Enabled alert check box.
- From the Severity list, select High.
- From the Match list, select All.
- From the lists, select Sessions Per User and is greater than.
- In the empty box after the lists, type the threshold number 10.
- From the Action list, select runSessionCount.
- Click Apply.
- If no single user on TEST1 has more than ten sessions, then create the conditions for the alert to be raised by opening 11 sessions for a Teradata user.For example, using BTEQ:
.set sessions 11 .logon TEST1/myUser,myPassword
- On the TEST1 system, review the sessionHist table. Use a query tool such as BTEQ or SQL Scratchpad to query the table.For example:
select * from admin.sessionHist order by TheTime
You may need to wait a few minutes for the alert to be triggered, depending on the Teradata session monitoring rate on TEST1. - In the Alert Viewer portlet, review triggered actions.