public static readonly Guid FunctionKey = new Guid("$guid2$"); //agent identity key static void Main(string[] args) { string outbox = @"\\mcpserver\MCPDropBox\"; //drop box for json files Guid JobKey = Guid.NewGuid(); //use for grouping packages into job chunks CMCPPackage p = new CMCPPackage(FunctionKey, DeveloperKey, outbox); p.SetJob(JobKey); //re-use job to group all these packages together p.KeyVals.Add("Failure Message", "something here"); p.Type = CMCPPackage.PackageType.Info; p.NoticeCount = 1; p.Blob = "some info here"; p.DT = DateTime.Now; p.SaveToFolder(); }
public static readonly Guid FunctionKey = new Guid("a2cad9b8-bb58-4057-b729-5c11245b8071"); //agent identity key static void Main(string[] args) { string outbox = @"\\mcpserver\MCPDropBox\"; //drop box for json files Guid JobKey = Guid.NewGuid(); //use for grouping packages into job chunks string ip = "10.10.10.150"; CMCPPackage p = new CMCPPackage(FunctionKey, DeveloperKey, outbox); p.SetJob(JobKey); Ping x = new Ping(); PingReply reply = x.Send(IPAddress.Parse(ip)); p.KeyVals.Add("Server", ip); if (reply.Status == IPStatus.Success) { p.Type = CMCPPackage.PackageType.Info; p.NoticeCount = 1; p.InfoCount = 1; p.Blob = "Connection OK to " + ip; p.DT = DateTime.Now; p.SaveToFolder(); Console.WriteLine("Connection OK"); } else { Console.WriteLine("Connection not OK"); p.Type = CMCPPackage.PackageType.Error; p.NoticeCount = 1; p.ErrorCount = 1; p.Blob = "Can't connect to " + ip; p.DT = DateTime.Now; p.SaveToFolder(); } }
private static void DoWork() { ClientContext clientContext = new ClientContext("http://intranet"); //context.Credentials = new NetworkCredential(this.UserName, this.Password, this.Domain); GroupCollection groupCollection = clientContext.Web.SiteGroups; clientContext.Load(groupCollection, groups => groups.Include(group => group.Users)); clientContext.ExecuteQuery(); CMCPPackage p = new CMCPPackage(FunctionKey, DeveloperKey, outbox); List <string> ignoreUsersList = new List <string>() { @"NT AUTHORITY\authenticated users", @"NT AUTHORITY\LOCAL SERVICE", @"SHAREPOINT\system", @"DOMAIN1\spfarm", @"DOMAIN1\spups", @"DOMAIN1\sptest", @"DOMAIN1\administrator", @"DOMAIN1\domain admins", @"DOMAIN1\domain users" }; StringBuilder sbuilder = new StringBuilder(); int cnt = 0; foreach (Group oGroup in groupCollection) { UserCollection userColl = oGroup.Users; foreach (User user in userColl) { if (!ignoreUsersList.Contains(user.LoginName)) { string s = IsUserInAD(user.LoginName); if (s != "") { cnt++; sbuilder.AppendLine(s); } } } } if (!foundsome) { CMCPPackage newPackage = new CMCPPackage(FunctionKey, DeveloperKey, outbox); newPackage.KeyVals.Add("Server", "intranet"); newPackage.Blob = "No issues found"; newPackage.Type = CMCPPackage.PackageType.Info; newPackage.DT = DateTime.Now; newPackage.NoticeCount = 0; newPackage.InfoCount = 0; newPackage.SaveToFolder(); } else { CMCPPackage newPackage = new CMCPPackage(FunctionKey, DeveloperKey, outbox); newPackage.KeyVals.Add("Server", "intranet"); newPackage.Blob = sbuilder.ToString(); newPackage.Type = CMCPPackage.PackageType.Warning; newPackage.DT = DateTime.Now; newPackage.NoticeCount = cnt; newPackage.WarningCount = cnt; newPackage.SaveToFolder(); } }
public static readonly Guid FunctionKey = new Guid("01021458-8b6f-4ef4-a0b3-7b0f6ee81c5d"); //agent identity key static void Main(string[] args) { string outbox = @"\\mcpserver\MCPDropBox\"; Guid JobKey = Guid.NewGuid(); ClientContext clientContext = new ClientContext("http://spserver:28765/"); Regex regex = new Regex("4(.)-(.)Success"); List list = clientContext.Web.Lists.GetByTitle("Review problems and solutions"); clientContext.Load(list); CamlQuery camlQuery = new CamlQuery(); camlQuery.ViewXml = "<View>All Reports</View>"; ListItemCollection listItems = list.GetItems(camlQuery); clientContext.Load(listItems); clientContext.ExecuteQuery(); foreach (ListItem listItem in listItems) { StringBuilder sbuilder = new StringBuilder(); Match m = regex.Match(listItem["HealthReportSeverity"].ToString()); if (!m.Success) { sbuilder.AppendLine(listItem["Title"].ToString()); sbuilder.AppendLine("Description: " + listItem["HealthReportExplanation"].ToString()); sbuilder.AppendLine("Remedy: " + listItem["HealthReportRemedy"].ToString()); CMCPPackage p = new CMCPPackage(FunctionKey, DeveloperKey, outbox); p.SetJob(JobKey); //re-use job to group all these packages together p.KeyVals.Add("Severity", listItem["HealthReportSeverity"].ToString()); p.KeyVals.Add("Failing Services", listItem["HealthReportServices"].ToString()); try { p.KeyVals.Add("Failing Servers", listItem["HealthReportServers"].ToString()); } catch { } p.KeyVals.Add("Failure Message Date", listItem["Modified"].ToString()); switch (listItem["HealthReportSeverity"].ToString()) { case "1 - Error": p.Type = CMCPPackage.PackageType.Error; p.ErrorCount = 1; break; case "2 - Warning": p.Type = CMCPPackage.PackageType.Warning; p.WarningCount = 1; break; default: p.Type = CMCPPackage.PackageType.Info; p.InfoCount = 1; break; } p.NoticeCount = 1; p.Blob = sbuilder.ToString(); p.DT = DateTime.UtcNow; p.SaveToFolder(); } } }
private static void DoWork() { int cnt = 0; // To be written to file to make sure we do not process the same files multiple times. DateTime dtTodaysDate = DateTime.Now; Regex regexObj = new Regex(regExString); MatchCollection mc = null; StringBuilder mystr = new StringBuilder(); string strnewlog = ""; string strLastLog = ""; try { strLastLog = File.ReadAllText(fnLastRun); } catch (FileNotFoundException ex) { strLastLog = "1900-01-01"; } //Reads from "lastlog.txt" to determine if files need to be checked or not. string[] fileHolder; try { fileHolder = Directory.GetFiles(log_path, "*"); } catch (Exception ex) { CMCPPackage p = new CMCPPackage(FunctionKey, DeveloperKey, outbox); p.SetJob(JobKey); //re-use job to group all these packages together p.KeyVals.Add("Server", "inthealthserver"); p.KeyVals.Add("URL", log_path); p.KeyVals.Add("Last Run", strLastLog); p.Type = CMCPPackage.PackageType.Error; p.NoticeCount = 1; p.ErrorCount = 1; p.Blob = ex.Message; p.DT = DateTime.Now; p.SaveToFolder(); return; } foreach (var file in fileHolder) { if (singleday) //SINGLEDAY ONLY { strLastLog = startrange.ToString(); if (startrange.Date == File.GetLastWriteTime(file).Date) { Console.WriteLine("Processing single day file: {0}", file); ReadFile(regexObj, ref strnewlog, ref mc, file, ref mystr, ref cnt); // Call to ReadFile() } } else //NOT single day { if (File.GetLastWriteTime(file) > Convert.ToDateTime(strLastLog)) //CHECK for files to process { Console.WriteLine("Processing new file: {0}", file); ReadFile(regexObj, ref strnewlog, ref mc, file, ref mystr, ref cnt);// Call to ReadFile() } } } //END FOR CMCPPackage newPackage = new CMCPPackage(FunctionKey, DeveloperKey, outbox); newPackage.SetJob(JobKey); //re-use job to group all these packages together newPackage.KeyVals.Add("Server", "inthealthserver"); newPackage.KeyVals.Add("URL", log_path); newPackage.KeyVals.Add("Last Run", strLastLog); if (cnt > 0) { newPackage.Type = CMCPPackage.PackageType.Warning; newPackage.NoticeCount = cnt; newPackage.WarningCount = cnt; newPackage.Blob = mystr.ToString(); Console.WriteLine("sending multiple {0}", cnt); } else { newPackage.Type = CMCPPackage.PackageType.Info; newPackage.NoticeCount = 1; newPackage.InfoCount = 1; newPackage.Blob = "No Data to Send"; Console.WriteLine("sending nothing"); } if (singleday) { newPackage.DT = startrange; } else { newPackage.DT = DateTime.Now; } newPackage.SaveToFolder(); File.WriteAllText(fnLastRun, dtTodaysDate.ToString()); }