Skip to main content

Get a notification mail when carbon server throws an error

Last week I encountered problem that how to get a notification when carbon server throws an error during a long running test or in a production environment. Tailing the log is not practical during these kinds of situations, so I google and found a interesting solution.

First you have to install Mailutils package

$ sudo apt-get install mailutils

Create a file called "notify.sh" and paste the following code in to it.

#!/bin/bash

EMAILADDRESS="yourmail@gmail.com"
EMAILSUBJECT="[Important][CARBON] ERROR OCCURRED"
MESSAGEBODY="../repository/logs/errors.txt"
cat /dev/null > $MESSAGEBODY

SEARCHSTRING='ERROR\|Error\|error\|Exception'
SYSLOG=../repository/logs/wso2carbon.log
LASTOCCURANCE=`grep -n "$SEARCHSTRING" $SYSLOG | tail -1`
LASTLINE=`echo $LASTOCCURANCE | cut -d':' -f1`

while true
do

END=`wc -l $SYSLOG | cut -d' ' -f1`
if [ $END -lt $LASTLINE ]
then
        LASTLINE=$END
fi

tail -n +$LASTLINE $SYSLOG | grep "$SEARCHSTRING" > $MESSAGEBODY

if [ `stat -c %s $MESSAGEBODY` -ne '0' -a $LASTLINE -ne $END ]
then

        mail -s "$EMAILSUBJECT" "$EMAILADDRESS" < $MESSAGEBODY

        ((LASTLINE=$LASTLINE+1))
fi

LASTLINE=$END
mv $MESSAGEBODY ../repository/logs/old_errors.txt
cat /dev/null > $MESSAGEBODY
sleep 300

done


Now change the EMAILADDRESS to the desired email address and copy this "notify.sh" file to your "<CARBON_SERVER>/bin" folder.

Finally run the script,

$ ./notify.sh

In every 5 minutes this script will check the new logs written to "wso2carbon.log" file and will send you a mail if error found. You can change the time gap between each check by changing sleep value of the above script.

Comments

Popular posts from this blog

How to extract and import certificate from a SAML SP metadata file to a Keystore

Extract certificate from the SAML service provider metadata file as follows, <X509Data> <X509Certificate> MIICNTCCAZ6gAwIBAgIES343gjANBgkqhkiG9w0BAQUFADBVMQswCQYDVQQGEwJVUzELMAkGA1UE CAwCQ0ExFjAUBgNVBAcMDU1vdW50YWluIFZpZXcxDTALBgNVBAoMBFdTTzIxEjAQBgNVBAMMCWxv Y2FsaG9zdDAeFw0xMDAyMTkwNzAyMjZaFw0zNTAyMTMwNzAyMjZaMFUxCzAJBgNVBAYTAlVTMQsw CQYDVQQIDAJDQTEWMBQGA1UEBwwNTW91bnRhaW4gVmlldzENMAsGA1UECgwEV1NPMjESMBAGA1UE AwwJbG9jYWxob3N0MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCUp/oV1vWc8/TkQSiAvTou sMzOM4asB2iltr2QKozni5aVFu818MpOLZIr8LMnTzWllJvvaA5RAAdpbECb+48FjbBe0hseUdN5 HpwvnH/DW8ZccGvk53I6Orq7hLCv1ZHtuOCokghz/ATrhyPq+QktMfXnRS4HrKGJTzxaCcU7OQID AQABoxIwEDAOBgNVHQ8BAf8EBAMCBPAwDQYJKoZIhvcNAQEFBQADgYEAW5wPR7cr1LAdq+IrR44i QlRG5ITCZXY9hI0PygLP2rHANh+PYfTmxbuOnykNGyhM6FjFLbW2uZHQTY1jMrPprjOrmyK5sjJR O4d1DeGHT/YnIjs9JogRKv4XHECwLtIVdAbIdWHEtVZJyMSktcyysFcvuhPQK8Qc/E/Wq8uHSCo= </X509Certificate> </X509Data> Copy extracted certificate to ...

SAML2 IdP Initiated Single Logout with WSO2 Identity Server 5.1.0

With this feature WSO2 Identity Server facilitates IdP initiated SAML2 single log out requests. In the SAML service provider configuration UI here is a new configuration called “Enable IdP Initiated SLO”. You can enable this feature using this checkbox. Also you can define redirect URL after the single log out using "Return to URL" under “Enable IdP Initiated SLO” option. Following parameters can be used with IdP initiated SLO request. Parameter Description slo This is a mandatory parameter and must have the value “true” to mark the request as an IdP initiated log out request. spEntityID This is an optional parameter. Value of the parameter should be the SAML issuer name as in “Issuer” field in the SAML service provider configuration UI. returnTo This is an optional parameter. Value of the parameter should be the URL which needs to be redirected to, after the log out. If this parameter is present ...

Configuring Multiple Assertion Consumer Service URLs for SAML2 Service Provider with WSO2 Identity Server 5.1.0

This feature enables to define multiple assertion consumer service URLs for a SAML2 service provider.  In the  SAML service provider configuration UI there is a new configuration called “Assertion Consumer URLs”. You can add multiple assertion consumer   URLs for the SAML2 service provider using the “Add” button. Since we have multiple assertion consumer URLs, we need to define a default assertion consumer URL in case we can’t retrieve it from the authentication request. Now SP initiated SSO and IdP initiated SSO flows behave as follows, In SP initiated SSO, If no AssertionConsumerServiceUrl is given in the <AuthnRequest>, IS will send the response to default ACS URL of the SP. (Whether request is signed or not)  If the AssertionConsumerServiceUrl in <AuthnRequest> matches with one of the registered URLs, IS will send the response to the matched one.  If the AssertionConsumerServiceUrl in <AuthnRequest> does not match ...