public static void Setup()
 {
     if (Client == null)
     {
         using var config = TelemetryConfiguration.CreateDefault();
         using (var cmd = new SqliteCommand(CHECK_TELEMETRY, DatabaseManager.Connection, DatabaseManager.Transaction))
         {
             using (var reader = cmd.ExecuteReader())
             {
                 while (reader.Read())
                 {
                     OptOut = bool.Parse(reader["value"].ToString());
                 }
             }
         }
         config.InstrumentationKey = INSTRUMENTATION_KEY;
         config.DisableTelemetry   = OptOut;
         Client = new TelemetryClient(config);
         Client.Context.Component.Version = AsaHelpers.GetVersionString();
         // Force some values to static values to prevent gathering unneeded data
         Client.Context.Cloud.RoleInstance = "Asa";
         Client.Context.Cloud.RoleName     = "Asa";
         Client.Context.Location.Ip        = "1.1.1.1";
     }
 }
        public static void InsertRun(string runId, Dictionary <RESULT_TYPE, bool> dictionary)
        {
            if (dictionary == null)
            {
                return;
            }
            string INSERT_RUN = "insert into runs (run_id, file_system, ports, users, services, registry, certificates, firewall, comobjects, eventlogs, type, timestamp, version, platform) values (@run_id, @file_system, @ports, @users, @services, @registry, @certificates, @firewall, @comobjects, @eventlogs, @type, @timestamp, @version, @platform)";

            using var cmd = new SQLiteCommand(INSERT_RUN, Connection, Transaction);
            cmd.Parameters.AddWithValue("@run_id", runId);
            cmd.Parameters.AddWithValue("@file_system", (dictionary.ContainsKey(RESULT_TYPE.FILE) && dictionary[RESULT_TYPE.FILE]) || (dictionary.ContainsKey(RESULT_TYPE.FILEMONITOR) && dictionary[RESULT_TYPE.FILEMONITOR]));
            cmd.Parameters.AddWithValue("@ports", (dictionary.ContainsKey(RESULT_TYPE.PORT) && dictionary[RESULT_TYPE.PORT]));
            cmd.Parameters.AddWithValue("@users", (dictionary.ContainsKey(RESULT_TYPE.USER) && dictionary[RESULT_TYPE.USER]));
            cmd.Parameters.AddWithValue("@services", (dictionary.ContainsKey(RESULT_TYPE.SERVICE) && dictionary[RESULT_TYPE.SERVICE]));
            cmd.Parameters.AddWithValue("@registry", (dictionary.ContainsKey(RESULT_TYPE.REGISTRY) && dictionary[RESULT_TYPE.REGISTRY]));
            cmd.Parameters.AddWithValue("@certificates", (dictionary.ContainsKey(RESULT_TYPE.CERTIFICATE) && dictionary[RESULT_TYPE.CERTIFICATE]));
            cmd.Parameters.AddWithValue("@firewall", (dictionary.ContainsKey(RESULT_TYPE.FIREWALL) && dictionary[RESULT_TYPE.FIREWALL]));
            cmd.Parameters.AddWithValue("@comobjects", (dictionary.ContainsKey(RESULT_TYPE.COM) && dictionary[RESULT_TYPE.COM]));
            cmd.Parameters.AddWithValue("@eventlogs", (dictionary.ContainsKey(RESULT_TYPE.LOG) && dictionary[RESULT_TYPE.LOG]));
            cmd.Parameters.AddWithValue("@type", (dictionary.ContainsKey(RESULT_TYPE.FILEMONITOR) && dictionary[RESULT_TYPE.FILEMONITOR]) ? "monitor" : "collect");
            cmd.Parameters.AddWithValue("@timestamp", DateTime.Now.ToString("o", CultureInfo.InvariantCulture));
            cmd.Parameters.AddWithValue("@version", AsaHelpers.GetVersionString());
            cmd.Parameters.AddWithValue("@platform", AsaHelpers.GetPlatformString());
            try
            {
                cmd.ExecuteNonQuery();
                Commit();
            }
            catch (SQLiteException e)
            {
                Log.Warning(e.StackTrace);
                Log.Warning(e.Message);
                AsaTelemetry.TrackTrace(Microsoft.ApplicationInsights.DataContracts.SeverityLevel.Error, e);
            }
        }
 public static void TrackEvent(string name, Dictionary<string, string> evt)
 {
     var track = (evt == null) ? new Dictionary<string, string>() : evt;
     track.Add("Version", AsaHelpers.GetVersionString());
     track.Add("OS", AsaHelpers.GetOsName());
     track.Add("OS_Version", AsaHelpers.GetOsVersion());
     track.Add("Method", new System.Diagnostics.StackFrame(1).GetMethod()?.Name ?? "");
     Client?.TrackEvent(name, track);
 }
 public static void TrackTrace(SeverityLevel severityLevel, Exception e)
 {
     var evt = new Dictionary<string, string>();
     evt.Add("Version", AsaHelpers.GetVersionString());
     evt.Add("OS", AsaHelpers.GetOsName());
     evt.Add("OS_Version", AsaHelpers.GetOsVersion());
     evt.Add("Method", new System.Diagnostics.StackFrame(1).GetMethod()?.Name ?? "");
     evt.Add("Stack", (e == null || e.StackTrace == null) ? "" : e.StackTrace);
     Client?.TrackTrace((e == null) ? "Null" : e.GetType().ToString(), severityLevel, evt);
 }
