Absent Member.. Absent Member..
Absent Member..
291 views

VPN Session Query Total Time Calculation

I try to schedule weekly VPN sessions report. Due to bug in mysql I used concat in my query. But somehow total time is less then longest session.

Any help would be really appreciated.

Thank you.

SELECT count(*) "Number of Sessions" , t1.userId "User Name", CONCAT(

       CASE WHEN SUM(UNIX_TIMESTAMP(t2.endtime)

                    -UNIX_TIMESTAMP(t1.endtime)) > 86400

            THEN CONCAT('',FLOOR(

                 SUM(UNIX_TIMESTAMP(t2.endtime)

                    -UNIX_TIMESTAMP(t1.endtime)) / 86400 )

                          , ' days, ' )

            ELSE '' END

        , SEC_TO_TIME(MOD(

                 SUM(UNIX_TIMESTAMP(t2.endtime)

                    -UNIX_TIMESTAMP(t1.endtime)) , 86400 )

             ) ) "Total Duration" ,

CONCAT(

       CASE WHEN AVG(UNIX_TIMESTAMP(t2.endtime)

                    -UNIX_TIMESTAMP(t1.endtime)) > 86400

            THEN CONCAT('',FLOOR(

                 AVG(UNIX_TIMESTAMP(t2.endtime)

                    -UNIX_TIMESTAMP(t1.endtime)) / 86400 )

                          , ' days, ' )

            ELSE '' END

        , SEC_TO_TIME(MOD(

                 AVG(UNIX_TIMESTAMP(t2.endtime)

                    -UNIX_TIMESTAMP(t1.endtime)) , 86400 )

             ) ) "Average Session" ,

CONCAT(

       CASE WHEN MAX(UNIX_TIMESTAMP(t2.endtime)

                    -UNIX_TIMESTAMP(t1.endtime)) > 86400

            THEN CONCAT('',FLOOR(

                 MAX(UNIX_TIMESTAMP(t2.endtime)

                    -UNIX_TIMESTAMP(t1.endtime)) / 86400 )

                          , ' days, ' )

            ELSE '' END

        , SEC_TO_TIME(MOD(

                 MAX(UNIX_TIMESTAMP(t2.endtime)

                    -UNIX_TIMESTAMP(t1.endtime)) , 86400 )

             ) ) "Longest Session"

From (SELECT events.arc_endTime "endTime", events.arc_destinationUserName "userId", events.arc_flexString1 "sessionid" FROM events WHERE (events.arc_deviceEventClassId LIKE '%to gateway' AND events.arc_sourceAddress IS NOT NULL AND events.arc_deviceProduct = 'VPN-1 & FireWall-1'  )) t1 ,

(SELECT events.arc_endTime "endTime", events.arc_destinationUserName "userId", events.arc_flexString1 "sessionid" FROM events WHERE (events.arc_deviceEventClassId LIKE '%from gateway' AND events.arc_sourceAddress IS NOT NULL AND events.arc_deviceProduct = 'VPN-1 & FireWall-1'  )) t2

WHERE (t1.sessionid = t2.sessionid) GROUP BY t1.userid


totaltime.png


Labels (2)
Tags (4)
0 Likes
0 Replies
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.