Ejemplo n.º 1
0
    public static EventLogRecord[] ReadEventLog(EventlogHandle handle,
    UInt32 dwLastRecordId,
    UInt32 nMaxRecords,
    string sqlQuery)
    {

        EventLogRecord[] result = null;
        EventAPI.EventLogRecord[] records = null; // new EventAPI.EventLogRecord[nMaxRecords];

        UInt32 nRecordsReturned = 0;
        UInt32 dwError =
        EventAPI.ReadEventLog(handle.Handle, dwLastRecordId, nMaxRecords, sqlQuery,
        out nRecordsReturned,  out records);
        if (dwError != 0)
        {
            Logger.Log(String.Format("Error: ReadEventLog [Code:{0}]", dwError), Logger.eventLogLogLevel);
        }
        if (nRecordsReturned > 0)
        {
            result = new EventLogRecord[nRecordsReturned];
            int iRecord = 0;
            foreach (EventAPI.EventLogRecord record in records)
            {
                result[iRecord++] = new EventLogRecord(record);
            }
        }
        return result;

    }
Ejemplo n.º 2
0
        public static EventLogRecord[] ReadEventLog(EventlogHandle handle,
                                                    UInt32 dwLastRecordId,
                                                    UInt32 nMaxRecords,
                                                    string sqlQuery)
        {
            EventLogRecord[]          result  = null;
            EventAPI.EventLogRecord[] records = null; // new EventAPI.EventLogRecord[nMaxRecords];

            UInt32 nRecordsReturned = 0;
            UInt32 dwError          =
                EventAPI.ReadEventLog(handle.Handle, dwLastRecordId, nMaxRecords, sqlQuery,
                                      out nRecordsReturned, out records);

            if (dwError != 0)
            {
                Logger.Log(String.Format("Error: ReadEventLog [Code:{0}]", dwError), Logger.eventLogLogLevel);
            }
            if (nRecordsReturned > 0)
            {
                result = new EventLogRecord[nRecordsReturned];
                int iRecord = 0;
                foreach (EventAPI.EventLogRecord record in records)
                {
                    result[iRecord++] = new EventLogRecord(record);
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        public static UInt32 GetCategoryCount(EventlogHandle handle)
        {
            UInt32 pdwNumMatched = 0;

            UInt32 dwError =
                EventAPI.GetCategoryCount(handle.Handle, out pdwNumMatched);

            if (dwError != 0)
            {
                Logger.Log(String.Format("Error: GetCategoryCount [Code:{0}]", dwError), Logger.eventLogLogLevel);
            }
            return(pdwNumMatched);
        }
Ejemplo n.º 4
0
        public static UInt32 DeleteFromEventLog(EventlogHandle handle,
                                                string sqlfilter)
        {
            UInt32 dwError =
                EventAPI.DeleteFromEventLog(handle.Handle, sqlfilter);

            if (dwError != 0)
            {
                Logger.Log(String.Format("Error: GetDistinctCategories [Code:{0}]", dwError), Logger.eventLogLogLevel);
            }

            return(dwError);
        }
Ejemplo n.º 5
0
        public static UInt32 CountLogs(EventlogHandle handle,
                                       string sqlQuery)
        {
            UInt32 nRecordsMatched = 0;

            UInt32 dwError =
                EventAPI.CountEventLog(handle.Handle, sqlQuery, out nRecordsMatched);

            if (dwError != 0)
            {
                Logger.Log(String.Format("Error: CountEventLog [Code:{0}]", dwError), Logger.eventLogLogLevel);
            }
            return(nRecordsMatched);
        }
Ejemplo n.º 6
0
        public static string[] GetDistinctCategories(EventlogHandle handle,
                                                     UInt32 pdwNumMatched)
        {
            string[] EventCategories = null;

            UInt32 dwError =
                EventAPI.GetDistinctCategories(handle.Handle, pdwNumMatched, out EventCategories);

            if (dwError != 0)
            {
                Logger.Log(String.Format("Error: GetDistinctCategories [Code:{0}]", dwError), Logger.eventLogLogLevel);
            }

            return(EventCategories);
        }
Ejemplo n.º 7
0
    private void ConnectToDomain()
    {
        Logger.Log("EventlogPlugin.ConnectToDomain", Logger.eventLogLogLevel);

        if (_hn.creds.Invalidated)
        {
            _container.ShowError("EventlogPlugin cannot connect to domain due to invalid credentials");
            _hn.IsConnectionSuccess = false;
            return;
        }

        if (!String.IsNullOrEmpty(_hn.hostName))
        {
            if (_currentHost != _hn.hostName)
            {
                if (eventLogHandle != null)
                {
                    eventLogHandle.Dispose();
                    eventLogHandle = null;
                }

                if (_pluginNode != null && !String.IsNullOrEmpty(_hn.hostName))
                {
                    _hn.IsConnectionSuccess = OpenEventLog(_hn.hostName);
                    if (!_hn.IsConnectionSuccess)
                    {
                        Logger.ShowUserError("Unable to open the event log; eventlog server may be disabled");
                        return;
                    }

                    if (eventLogHandle != null)
                        _pluginNode.Nodes.Clear();
                }
                _currentHost = _hn.hostName;
            }
            _hn.IsConnectionSuccess = true;
        }
        else
        {
            _hn.IsConnectionSuccess = false;
        }
    }
Ejemplo n.º 8
0
    public void CloseEventLog()
    {
        if (eventLogHandle == null)
        {
            return;
        }

        eventLogHandle.Dispose();

        eventLogHandle = null;

    }
Ejemplo n.º 9
0
    public bool OpenEventLog(string hostname)
    {
        try
        {
            if (eventLogHandle == null)
            {
                eventLogHandle = EventlogAdapter.OpenEventlog(hostname);
            }

            return (eventLogHandle != null);
        }
        catch (Exception e)
        {
            Logger.LogException("EventViewerPlugin.OpenEventLog", e);
            eventLogHandle = null;
            return false;
        }
    }
Ejemplo n.º 10
0
    public static UInt32 CountLogs(EventlogHandle handle,
    string sqlQuery)
    {

        UInt32 nRecordsMatched = 0;

        UInt32 dwError =
        EventAPI.CountEventLog(handle.Handle, sqlQuery, out nRecordsMatched);
        if (dwError != 0)
        {
            Logger.Log(String.Format("Error: CountEventLog [Code:{0}]", dwError), Logger.eventLogLogLevel);
        }
        return nRecordsMatched;

    }
Ejemplo n.º 11
0
    public static UInt32 DeleteFromEventLog(EventlogHandle handle,
                                                string sqlfilter)
    {
        UInt32 dwError =
               EventAPI.DeleteFromEventLog(handle.Handle, sqlfilter);
        if (dwError != 0)
        {
            Logger.Log(String.Format("Error: GetDistinctCategories [Code:{0}]", dwError), Logger.eventLogLogLevel);
        }

        return dwError;
    }
Ejemplo n.º 12
0
    public static string[] GetDistinctCategories(EventlogHandle handle,
                                                 UInt32 pdwNumMatched)
    {
        string[] EventCategories = null;

        UInt32 dwError =
               EventAPI.GetDistinctCategories(handle.Handle, pdwNumMatched, out EventCategories);
        if (dwError != 0)
        {
            Logger.Log(String.Format("Error: GetDistinctCategories [Code:{0}]", dwError), Logger.eventLogLogLevel);
        }

        return EventCategories;
    }
Ejemplo n.º 13
0
    public static UInt32 GetCategoryCount(EventlogHandle handle)
    {

        UInt32 pdwNumMatched = 0;

        UInt32 dwError =
               EventAPI.GetCategoryCount(handle.Handle, out pdwNumMatched);
        if (dwError != 0)
        {
            Logger.Log(String.Format("Error: GetCategoryCount [Code:{0}]", dwError), Logger.eventLogLogLevel);
        }
        return pdwNumMatched;

    }
Ejemplo n.º 14
0
        private EventlogHandle OpenEventLogHandle(EventlogHandle eventlogHandle)
        {
            Logger.Log("Opening eventlog", Logger.eventLogLogLevel);
            EventlogPlugin plugin = (EventlogPlugin)pi;
            EventlogHandle result = null;
            if (eventlogHandle == null)
            {
                if (plugin.HostInfo != null &&
                    !String.IsNullOrEmpty(plugin.HostInfo.hostName))
                {
                    result = EventlogAdapter.OpenEventlog((plugin.HostInfo.hostName));
                }
            }

            if (result == null)
            {
                throw new Exception("Failed to get the eventlog handle");
            }

            Logger.Log(String.Format(
            "EventViewerControl.OpenEventLogHandle(found handle={0:X}",
            result.Handle.ToInt32()));

            return result;
        }