public bool checkArgs() { if (warning.getInt() <= 0 || critical.getInt() <= 0) { return(false); } if (warning.getInt() > critical.getInt()) { return(false); } return(true); }
public int executePlugin() { int retVal = 0; if (failTest()) { retVal = 2; } else { if (checkArguments) { if (!checkArgs()) { return(3); } } int shared_folders_counter = 0; using (System.Management.ManagementClass shareObj = new System.Management.ManagementClass("Win32_Share")) { System.Management.ManagementObjectCollection shares = shareObj.GetInstances(); foreach (System.Management.ManagementObject share in shares) { shared_folders_counter++; } } String performance_data = " | shared_folders=" + shared_folders_counter + ";" + warning.getInt() + ";" + critical.getInt(); if (shared_folders_counter < warning.getInt()) { resultString = "Shared Folders OK: There are " + shared_folders_counter + " shared folders" + performance_data + " metric=1.00"; retVal = 0; } else if ((warning.getInt() == critical.getInt() && warning.getInt() >= shared_folders_counter) || shared_folders_counter >= critical.getInt()) { resultString = "Shared Folders CRITICAL: There are " + shared_folders_counter + "shared folders" + performance_data + " metric=0.00"; retVal = 2; } else if (shared_folders_counter >= warning.getInt() && shared_folders_counter < critical.getInt()) { resultString = "Shared Folders WARNING: There are " + shared_folders_counter + "shared folders" + performance_data + " metric=0.50"; retVal = 1; } else { resultString = "Shared Folders UNKNOWN: Unable to get the shared folders | metric=0.00"; retVal = 3; } } Console.WriteLine(resultString); return(retVal); }
public int executePlugin() { int retVal = 3; if (failTest()) { retVal = 2; } else { if (hasArgs) { if (!checkArgs()) { Console.WriteLine("Check your arguments!"); return(3); } } UserUtilities s1 = new UserUtilities(); Dictionary <string, List <StoreUserProcesses> > processes = s1.GetUsersProcessesInfo(); Dictionary <string, long> user_memory = new Dictionary <string, long>(); foreach (KeyValuePair <string, List <StoreUserProcesses> > user in processes) { if (!user_memory.ContainsKey(user.Key)) { user_memory[user.Key] = 0; } foreach (StoreUserProcesses process in user.Value) { user_memory[user.Key] += process.memory_load; } } string output_data = ""; string performance_data = ""; string metric_data = " | metric="; bool is_critical = false; bool is_warning = false; long largest_memory_found = 0; foreach (var x in user_memory) { if (exclude_system_accounts) { if (users_exclusions.Contains(x.Key)) { continue; } } string user = x.Key.Contains(" ")? x.Key.Replace(" ", "_") : x.Key; long current_memory = x.Value / (1024 * 1024); performance_data += String.Format("{0}={1};{2};{3} ", user, current_memory, warning.getInt(), critical.getInt()); if (current_memory > largest_memory_found) { largest_memory_found = current_memory; } if (current_memory >= critical.getLong()) { is_critical = true; output_data += String.Format("User {0} has {1} MB ", user, current_memory); continue; } if (current_memory >= warning.getLong()) { is_warning = true; output_data += String.Format("User {0} has {1} MB ", user, current_memory); continue; } } if (is_critical) { string metric = metric_data + "0.00"; resultString = "USER MEMORY CRITICAL: " + output_data.Trim() + " memory in use" + metric + performance_data; retVal = 2; } else if (is_warning) { ATypes a1 = new ATypes(largest_memory_found); double metric = (1.0 / (this.warning.getDouble() - this.critical.getDouble())) * (a1.getDouble() - this.warning.getDouble()) + 1.0; resultString = "USER MEMORY WARNING: " + output_data.Trim() + " memory in use" + metric_data + metric.ToString("N2") + " " + performance_data; retVal = 1; } else if (!is_warning && !is_critical) { string metric = "1.00 "; resultString = "USER MEMORY OK: All users are within thresholds" + metric_data + metric + performance_data; retVal = 0; } else { resultString = "USER MEMORY UNKNOWN: Unknown error"; retVal = 3; } } Console.WriteLine(resultString); return(retVal); }