Skip to content

Commit d935d27

Browse files
committed
Modified daily job
1 parent feec0d8 commit d935d27

File tree

4 files changed

+73
-19
lines changed

4 files changed

+73
-19
lines changed
0 Bytes
Binary file not shown.
Binary file not shown.

AzureCost_to_LogAnalytics/AzureCost_to_LogAnalytics/AzureCost_to_LogAnalytics.cs

Lines changed: 72 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public static async void callAPIPage(string scope, string skipToken, string work
9292

9393

9494
[FunctionName("DailyCostLoad")]
95-
public static async void Run([TimerTrigger("0 0 14 * * *")]TimerInfo myTimer, ILogger log)
95+
public static async void Run([TimerTrigger("0 0 12 * * *")]TimerInfo myTimer, ILogger log)
9696
{
9797
DateTime start = DateTime.Now.AddDays(-1);
9898

@@ -169,29 +169,82 @@ public static async void Run([TimerTrigger("0 0 14 * * *")]TimerInfo myTimer, IL
169169

170170

171171
jsonResult = "[";
172-
for(int i = 0;i < result.properties.rows.Length;i++)
172+
for (int i = 0; i < result.properties.rows.Length; i++)
173173
{
174-
object[] row = result.properties.rows[i];
175-
double cost = Convert.ToDouble(row[0]);
176-
177-
if (i == 0)
178-
{
179-
jsonResult += $"{{\"PreTaxCost\": {cost},\"Date\": \"{row[1]}\",\"ResourceId\": \"{row[2]}\",\"ResourceType\": \"{row[3]}\",\"SubscriptionName\": \"{row[4]}\",\"ResourceGroup\": \"{row[5]}\"}}";
180-
}
181-
else
174+
object[] row;
175+
try
182176
{
183-
jsonResult += $",{{\"PreTaxCost\": {cost},\"Date\": \"{row[1]}\",\"ResourceId\": \"{row[2]}\",\"ResourceType\": \"{row[3]}\",\"SubscriptionName\": \"{row[4]}\",\"ResourceGroup\": \"{row[5]}\"}}";
177+
row = result.properties.rows[i];
178+
double cost = Convert.ToDouble(row[0]);
179+
string sDate = Convert.ToString(row[1]);
180+
string sResourceId;
181+
try
182+
{
183+
sResourceId = Convert.ToString(row[2]);
184+
}
185+
catch
186+
{
187+
sResourceId = "";
188+
}
189+
string sResourceType;
190+
try
191+
{
192+
sResourceType = Convert.ToString(row[3]);
193+
}
194+
catch
195+
{
196+
sResourceType = "";
197+
}
198+
string sSubscriptionName;
199+
try
200+
{
201+
sSubscriptionName = Convert.ToString(row[4]);
202+
}
203+
catch
204+
{
205+
sSubscriptionName = "";
206+
}
207+
string sResourceGroup;
208+
try
209+
{
210+
sResourceGroup = Convert.ToString(row[5]);
211+
}
212+
catch
213+
{
214+
sResourceGroup = "";
215+
}
216+
217+
218+
if (i == 0)
219+
{
220+
jsonResult += $"{{\"PreTaxCost\": {cost},\"Date\": \"{sDate}\",\"ResourceId\": \"{sResourceId}\",\"ResourceType\": \"{sResourceType}\",\"SubscriptionName\": \"{sSubscriptionName}\",\"ResourceGroup\": \"{sResourceGroup}\"}}";
221+
}
222+
else
223+
{
224+
jsonResult += $",{{\"PreTaxCost\": {cost},\"Date\": \"{sDate}\",\"ResourceId\": \"{sResourceId}\",\"ResourceType\": \"{sResourceType}\",\"SubscriptionName\": \"{sSubscriptionName}\",\"ResourceGroup\": \"{sResourceGroup}\"}}";
225+
}
226+
227+
228+
jsonResult += "]";
229+
230+
log.LogInformation($"Cost Data: {jsonResult}");
231+
Console.WriteLine($"Cost Data: {jsonResult}");
232+
logAnalytics.Post(jsonResult);
233+
234+
string nextLink = result.properties.nextLink.ToString();
235+
236+
if (!string.IsNullOrEmpty(nextLink))
237+
{
238+
string skipToken = nextLink.Split('&')[1];
239+
callAPIPage(scope, skipToken, workspaceid, workspacekey, logName, log, myJson);
240+
}
241+
242+
//return new OkObjectResult(jsonResult);
184243
}
185-
}
244+
catch
245+
{ }
186246

187-
jsonResult += "]";
188-
logAnalytics.Post(jsonResult);
189247

190-
if (result.properties.nextLink != null)
191-
{
192-
string nextLink = result.properties.nextLink.ToString();
193-
string skipToken = nextLink.Split('&')[1];
194-
callAPIPage(scope, skipToken, workspaceid, workspacekey, logName, log, myJson);
195248
}
196249
}
197250
}

AzureCost_to_LogAnalytics/AzureCost_to_LogAnalytics/PreLoadLogAnalytics.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ public static async Task<IActionResult> Run(
254254
}
255255
catch
256256
{ }
257+
257258
}
258259
}
259260

0 commit comments

Comments
 (0)