├── .gitignore
├── HTTPDataCollectorAPI.sln
├── HTTPDataCollectorAPI
├── Collector.cs
├── HTTPDataCollectorAPI.csproj
├── HTTPDataCollectorAPI.xproj.nuspec
└── ICollector.cs
├── LICENSE
├── README.md
└── test
├── .gitignore
├── HTTPDataCollectorAPITests.cs
├── test.csproj
└── xunit.runner.json
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | build/
21 | bld/
22 | [Bb]in/
23 | [Oo]bj/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | artifacts/
46 |
47 | *_i.c
48 | *_p.c
49 | *_i.h
50 | *.ilk
51 | *.meta
52 | *.obj
53 | *.pch
54 | *.pdb
55 | *.pgc
56 | *.pgd
57 | *.rsp
58 | *.sbr
59 | *.tlb
60 | *.tli
61 | *.tlh
62 | *.tmp
63 | *.tmp_proj
64 | *.log
65 | *.vspscc
66 | *.vssscc
67 | .builds
68 | *.pidb
69 | *.svclog
70 | *.scc
71 |
72 | # Chutzpah Test files
73 | _Chutzpah*
74 |
75 | # Visual C++ cache files
76 | ipch/
77 | *.aps
78 | *.ncb
79 | *.opendb
80 | *.opensdf
81 | *.sdf
82 | *.cachefile
83 |
84 | # Visual Studio profiler
85 | *.psess
86 | *.vsp
87 | *.vspx
88 | *.sap
89 |
90 | # TFS 2012 Local Workspace
91 | $tf/
92 |
93 | # Guidance Automation Toolkit
94 | *.gpState
95 |
96 | # ReSharper is a .NET coding add-in
97 | _ReSharper*/
98 | *.[Rr]e[Ss]harper
99 | *.DotSettings.user
100 |
101 | # JustCode is a .NET coding add-in
102 | .JustCode
103 |
104 | # TeamCity is a build add-in
105 | _TeamCity*
106 |
107 | # DotCover is a Code Coverage Tool
108 | *.dotCover
109 |
110 | # NCrunch
111 | _NCrunch_*
112 | .*crunch*.local.xml
113 | nCrunchTemp_*
114 |
115 | # MightyMoose
116 | *.mm.*
117 | AutoTest.Net/
118 |
119 | # Web workbench (sass)
120 | .sass-cache/
121 |
122 | # Installshield output folder
123 | [Ee]xpress/
124 |
125 | # DocProject is a documentation generator add-in
126 | DocProject/buildhelp/
127 | DocProject/Help/*.HxT
128 | DocProject/Help/*.HxC
129 | DocProject/Help/*.hhc
130 | DocProject/Help/*.hhk
131 | DocProject/Help/*.hhp
132 | DocProject/Help/Html2
133 | DocProject/Help/html
134 |
135 | # Click-Once directory
136 | publish/
137 |
138 | # Publish Web Output
139 | *.[Pp]ublish.xml
140 | *.azurePubxml
141 | # TODO: Comment the next line if you want to checkin your web deploy settings
142 | # but database connection strings (with potential passwords) will be unencrypted
143 | *.pubxml
144 | *.publishproj
145 |
146 | # NuGet Packages
147 | *.nupkg
148 | # The packages folder can be ignored because of Package Restore
149 | **/packages/*
150 | # except build/, which is used as an MSBuild target.
151 | !**/packages/build/
152 | # Uncomment if necessary however generally it will be regenerated when needed
153 | #!**/packages/repositories.config
154 |
155 | # Microsoft Azure Build Output
156 | csx/
157 | *.build.csdef
158 |
159 | # Microsoft Azure Emulator
160 | ecf/
161 | rcf/
162 |
163 | # Microsoft Azure ApplicationInsights config file
164 | ApplicationInsights.config
165 |
166 | # Windows Store app package directory
167 | AppPackages/
168 | BundleArtifacts/
169 |
170 | # Visual Studio cache files
171 | # files ending in .cache can be ignored
172 | *.[Cc]ache
173 | # but keep track of directories ending in .cache
174 | !*.[Cc]ache/
175 |
176 | # Others
177 | ClientBin/
178 | ~$*
179 | *~
180 | *.dbmdl
181 | *.dbproj.schemaview
182 | *.pfx
183 | *.publishsettings
184 | node_modules/
185 | orleans.codegen.cs
186 |
187 | # RIA/Silverlight projects
188 | Generated_Code/
189 |
190 | # Backup & report files from converting an old project file
191 | # to a newer Visual Studio version. Backup files are not needed,
192 | # because we have git ;-)
193 | _UpgradeReport_Files/
194 | Backup*/
195 | UpgradeLog*.XML
196 | UpgradeLog*.htm
197 |
198 | # SQL Server files
199 | *.mdf
200 | *.ldf
201 |
202 | # Business Intelligence projects
203 | *.rdl.data
204 | *.bim.layout
205 | *.bim_*.settings
206 |
207 | # Microsoft Fakes
208 | FakesAssemblies/
209 |
210 | # GhostDoc plugin setting file
211 | *.GhostDoc.xml
212 |
213 | # Node.js Tools for Visual Studio
214 | .ntvs_analysis.dat
215 |
216 | # Visual Studio 6 build log
217 | *.plg
218 |
219 | # Visual Studio 6 workspace options file
220 | *.opt
221 |
222 | # Visual Studio LightSwitch build output
223 | **/*.HTMLClient/GeneratedArtifacts
224 | **/*.DesktopClient/GeneratedArtifacts
225 | **/*.DesktopClient/ModelManifest.xml
226 | **/*.Server/GeneratedArtifacts
227 | **/*.Server/ModelManifest.xml
228 | _Pvt_Extensions
229 |
230 | # Paket dependency manager
231 | .paket/paket.exe
232 |
233 | # FAKE - F# Make
234 | .fake/
235 |
--------------------------------------------------------------------------------
/HTTPDataCollectorAPI.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26206.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HTTPDataCollectorAPI", "HTTPDataCollectorAPI\HTTPDataCollectorAPI.csproj", "{2F319A14-F56D-4366-AF4C-65D1FD350227}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "test", "test\test.csproj", "{9AE516B4-0D54-48E1-9799-59553C6FC4BF}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {2F319A14-F56D-4366-AF4C-65D1FD350227}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {2F319A14-F56D-4366-AF4C-65D1FD350227}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {2F319A14-F56D-4366-AF4C-65D1FD350227}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 | {2F319A14-F56D-4366-AF4C-65D1FD350227}.Release|Any CPU.Build.0 = Release|Any CPU
20 | {9AE516B4-0D54-48E1-9799-59553C6FC4BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {9AE516B4-0D54-48E1-9799-59553C6FC4BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {9AE516B4-0D54-48E1-9799-59553C6FC4BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {9AE516B4-0D54-48E1-9799-59553C6FC4BF}.Release|Any CPU.Build.0 = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/HTTPDataCollectorAPI/Collector.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Net;
4 | using System.Security.Cryptography;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace HTTPDataCollectorAPI
9 | {
10 | ///
11 | /// HTTP Data Collector API wrapper
12 | ///
13 | public class Collector : ICollector
14 | {
15 | private string _WorkspaceId;
16 | private string _SharedKey;
17 | private byte[] _SharedKeyBytes;
18 | private string _ServiceNamespace;
19 | ///
20 | /// Wrapper for reporting custom JSON events to Azure Log Analytics
21 | ///
22 | /// Workspace Id obtained from your Microsoft Operations Management Suite account, Settings > Connected Sources.
23 | /// Primary or Secondary Key obtained from your Microsoft Operations Management Suite account, Settings > Connected Sources.
24 | /// Optional. Allows to change the service endpoint to use the library in different clouds.
25 | public Collector(string WorkspaceId, string SharedKey, string ServiceNamespace = "ods.opinsights.azure.com")
26 | {
27 | _WorkspaceId = WorkspaceId;
28 | _SharedKey = SharedKey;
29 | _SharedKeyBytes = Convert.FromBase64String(_SharedKey);
30 | _ServiceNamespace = ServiceNamespace;
31 | }
32 |
33 | ///
34 | /// Collect a JSON log to Azure Log Analytics
35 | ///
36 | /// Name of the Type of Log. Can be any name you want to appear on Azure Log Analytics.
37 | /// Object to serialize and collect.
38 | /// Optional. Api Version.
39 | public async Task Collect(string LogType, object ObjectToSerialize, string ApiVersion="2016-04-01", string timeGeneratedPropertyName = null)
40 | {
41 | await Collect(LogType, Newtonsoft.Json.JsonConvert.SerializeObject(ObjectToSerialize), ApiVersion, timeGeneratedPropertyName);
42 | }
43 | ///
44 | /// Collect a JSON log to Azure Log Analytics
45 | ///
46 | /// Name of the Type of Log. Can be any name you want to appear on Azure Log Analytics.
47 | /// JSON string. Can be an array or single object.
48 | /// Optional. Api Version.
49 | public async Task Collect(string LogType, string JsonPayload, string ApiVersion="2016-04-01", string timeGeneratedPropertyName = null)
50 | {
51 | var utf8Encoding = new UTF8Encoding();
52 | Byte[] content = utf8Encoding.GetBytes(JsonPayload);
53 |
54 | string url = "https://" + _WorkspaceId + "."+ _ServiceNamespace + "/api/logs?api-version=" + ApiVersion;
55 | var rfcDate = DateTime.Now.ToUniversalTime().ToString("r");
56 | var signature = HashSignature("POST", content.Length, "application/json", rfcDate, "/api/logs");
57 |
58 | HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
59 | request.ContentType = "application/json";
60 | request.Method = "POST";
61 | request.Headers["Log-Type"] = LogType;
62 | request.Headers["x-ms-date"] = rfcDate;
63 | request.Headers["Authorization"] = signature;
64 | if (!string.IsNullOrEmpty(timeGeneratedPropertyName))
65 | {
66 | request.Headers["time-generated-field"] = timeGeneratedPropertyName;
67 | }
68 | request.Proxy = null;
69 | using (Stream requestStream = await request.GetRequestStreamAsync())
70 | {
71 | requestStream.Write(content, 0, content.Length);
72 | }
73 |
74 | using (HttpWebResponse response = (HttpWebResponse) await request.GetResponseAsync())
75 | {
76 | if (!response.StatusCode.Equals(HttpStatusCode.OK) && !response.StatusCode.Equals(HttpStatusCode.Accepted))
77 | {
78 | //Take response body and throw it as an exception
79 | Stream dataStream = response.GetResponseStream();
80 | using (StreamReader reader = new StreamReader(dataStream))
81 | {
82 | throw new Exception(reader.ReadToEnd());
83 | }
84 | }
85 | }
86 | }
87 |
88 | ///
89 | /// SHA256 signature hash
90 | ///
91 | ///
92 | private string HashSignature(string method, int contentLength, string contentType, string date, string resource)
93 | {
94 | var stringtoHash = method + "\n" + contentLength + "\n" + contentType + "\nx-ms-date:" + date + "\n" + resource;
95 | var encoding = new System.Text.ASCIIEncoding();
96 | var bytesToHash = encoding.GetBytes(stringtoHash);
97 | using (var sha256 = new HMACSHA256(_SharedKeyBytes))
98 | {
99 | var calculatedHash = sha256.ComputeHash(bytesToHash);
100 | var stringHash = Convert.ToBase64String(calculatedHash);
101 | return "SharedKey " + _WorkspaceId + ":" + stringHash;
102 | }
103 | }
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/HTTPDataCollectorAPI/HTTPDataCollectorAPI.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Azure Log Analytics HTTP DataCollector API wrapper
5 | 1.0.5
6 | ealsur
7 | netstandard1.3;net461;net46;net45
8 | HTTPDataCollectorAPI
9 | HTTPDataCollectorAPI
10 | azure;log;analytics
11 | https://github.com/ealsur/HTTPDataCollectorAPI
12 | https://github.com/ealsur/HTTPDataCollectorAPI/blob/master/LICENSE
13 | 1.6.0
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/HTTPDataCollectorAPI/HTTPDataCollectorAPI.xproj.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | HTTPDataCollectorAPICollector
5 | $version$
6 | ealsur
7 | ealsur
8 | https://github.com/ealsur/HTTPDataCollectorAPI/blob/master/LICENSE
9 | https://github.com/ealsur/HTTPDataCollectorAPI
10 | false
11 | Azure Log Analytics HTTP Data Collector API wrapper
12 | Interface optional parameters
13 | Copyright 2018. Ealsur.
14 | azure log analytics
15 |
16 |
17 |
--------------------------------------------------------------------------------
/HTTPDataCollectorAPI/ICollector.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 |
3 | namespace HTTPDataCollectorAPI
4 | {
5 | ///
6 | /// Interface for HTTP Data Collector API wrapper
7 | ///
8 | public interface ICollector
9 | {
10 | Task Collect(string LogType, string JsonPayload, string ApiVersion = "2016-04-01", string timeGeneratedPropertyName = null);
11 | Task Collect(string LogType, object ObjectToSerialize, string ApiVersion = "2016-04-01", string timeGeneratedPropertyName = null);
12 | }
13 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2016 Matías Quaranta
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Azure Log Analytics HTTP Collector API wrapper
2 |
3 | This package is a .Net adaptation of the Powershell code for implementing the HTTP Collector API for Azure Log Analytics as seen on [the announcement](https://blogs.technet.microsoft.com/msoms/2016/08/30/http-data-collector-api-send-us-data-from-space-or-anywhere/).
4 |
5 | [Full API Documentation](https://azure.microsoft.com/documentation/articles/log-analytics-data-collector-api/)
6 |
7 | ## Get it
8 |
9 | You can obtain this project as a [Nuget Package](https://www.nuget.org/packages/HTTPDataCollectorAPI).
10 |
11 | Install-Package HTTPDataCollectorAPI
12 |
13 | Or reference it and use it according to the [License](./LICENSE).
14 |
15 | ## Use it
16 |
17 | Using it is simple:
18 |
19 | var collector = new HTTPDataCollectorAPI.Collector("{Your_Workspace_Id}", "{Your_Workspace_Key}");
20 | await collector.Collect("TestLogType", "{\"TestAttribute\":\"TestValue\"}");
21 |
22 | You can also pass serializable objects (they will be serialized with [Newtonsoft.Json](https://www.nuget.org/packages/Newtonsoft.Json)):
23 |
24 | var anObject = new MySerializableClass(){
25 | MyIntAttribute = 4,
26 | MyStringAttribute = "hello",
27 | MyListAttribute = new List(){"one","two"}
28 | };
29 | var collector = new HTTPDataCollectorAPI.Collector("{Your_Workspace_Id}", "{Your_Workspace_Key}");
30 | await collector.Collect("TestLogType", anObject);
31 |
32 | If you are using a Depedency Injection mechanism (or ASP.NET Core) you can use the available interface. In ASP.NET Core for example:
33 |
34 | public void ConfigureServices(IServiceCollection services)
35 | {
36 | //... some other code
37 | services.AddSingleton();
38 | }
39 |
40 | ## Does it work on Azure Gov clouds?
41 |
42 | Yes, just use the constructor overload to define the cloud service endpoint:
43 |
44 | var collector = new HTTPDataCollectorAPI.Collector("{Your_Workspace_Id}", "{Your_Workspace_Key}", "ods.opinsights.azure.us");
45 |
46 | ## Issues
47 |
48 | Please feel free to [report any issues](https://github.com/ealsur/HTTPDataCollectorAPI/issues) you might encounter. Keep in mind that this library won't assure that your JSON payloads are being indexed, it will make sure that the HTTP Data Collection API [responds an Accept](https://azure.microsoft.com/en-us/documentation/articles/log-analytics-data-collector-api/#return-codes) but there is no way (right now) to know when has the payload been indexed completely.
49 |
50 | ## Supported Frameworks
51 |
52 | * .Net 4.5 Full Framework
53 | * .Net 4.6 Full Framework
54 | * .Net 4.6.1 Full Framework
55 | * [.Net Standard Library](https://docs.microsoft.com/en-us/dotnet/articles/standard/library) 1.3
56 |
--------------------------------------------------------------------------------
/test/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | build/
21 | bld/
22 | [Bb]in/
23 | [Oo]bj/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | artifacts/
46 |
47 | *_i.c
48 | *_p.c
49 | *_i.h
50 | *.ilk
51 | *.meta
52 | *.obj
53 | *.pch
54 | *.pdb
55 | *.pgc
56 | *.pgd
57 | *.rsp
58 | *.sbr
59 | *.tlb
60 | *.tli
61 | *.tlh
62 | *.tmp
63 | *.tmp_proj
64 | *.log
65 | *.vspscc
66 | *.vssscc
67 | .builds
68 | *.pidb
69 | *.svclog
70 | *.scc
71 |
72 | # Chutzpah Test files
73 | _Chutzpah*
74 |
75 | # Visual C++ cache files
76 | ipch/
77 | *.aps
78 | *.ncb
79 | *.opendb
80 | *.opensdf
81 | *.sdf
82 | *.cachefile
83 |
84 | # Visual Studio profiler
85 | *.psess
86 | *.vsp
87 | *.vspx
88 | *.sap
89 |
90 | # TFS 2012 Local Workspace
91 | $tf/
92 |
93 | # Guidance Automation Toolkit
94 | *.gpState
95 |
96 | # ReSharper is a .NET coding add-in
97 | _ReSharper*/
98 | *.[Rr]e[Ss]harper
99 | *.DotSettings.user
100 |
101 | # JustCode is a .NET coding add-in
102 | .JustCode
103 |
104 | # TeamCity is a build add-in
105 | _TeamCity*
106 |
107 | # DotCover is a Code Coverage Tool
108 | *.dotCover
109 |
110 | # NCrunch
111 | _NCrunch_*
112 | .*crunch*.local.xml
113 | nCrunchTemp_*
114 |
115 | # MightyMoose
116 | *.mm.*
117 | AutoTest.Net/
118 |
119 | # Web workbench (sass)
120 | .sass-cache/
121 |
122 | # Installshield output folder
123 | [Ee]xpress/
124 |
125 | # DocProject is a documentation generator add-in
126 | DocProject/buildhelp/
127 | DocProject/Help/*.HxT
128 | DocProject/Help/*.HxC
129 | DocProject/Help/*.hhc
130 | DocProject/Help/*.hhk
131 | DocProject/Help/*.hhp
132 | DocProject/Help/Html2
133 | DocProject/Help/html
134 |
135 | # Click-Once directory
136 | publish/
137 |
138 | # Publish Web Output
139 | *.[Pp]ublish.xml
140 | *.azurePubxml
141 | # TODO: Comment the next line if you want to checkin your web deploy settings
142 | # but database connection strings (with potential passwords) will be unencrypted
143 | *.pubxml
144 | *.publishproj
145 |
146 | # NuGet Packages
147 | *.nupkg
148 | # The packages folder can be ignored because of Package Restore
149 | **/packages/*
150 | # except build/, which is used as an MSBuild target.
151 | !**/packages/build/
152 | # Uncomment if necessary however generally it will be regenerated when needed
153 | #!**/packages/repositories.config
154 |
155 | # Microsoft Azure Build Output
156 | csx/
157 | *.build.csdef
158 |
159 | # Microsoft Azure Emulator
160 | ecf/
161 | rcf/
162 |
163 | # Microsoft Azure ApplicationInsights config file
164 | ApplicationInsights.config
165 |
166 | # Windows Store app package directory
167 | AppPackages/
168 | BundleArtifacts/
169 |
170 | # Visual Studio cache files
171 | # files ending in .cache can be ignored
172 | *.[Cc]ache
173 | # but keep track of directories ending in .cache
174 | !*.[Cc]ache/
175 |
176 | # Others
177 | ClientBin/
178 | ~$*
179 | *~
180 | *.dbmdl
181 | *.dbproj.schemaview
182 | *.pfx
183 | *.publishsettings
184 | node_modules/
185 | orleans.codegen.cs
186 |
187 | # RIA/Silverlight projects
188 | Generated_Code/
189 |
190 | # Backup & report files from converting an old project file
191 | # to a newer Visual Studio version. Backup files are not needed,
192 | # because we have git ;-)
193 | _UpgradeReport_Files/
194 | Backup*/
195 | UpgradeLog*.XML
196 | UpgradeLog*.htm
197 |
198 | # SQL Server files
199 | *.mdf
200 | *.ldf
201 |
202 | # Business Intelligence projects
203 | *.rdl.data
204 | *.bim.layout
205 | *.bim_*.settings
206 |
207 | # Microsoft Fakes
208 | FakesAssemblies/
209 |
210 | # GhostDoc plugin setting file
211 | *.GhostDoc.xml
212 |
213 | # Node.js Tools for Visual Studio
214 | .ntvs_analysis.dat
215 |
216 | # Visual Studio 6 build log
217 | *.plg
218 |
219 | # Visual Studio 6 workspace options file
220 | *.opt
221 |
222 | # Visual Studio LightSwitch build output
223 | **/*.HTMLClient/GeneratedArtifacts
224 | **/*.DesktopClient/GeneratedArtifacts
225 | **/*.DesktopClient/ModelManifest.xml
226 | **/*.Server/GeneratedArtifacts
227 | **/*.Server/ModelManifest.xml
228 | _Pvt_Extensions
229 |
230 | # Paket dependency manager
231 | .paket/paket.exe
232 |
233 | # FAKE - F# Make
234 | .fake/
235 |
--------------------------------------------------------------------------------
/test/HTTPDataCollectorAPITests.cs:
--------------------------------------------------------------------------------
1 | using Xunit;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Threading.Tasks;
5 |
6 | namespace HTTPDataCollectorAPI.Test
7 | {
8 | public class HTTPDataCollectorAPITests
9 | {
10 | public class MySerializableClass{
11 | public int MyIntAttribute{get;set;}
12 | public string MyStringAttribute{get;set;}
13 | public List MyListAttribute{get;set;}
14 | }
15 | [Fact]
16 | public async Task SendingValidPayload()
17 | {
18 | ICollector collector = new HTTPDataCollectorAPI.Collector("{Your_Workspace_Id}", "{Your_Workspace_Key}");
19 | await collector.Collect("TestLogType", "{\"TestAttribute\":\"TestValue\"}");
20 | }
21 |
22 | [Fact]
23 | public async Task SendingValidObject()
24 | {
25 | var anObject = new MySerializableClass(){
26 | MyIntAttribute = 4,
27 | MyStringAttribute = "hello",
28 | MyListAttribute = new List(){"one","two"}
29 | };
30 | ICollector collector = new HTTPDataCollectorAPI.Collector("{Your_Workspace_Id}", "{Your_Workspace_Key}");
31 | await collector.Collect("TestLogType", anObject);
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/test/test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.1
5 | test
6 | test
7 | true
8 |
9 |
10 |
11 |
12 | PreserveNewest
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | all
24 | runtime; build; native; contentfiles; analyzers
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/test/xunit.runner.json:
--------------------------------------------------------------------------------
1 | {
2 | "diagnosticMessages": false,
3 | "methodDisplay": "classAndMethod",
4 | "parallelizeTestCollections": true
5 | }
6 |
--------------------------------------------------------------------------------