Skip to content

Commit d5a2566

Browse files
committed
Renamed some classes. Added some "print help" methods
1 parent b39ceaa commit d5a2566

File tree

5 files changed

+124
-5
lines changed

5 files changed

+124
-5
lines changed

Common/Tools.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,37 @@ public static void PrintError()
1717
Console.WriteLine("Invalid argument");
1818
}
1919

20+
/// <summary>
21+
/// Print help for assemblies requiring agent ids as parameter
22+
/// </summary>
23+
/// <param name="api"></param>
24+
public static void PringAgentHelp(ZendeskApi api)
25+
{
26+
Console.WriteLine("You have to specify at least one agent id as parameter separated by spaces");
27+
PrintAgentIds(api);
28+
}
29+
30+
/// <summary>
31+
/// Prints agent ids
32+
/// </summary>
33+
/// <param name="api"></param>
34+
private static void PrintAgentIds(ZendeskApi api)
35+
{
36+
Console.WriteLine("List of agents");
37+
var users = api.Users.GetAllUsers();
38+
39+
var agents = users.Users.Where(u => u.Role.ToLower().Equals("agent"));
40+
41+
foreach (var agent in agents)
42+
{
43+
Console.WriteLine(agent.Id + ": " + agent.Name);
44+
}
45+
}
46+
2047
/// <summary>
2148
/// Print help message
2249
/// </summary>
23-
public static void PrintHelp(ZendeskApi api)
50+
public static void PrintGroupHelp(ZendeskApi api)
2451
{
2552
Console.WriteLine("You have to specify a group name or id as parameter");
2653
PrintGroups(api);

GetZendesAgentStatsInGroup/GetZendeskAgentStatsInGroup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static void Main(string[] args)
1818

1919
if (args == null || args.Length == 0)
2020
{
21-
Common.Tools.PrintHelp(_api);
21+
Common.Tools.PrintGroupHelp(_api);
2222
return;
2323
}
2424

GetZendeskAgentStatisticsByAgentId/GetAgentStatsByAgentId.cs

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,84 @@
33
using System.Linq;
44
using System.Text;
55
using System.Threading.Tasks;
6+
using Common;
7+
using ZendeskApi_v2;
8+
using ZendeskApi_v2.Models.Tickets;
69

710
namespace GetZendeskAgentStatisticsByAgentId
811
{
9-
class Program
12+
class GetAgentStatsByAgentId
1013
{
14+
15+
private static ZendeskApi _api;
16+
private static PrtgXmlOutput _xml;
17+
private static List<long> agentIdList;
18+
19+
1120
static void Main(string[] args)
1221
{
22+
_api = Common.ZendeskApiManager.ZendeskApi;
23+
_xml = new PrtgXmlOutput();
24+
25+
if (args == null || args.Length == 0)
26+
{
27+
Common.Tools.PringAgentHelp(_api);
28+
return;
29+
}
30+
31+
agentIdList = new List<long>();
32+
foreach (var s in args)
33+
{
34+
long agentId;
35+
if (long.TryParse(args[0], out agentId))
36+
{
37+
agentIdList.Add(agentId);
38+
}
39+
else
40+
{
41+
Tools.PrintError();
42+
break;
43+
}
44+
}
45+
}
46+
47+
private static void GetResult()
48+
{
49+
foreach (var agentId in agentIdList)
50+
{
51+
var agent = _api.Users.GetUser(agentId).User;
52+
53+
string[] solvedStatus = { "closed", "solved" };
54+
55+
56+
// Get the agents tickets
57+
if (agent.Id != null)
58+
{
59+
var ticketPage = _api.Tickets.GetTicketsByUserID((long)agent.Id);
60+
var agentTickets = ticketPage.Tickets.ToList();
61+
62+
// If more than 100 exist, import the rest as well
63+
while (!string.IsNullOrEmpty(ticketPage.NextPage))
64+
{
65+
ticketPage = _api.Tickets.GetByPageUrl<GroupTicketResponse>(ticketPage.NextPage);
66+
agentTickets.AddRange(ticketPage.Tickets.ToList());
67+
}
68+
69+
// Create a channel for this agent with the number of open tickets.
70+
var openTickets = agentTickets.Where(t => !solvedStatus.Contains(t.Status.ToLower())).ToList();
71+
var problems = openTickets.Count(t => t.Type.Equals("problem"));
72+
var incidents = openTickets.Count(t => t.Type.Equals("incident"));
73+
var tasks = openTickets.Count(t => t.Type.Equals("task"));
74+
75+
_xml.AddChannel(agent.Name + "(Problem)", problems.ToString());
76+
_xml.AddChannel(agent.Name + "(Incident)", incidents.ToString());
77+
_xml.AddChannel(agent.Name + "(Tasks)", tasks.ToString());
78+
_xml.AddChannel(agent.Name + "(Total open)", openTickets.Count.ToString());
79+
}
80+
}
81+
82+
// Output the finished XML.
83+
_xml.PrintXml();
1384
}
1485
}
1586
}

GetZendeskAgentStatisticsByAgentId/GetZendeskAgentStatisticsByAgentId.csproj

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<DebugSymbols>true</DebugSymbols>
1919
<DebugType>full</DebugType>
2020
<Optimize>false</Optimize>
21-
<OutputPath>bin\Debug\</OutputPath>
21+
<OutputPath>..\bin\Debug\</OutputPath>
2222
<DefineConstants>DEBUG;TRACE</DefineConstants>
2323
<ErrorReport>prompt</ErrorReport>
2424
<WarningLevel>4</WarningLevel>
@@ -33,6 +33,10 @@
3333
<WarningLevel>4</WarningLevel>
3434
</PropertyGroup>
3535
<ItemGroup>
36+
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
37+
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
38+
<Private>True</Private>
39+
</Reference>
3640
<Reference Include="System" />
3741
<Reference Include="System.Core" />
3842
<Reference Include="System.Xml.Linq" />
@@ -41,13 +45,24 @@
4145
<Reference Include="System.Data" />
4246
<Reference Include="System.Net.Http" />
4347
<Reference Include="System.Xml" />
48+
<Reference Include="ZendeskApi_v2, Version=3.2.14.0, Culture=neutral, processorArchitecture=MSIL">
49+
<HintPath>..\packages\ZendeskApi_v2.3.2.14\lib\net45\ZendeskApi_v2.dll</HintPath>
50+
<Private>True</Private>
51+
</Reference>
4452
</ItemGroup>
4553
<ItemGroup>
46-
<Compile Include="Program.cs" />
54+
<Compile Include="GetAgentStatsByAgentId.cs" />
4755
<Compile Include="Properties\AssemblyInfo.cs" />
4856
</ItemGroup>
4957
<ItemGroup>
5058
<None Include="App.config" />
59+
<None Include="packages.config" />
60+
</ItemGroup>
61+
<ItemGroup>
62+
<ProjectReference Include="..\Common\Common.csproj">
63+
<Project>{966cb1d4-42c9-4d90-876a-ce2466623d76}</Project>
64+
<Name>Common</Name>
65+
</ProjectReference>
5166
</ItemGroup>
5267
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
5368
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

GetZendeskStatsForPRTG.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "Common\Common.csp
99
EndProject
1010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GetZendeskGroupStats", "GetZendeskGroupStats\GetZendeskGroupStats.csproj", "{3B718B72-40DA-41D3-B343-56C00E2B9CC1}"
1111
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GetZendeskAgentStatisticsByAgentId", "GetZendeskAgentStatisticsByAgentId\GetZendeskAgentStatisticsByAgentId.csproj", "{B4F36DFB-44F0-439F-A777-2C69446C1701}"
13+
EndProject
1214
Global
1315
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1416
Debug|Any CPU = Debug|Any CPU
@@ -27,6 +29,10 @@ Global
2729
{3B718B72-40DA-41D3-B343-56C00E2B9CC1}.Debug|Any CPU.Build.0 = Debug|Any CPU
2830
{3B718B72-40DA-41D3-B343-56C00E2B9CC1}.Release|Any CPU.ActiveCfg = Release|Any CPU
2931
{3B718B72-40DA-41D3-B343-56C00E2B9CC1}.Release|Any CPU.Build.0 = Release|Any CPU
32+
{B4F36DFB-44F0-439F-A777-2C69446C1701}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33+
{B4F36DFB-44F0-439F-A777-2C69446C1701}.Debug|Any CPU.Build.0 = Debug|Any CPU
34+
{B4F36DFB-44F0-439F-A777-2C69446C1701}.Release|Any CPU.ActiveCfg = Release|Any CPU
35+
{B4F36DFB-44F0-439F-A777-2C69446C1701}.Release|Any CPU.Build.0 = Release|Any CPU
3036
EndGlobalSection
3137
GlobalSection(SolutionProperties) = preSolution
3238
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)