Beispiel #5
0
 public static void SetEnabled(bool enabled)
 {
     Enabled                   = enabled;
     using var config          = TelemetryConfiguration.CreateDefault();
     config.InstrumentationKey = INSTRUMENTATION_KEY;
     config.DisableTelemetry   = Enabled;
     Client = new TelemetryClient(config);
     Client.Context.Component.Version = AsaHelpers.GetVersionString();
     // Force some values to static values to prevent gathering unneeded data
     Client.Context.Cloud.RoleInstance = "Asa";
     Client.Context.Cloud.RoleName     = "Asa";
     Client.Context.Location.Ip        = "1.1.1.1";
 }
Beispiel #6
0
        public static void InsertRun(string runId, List <RESULT_TYPE> typeList, RUN_TYPE type)
        {
            var runs = db?.GetCollection <AsaRun>("Runs");

            runs?.Insert(new AsaRun(
                             RunId: runId,
                             ResultTypes: typeList,
                             Platform: AsaHelpers.GetPlatform(),
                             Timestamp: DateTime.Now,
                             Type: type,
                             Version: AsaHelpers.GetVersionString()
                             ));
        }
 public static void Setup(bool test = false)
 {
     if (Client == null)
     {
         using var config          = TelemetryConfiguration.CreateDefault();
         Enabled                   = test ? true : DatabaseManager.GetTelemetryEnabled();
         config.InstrumentationKey = INSTRUMENTATION_KEY;
         config.DisableTelemetry   = !Enabled;
         Client = new TelemetryClient(config);
         Client.Context.Component.Version = AsaHelpers.GetVersionString();
         // Force some values to static values to prevent gathering unneeded data
         Client.Context.Cloud.RoleInstance = "Asa";
         Client.Context.Cloud.RoleName     = "Asa";
         Client.Context.Location.Ip        = "1.1.1.1";
     }
 }
 public static void SetOptOut(bool optOut)
 {
     OptOut                           = optOut;
     using var config                 = TelemetryConfiguration.CreateDefault();
     config.InstrumentationKey        = INSTRUMENTATION_KEY;
     config.DisableTelemetry          = OptOut;
     Client                           = new TelemetryClient(config);
     Client.Context.Component.Version = AsaHelpers.GetVersionString();
     // Force some values to static values to prevent gathering unneeded data
     Client.Context.Cloud.RoleInstance = "Asa";
     Client.Context.Cloud.RoleName     = "Asa";
     Client.Context.Location.Ip        = "1.1.1.1";
     using (var cmd = new SqliteCommand(UPDATE_TELEMETRY, DatabaseManager.Connection, DatabaseManager.Transaction))
     {
         cmd.Parameters.AddWithValue("@TelemetryOptOut", OptOut.ToString(CultureInfo.InvariantCulture));
         cmd.ExecuteNonQuery();
         DatabaseManager.Commit();
     }
 }