Thursday, April 5, 2012

Custom scripts to monitor Siebel using OMS user defined metrics

In this post, I describe how to create user defined metrics in hosts.
The following scripts will raise alerts, whenever something's wrong.

IBM HTTP Server:
#!/bin/sh
PS=`ps -ef|grep "HTTPServer -k start"|grep -v grep|wc -l`

echo em_result=$PS
if test $PS -lt 4
then
echo em_message='Apache is down. Processes='$PS
else
echo em_message='Apache is up. Processes='$PS
fi

Oracle BI Publisher:
#!/bin/sh
PS=`ps -ef|grep oc4j_bi|grep java|grep -v grep|wc -l`

echo em_result=$PS
if test $PS -ne 1
then
echo em_message='BI Publisher is down. Processes='$PS
else
echo em_message='BI Publisher is up. Processes='$PS
fi

Gateway Server:
#!/bin/sh
PS=`ps -ef|grep gtwyns|grep -v grep|wc -l`

echo em_result=$PS
if test $PS -ne 1
then
echo em_message='Gateway is down. Processes='$PS
else
echo em_message='Gateway is up. Processes='$PS
fi

Siebel Server:
server.cfg:
spool server.lst
list server show SBLSRVR_NAME,HOST_NAME,SBLSRVR_STATE,START_TIME,END_TIME
exit

Main script [Insert your env. variables' values]:
export SIEBEL_HOME=
export SIEBGATE=
export SIEBENT=
export SADMINPWD=
export WORKDIR=
export HOST_NAME=

. $SIEBEL_HOME/siebenv.sh

cd $WORKDIR

cat /dev/null>server.lst

srvrmgr /g $SIEBGATE /e $SIEBENT /u sadmin /p $SADMINPWD /s $HOST_NAME /i server.cfg 1>/dev/null

GREP=`grep Running server.lst |wc -l`
echo em_result=$GREP

if test $GREP -lt 1
    then
                echo em_message='Siebel Server is down.'
        else
                echo em_message='Siebel Server is up.'
fi

Siebel Components:
comp.cfg:
spool comp.lst
list comp show SV_NAME,CC_ALIAS,CC_NAME,CP_DISP_RUN_STATE,CP_START_TIME,CP_END_TIME
exit

Main script [Insert your env. variables' values]:

export SIEBEL_HOME=
export SIEBGATE=
export SIEBENT=
export SADMINPWD=
export WORKDIR=
export HOST_NAME=

. $SIEBEL_HOME/siebenv.sh

cd $WORKDIR

cat /dev/null>comp.lst

srvrmgr /g $SIEBGATE /e $SIEBENT /u sadmin /p $SADMINPWD /s $HOST_NAME /i comp.cfg 1>/dev/null

GREP=`egrep '(Unavailable|Shutdown)' comp.lst |wc -l`
echo em_result=$GREP

if test $GREP -gt 0
    then
                echo em_message=$GREP' Components down.'
        else
                echo em_message='Components are OK.'
fi

You may use OMS 11g preinstalled Siebel plugin, instead, although I haven't seen anything about components' status. You only get informed, if gateway or Siebel servers are up or down.
If you choose to use this plugin, make sure agent's OS user has the same primary group as Siebel's OS user. Oracle had to open Bug 13849748 for me, until I discovered that this was needed, since it is not mentioned in any documentation.
Also agent messes with /tmp/regss* files, taking their ownership and crashing, sometimes, the gateway server. Remove "${MWHOME}/bin/regautobackup -off" from your siebenv.sh files to correct this.

Thursday, March 29, 2012

Logon trigger to forbid unauthorized logins

There was a need to stop some unauthorized logins in our database, attempted by some specific users.
First, we create a table to record those logins:
CREATE TABLE HELPDESK.FAILED_LOGINS
(
   USERNAME   VARCHAR2 (30 BYTE),
   OSUSER     VARCHAR2 (30 BYTE),
   TERMINAL   VARCHAR2 (30 BYTE),
   IP         VARCHAR2 (64 BYTE),
   MODULE     VARCHAR2 (48 BYTE),
   TIME       DATE
);

CREATE INDEX HELPDESK.FAILED_LOGINS_IDX
   ON HELPDESK.FAILED_LOGINS (TIME);

The following trigger will check some database users and will allow only specific os users to login.
CREATE OR REPLACE TRIGGER SYS.AUTH_LOGIN
   AFTER LOGON
   ON DATABASE
DECLARE
BEGIN
   IF DBMS_STANDARD.LOGIN_USER IN
         ('APPS',
          'APPLSYS',
          'AP',
          'AR',
          'AX',
          'GL',
          'INV',
          'ONT',
          'PO',
          'HR',
          'XXFSM')
      AND SYS_CONTEXT ('USERENV', 'OS_USER') NOT IN ('oracle', 'oracol')
   THEN
      INSERT INTO HELPDESK.FAILED_LOGINS (USERNAME,
                                          OSUSER,
                                          TERMINAL,
                                          IP,
                                          MODULE,
                                          TIME)
           VALUES (DBMS_STANDARD.LOGIN_USER,
                   SYS_CONTEXT ('USERENV', 'OS_USER'),
                   SYS_CONTEXT ('USERENV', 'TERMINAL'),
                   SYS_CONTEXT ('USERENV', 'IP_ADDRESS'),
                   SYS_CONTEXT ('USERENV', 'MODULE'),
                   SYSDATE);

      COMMIT;
      RAISE_APPLICATION_ERROR (-20001, 'Unauthorized login');
   END IF;
END;
/

We try to login as APPS and we are not allowed:
SQL> CONN APPS@COLDB_RP1
Enter password: ****
ERROR:
ORA-00604: error occurred at recursive SQL level 1
ORA-20001: Unauthorized login
ORA-06512: at line 31

The attempt is recorded:
SQL> SELECT * FROM HELPDESK.FAILED_LOGINS;

USERNAMEOSUSERTERMINALIPMODULELTIME
APPSetsekourasETSEKOUR10.100.25.60sqlplusw.exe29-MAR-12

If I add my os username in the trigger, I am allowed access:
SQL> CONN APPS@COLDB_RP1
Enter password: ****
Connected.

Sunday, March 18, 2012

ORA-01114: File reported not found in dba_data_files and v$datafile

We got an ORA-01114 error:
ORA-01114: IO error writing block to file  (block # )
ORA-01114: IO error writing block to file 5006 (block # 755027)

There is no file with FILE_ID = 5006 in dba_ data_files of with file#=5006 in v$datafile:
SQL> SELECT * FROM DBA_DATA_FILES WHERE FILE_ID = 5006;
no rows selected

SQL> SELECT * FROM V$DATAFILE WHERE FILE# = 5006;
no rows selected

That's, because the datafile associated with this error belongs to a temporary tablespace (temp file) and information about temp files is stored in dba_temp_files and v$tempfile.

To find your temp file, you need to find the value of initialization parameter "db_files":
SQL> SELECT NAME, VALUE FROM V$PARAMETER WHERE NAME = 'db_files';
NAME          VALUE
------------  -----
db_files      5000

In our case, the temp file is the one with file_id equal to 5006-5000 = 6.
The following queries will return temp file's info:
SELECT *
FROM DBA_TEMP_FILES
WHERE FILE_ID = 5006 - (SELECT VALUE FROM V$PARAMETER WHERE NAME='db_files');

SELECT *
FROM V$TEMPFILE
WHERE FILE# = 5006 - (SELECT VALUE FROM V$PARAMETER WHERE NAME='db_files');