The Mochi demonstration application simulates clusters of failed logins at a bank, either by phone or web, as well as withdrawals or debits using the same customer id number. To run the Mochi demo, do one of the following:
Note: $SQLSTREAM_HOME refers to the installation directory for s-Server, such as /opt/sqlstream/
Note: the Linux server user who runs the Mochi demo must be using the latest version of Mozilla Firefox or Google Chrome in order to work.
If your machine does not have a GUI, you can run the script in $SQLSTREAM_HOME/demo/mochi called runDemo.sh.
Note: $SQLSTREAM_HOME refers to the installation directory for s-Server, such as /opt/sqlstream/
This is the same script that is run when you click the desktop icon. When the script detects that your system has no browser installed, it will print out a message that includes the URL on which the demo runs. You can then point to this URL from any machine that can access it (including Windows machines) in order to view the demo.
To launch s-Dashboard, open a browser and enter localhost:5595/dashboards
The home page for s-Dashboard appears:
To stop the Mochi demo, do one of the following:
This will stop all pumps, datagens, WebAgent and s-Dashboard instances started by the Mochi demo.
The Mochi demo gathers simulated data on phone login events and web login events, then analyzes this data to identify clusters of failed login attempts. It tracks data using the following columns.
Column | Explanation |
---|---|
recNo | A unique record id for the event. |
accountNumber | Eleven digit number. |
directDial | Number dialed at bank. |
SQLstream uses streams to capture dynamically changing data so that this data can be queried with SQL. The stream used to capture data for Mochi's web login events is called WebLoginEvents and is created with the following block of SQL:
CREATE OR REPLACE STREAM "PhoneLoginEvents"
  ("recNo" INTEGER,
  "ts" TIMESTAMP NOT NULL,
  "accountNumber" INTEGER,
  "loginSuccessful" BOOLEAN,
  "callerId" VARCHAR(32),
  "directDial" VARCHAR(32),
  "customerId" INTEGER)
  DESCRIPTION 'Logins from the phone system';
Column | Explanation |
---|---|
recNo | A unique record id for the event. |
accountNumber | Eleven digit number. |
sourceIP | Originating id for login. |
destIP | Ip address that user attempted to log into. |
The Mochi demo uses the Log File Adapter to tail and parse a sample log file from a web server to track web login events. See the topic Log File Adapter in the Integration Guide for more details.
The Log File adapter uses a foreign stream to capture data. The code for a sample foreign stream is as follows:
CREATE OR REPLACE FOREIGN STREAM "WebLoginEvents"
  SERVER "WebAppServer"
  OPTIONS (
    log_path '/tmp/mochi/web_login.log',
    encoding 'UTF-8',
    sleep_interval '100',
    max_unchanged_stats '20',
    parser 'variable',
    parser_columns '"recNo" TYPE INTEGER,
        "ts" TYPE TIMESTAMP NOT NULL,
        "accountNumber" TYPE INTEGER,
        "loginSuccessful" TYPE BOOLEAN,
        "sourceIP" TYPE VARCHAR(32),
        "destIP" TYPE VARCHAR(32),
        "customerId" TYPE INTEGER',
    parser_delimiters ',')
  DESCRIPTION 'Login stream from web app';
Once the Mochi demo has created streams to gather data on the demo's events, it uses views to generate relationships between the streams' data. For example, the following code combines phone login events with the phone numbers' location.
CREATE OR REPLACE VIEW "PhoneLoginEventsWithLocation"
  DESCRIPTION 'Phone login events enriched by geo-lookup'
  AS
  SELECT STREAM
    "recNo", "ts", "accountNumber", "loginSuccessful",
    "callerId", "directDial", "customerId",
    CAST(PLE.r.countryCode AS CHAR(2)) AS "countryCode",
    CAST(PLE.r.countryName AS VARCHAR(34)) AS "countryName",
    CAST(PLE.r.city AS VARCHAR(32)) AS "city",
    CAST(PLE.r.region AS CHAR(2)) AS "region",
    CAST(PLE.r.lat AS DECIMAL(8,5)) AS "lat",
    CAST(PLE.r.lon AS DECIMAL(8,5)) AS "lon"
  FROM (
    SELECT STREAM
      *,
      -- getPhoneLocation output: 'countryCode,country,city,state/region,lat,lon'
      VARIABLE_COLUMN_LOG_PARSE("phoneLoc",
        'countryCode, countryName, city, region, lat, lon', ',') AS r
    FROM "PhoneLoginEvents2") AS PLE;
Other views identify suspect login events by combining data from web login streams and phone login streams, then identifying account numbers with more than three failed login attempts in a minute:
CREATE OR REPLACE VIEW "SuspectLoginFailures"
  DESCRIPTION 'Windowed stream view to detect groups of failed logins'
  AS
  SELECT STREAM
    "accountNumber",
    -- "loginFailureCount",
    "webFail", "phoneFail",
    "city", "region", "lat", "lon"
  FROM (
    SELECT STREAM
      "accountNumber",
      -- COUNT(*) OVER "lastMinute" AS "loginFailureCount",
      SUM(MOCHI_UTIL.CMI("accessType", 'WEB')) OVER "lastMinute" AS "webFail",
      SUM(MOCHI_UTIL.CMI("accessType", 'PHONE')) OVER "lastMinute" AS "phoneFail",
      "city", "region", "lat", "lon"
    FROM "LoginEvents"
    WHERE NOT "loginSuccessful"
    WINDOW "lastMinute" AS (
      PARTITION BY "accountNumber"
      ORDER BY "LoginEvents".ROWTIME
      RANGE INTERVAL '1' MINUTE PRECEDING))
  WHERE "webFail" + "phoneFail" > 3;
To change the amount, rate, and type of data generated, modify the xml files in /demo/mochi/datagen
For more information on Datagen, see the topic Generating Test Data with DataGen