Skip to content

Commit

Permalink
Merge pull request #935 from andrzej-jankowski/donpedro
Browse files Browse the repository at this point in the history
DonPedro - improvements
  • Loading branch information
mkurek committed Jun 20, 2014
2 parents 0dc21f8 + ec287d2 commit fdabcb8
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 32 deletions.
33 changes: 16 additions & 17 deletions contrib/donpedro_v_2/DonPedro.DTO/BaseDTOResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,34 @@ public string ToJSON()

foreach (var property in this.GetType().GetProperties())
{
if (property.GetValue(this, null) == null)
{
continue;
}
propertyValue = property.GetValue(
this, null
).ToString().Replace(
"\"", "\\\""
).Replace(
@"\", @"\\"
);

if (propertyValue.Length > 0) {
if (propertiesCount == 1)
{
return "\"" + propertyValue + "\"";
}

try
{
parts.Add(
string.Format(
"\"{0}\":\"{1}\"",
Regex.Replace(
property.Name,
@"\B[A-Z]",
new MatchEvaluator(BaseDTOResponse.AppendUnderscore)
).ToLower().Trim(),
propertyValue
)
);
}
catch (NullReferenceException) {}
parts.Add(
string.Format(
"\"{0}\":\"{1}\"",
Regex.Replace(
property.Name,
@"\B[A-Z]",
new MatchEvaluator(BaseDTOResponse.AppendUnderscore)
).ToLower().Trim(),
propertyValue
)
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public class DiskShareMountDTOResponse : BaseDTOResponse
{
public string Volume { get; set; }
public string SerialNumber { get; set; }
public string Size { get; set; }
}
}
14 changes: 13 additions & 1 deletion contrib/donpedro_v_2/DonPedro.DTO/MacAddressDTOResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ namespace DonPedro.DTO
{
public class MacAddressDTOResponse : BaseDTOResponse
{
public string Mac { get; set; }
private string macAddress;

public string Mac {
get
{
return macAddress;
}

set
{
macAddress = value.Replace(":", "").Replace("-", "").ToUpper();
}
}
}
}
77 changes: 69 additions & 8 deletions contrib/donpedro_v_2/DonPedro.Detectors/FCInfoDetectorSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using DonPedro.DTO;
using DonPedro.Detectors.Exceptions;
using System.Text.RegularExpressions;
using DonPedro.Utils;

namespace DonPedro.Detectors
{
Expand All @@ -16,10 +17,14 @@ public List<FibreChannelDTOResponse> GetFibreChannelInfo()

try
{
fcinfoResult = ExecuteFcinfoCommand();
fcinfoResult = ExecuteFcinfoCommand("details");
}
catch (ExternalCommandExecutionException)
catch (ExternalCommandExecutionException e)
{
Logger.Instance.LogWarning(
"[GetFCInfo] To get informations about FC cards or disk shares install fcinfo tool."
);
Logger.Instance.LogError(e.ToString());
return fc;
}

Expand All @@ -46,9 +51,10 @@ public List<FibreChannelDTOResponse> GetFibreChannelInfo()
{
if (modelName.Length > 0)
{
card.ModelName = modelName;
card.ModelName = SanitizeModelName(modelName);
}
fc.Add(card);
modelName = "";
}
card = new FibreChannelDTOResponse();
string[] adapterNameParts = lineParts[1].Trim().Split('-');
Expand All @@ -65,7 +71,7 @@ public List<FibreChannelDTOResponse> GetFibreChannelInfo()
case "model":
if (modelName.Length > 0)
{
modelName = " " + lineParts[1].Trim();
modelName = modelName + " " + lineParts[1].Trim();
}
else
{
Expand All @@ -87,16 +93,69 @@ public List<FibreChannelDTOResponse> GetFibreChannelInfo()
}
if (card != null)
{
if (card.ModelName == null)
{
card.ModelName = SanitizeModelName(modelName);
}
fc.Add(card);
}

return fc;
}

protected string ExecuteFcinfoCommand()
public string GetShareWWN(string serialNumber) {
string fcinfoResult = "";
try
{
fcinfoResult = ExecuteFcinfoCommand("mapping");
}
catch (ExternalCommandExecutionException e)
{
Logger.Instance.LogWarning(
"[GetShareWWN] To get informations about FC cards or disk shares install fcinfo tool."
);
Logger.Instance.LogError(e.ToString());
return "";
}

string[] lines = Regex.Split(fcinfoResult, "\r\n");
Regex rgx = new Regex( @"[a-zA-Z0-9]{16}");
for (int i = 0; i < lines.Length; i++)
{
string line = lines[i].Trim();
if (line.Length == 0)
{
continue;
}

if (line.ToLower().Contains(serialNumber.ToLower()))
{
Match m = rgx.Match(line);
if (m.Success)
{
return m.Value;
}
}
}

return "";
}

protected string SanitizeModelName(string modelName)
{
modelName = Regex.Replace(
modelName,
"corporation ",
"",
RegexOptions.IgnoreCase
);
return modelName;
}

protected string ExecuteFcinfoCommand(string option)
{
Process proc = new Process();
proc.StartInfo = PrepareProcessStartInfo();
proc.StartInfo = PrepareProcessStartInfo(option);
try
{
proc.Start();
Expand All @@ -115,9 +174,11 @@ protected string ExecuteFcinfoCommand()
return proc.StandardOutput.ReadToEnd();
}

protected ProcessStartInfo PrepareProcessStartInfo()
protected ProcessStartInfo PrepareProcessStartInfo(string option)
{
ProcessStartInfo psi = new ProcessStartInfo("cmd.exe", @"/C %windir%\\Sysnative\\fcinfo.exe /details");
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "fcinfo.exe";
psi.Arguments = "/" + option;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.UseShellExecute = false;
Expand Down
17 changes: 15 additions & 2 deletions contrib/donpedro_v_2/DonPedro.Detectors/WMIDetectorSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using DonPedro.DTO;
using DonPedro.Utils;
using DonPedro.Detectors;

namespace DonPedro.Detectors
{
Expand Down Expand Up @@ -390,11 +391,12 @@ from Win32_SCSIController
public List<DiskShareMountDTOResponse> GetDiskShareMountInfo()
{
List<DiskShareMountDTOResponse> mounts = new List<DiskShareMountDTOResponse>();
FCInfoDetectorSource fcinfo = new FCInfoDetectorSource();

try
{
SelectQuery query = new SelectQuery(
@"select Model, DeviceID
@"select Model, DeviceID, Size
from Win32_DiskDrive
where Model like '3PARdata%'"
);
Expand All @@ -410,9 +412,20 @@ from Win32_DiskDrive

foreach (ManagementObject snObj in snSearcher.Get())
{
string serialNumber = fcinfo.GetShareWWN(
GetValueAsString(snObj, "SerialNumber")
);
if (serialNumber.Length == 0)
{
continue;
}
DiskShareMountDTOResponse share = new DiskShareMountDTOResponse();
share.Volume = GetValueAsString(obj, "Model");
share.SerialNumber = GetValueAsString(snObj, "SerialNumber");
share.SerialNumber = serialNumber;
share.Size = ConvertSizeToMiB(
Int64.Parse(GetValueAsString(obj, "Size")),
SizeUnits.B
).ToString();

mounts.Add(share);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ public List<SoftwareDTOResponse> GetSoftwareInfo()
List<SoftwareDTOResponse> software = new List<SoftwareDTOResponse>();

software.AddRange(GetSoftwareFromLocalMachine32());
software = MergeSoftwareLists(software, GetSoftwareFromLocalMachine64());
try
{
software = MergeSoftwareLists(software, GetSoftwareFromLocalMachine64());
}
catch (NullReferenceException)
{
// It is a 32 bit machine...
}

return software;
}
Expand Down
2 changes: 1 addition & 1 deletion contrib/donpedro_v_2/DonPedro/DonPedroJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void NotifyRalph(object stateObject)
Detector d = new Detector();
string jsonData = d.GetAllComponentsJSON();

Logger.Instance.LogInformation("Sending to: " + ReportURL + " Data: " + jsonData);
Logger.Instance.LogInformation("Sending to: " + ReportURL);

int tries = 0;
while (tries < MaxTries)
Expand Down
2 changes: 1 addition & 1 deletion contrib/donpedro_v_2/DonPedro/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
//
// You can specify all the values or you can use the default the Revision and
// Build Numbers by using the '*' as shown below:
[assembly: AssemblyVersion("2.0.0")]
[assembly: AssemblyVersion("2.1.0")]
2 changes: 1 addition & 1 deletion contrib/donpedro_v_2/DonPedroOutput/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace DonPedroOutput
class Program
{
public static void Main(string[] args)
{
{
Detector d = new Detector();

Console.WriteLine("Detected CPUs:");
Expand Down

0 comments on commit fdabcb8

Please sign in to comment.