Azure function for handling stats
Creates a statistics document in {system}-collection in statistics database
See the example below for required fields. You can add as many optional fields as you like in addition to the required fields.
Example payload
const payload = {
"system": "Acos", // Required when not using system in param (url). System name. New system creates a new collection
"engine": "azf-acos-interact v1", // Required. e.g. from package json
"county": "VTFK", // Optional. If missing autogenerated from DEFAULT_COUNTY environment variable
"company": "SMM", // Required. Sector
"department": "Graveteam", // Optional. If missing, company will be set here.
"description": "Arkivering av gravesøknad og opprettelse av et listeelement i SP. Oppdaterer også kontaktobjektet i 360", // Required. A description of what the statistic element represents
"projectId": "Prosjekt ID (Hvis det er en kobling til innovasjonsløypa)", // Optional. If not set, will be set to "ingen prosjekttilknytning"
"type": "SMM - Gravesoknad", // Required. A short searchable type-name that distinguishes the statistic element
"externalId": "refId fra Acos", // Optional. ID in the external {system}
// optional fields:
"optionalField": "23/45678-3", // Optional. anything you like
"optionalField2": 4567895, // Optional. anything you like
// ...
"anotherLastOptionalkField": true // Optional. anything you like
}
Example payload - system from url will be used as "system" property and collection in stats db
const payload = {
"engine": "azf-acos-interact v1", // Required. e.g. from package json
"county": "VTFK", // Optional. If missing autogenerated from DEFAULT_COUNTY environment variable
"company": "SMM", // Required. Sector
"department": "Graveteam", // Optional. If missing, company will be set here.
"description": "Arkivering av gravesøknad og opprettelse av et listeelement i SP. Oppdaterer også kontaktobjektet i 360", // Required. A description of what the statistic element represents
"projectId": "Prosjekt ID (Hvis det er en kobling til innovasjonsløypa)", // Optional. If not set, will be set to "ingen prosjekttilknytning"
"type": "SMM - Gravesoknad", // Required. A short searchable type-name that distinguishes the statistic element
"externalId": "refId fra Acos", // Optional. ID in the external {system}
// optional fields:
"optionalField": "23/45678-3", // Optional. anything you like
"optionalField2": 4567895, // Optional. anything you like
// ...
"anotherLastOptionalkField": true // Optional. anything you like
}
Returns a list of all system names (collections) in the statistics db
Example request
GET https://{statsurl}/api/Systems
Example return value
[
"publish-teams-document",
"vigo-isi-arkiv",
"import-files-p360",
"tullball",
"Masseutsendelse",
"littasystem",
"IOP",
"onbaording",
"Digitroll",
"MinElev",
"hei med mellomrom",
"Acos skjema",
"onboarding",
"dos-arkivaros"
]
Returns stats for {system}
Example request
GET https://{statsurl}/api/Stats/Acos%20skjema
Example return value
[
{
"_id": "655f398962f1958a50d4eec5",
"system": "Acos skjema",
"engine": "azf-acos-interact 1.9.1",
"createdTimestamp": "2023-11-23T11:37:45.025Z",
"county": "VFK",
"company": "Opplæring",
"department": "EKSAMEN",
"description": "Sender til elevmappe",
"projectId": "ingen prosjekttilknytning",
"externalId": "1287555",
"type": "Søknad om tilrettelegging på fag, svenne eller kompetanseprøve"
},
{
"_id": "655f511e62f1958a50d4eec6",
"system": "Acos skjema",
"engine": "azf-acos-interact 1.9.1",
"createdTimestamp": "2023-11-23T13:18:22.648Z",
"county": "VFK",
"company": "HRMU",
"department": "Mestring og utvikling",
"description": "Arkivering av henvendelse til mobbeombud. Skal opprettes en ny sak pr skjema",
"projectId": "ingen prosjekttilknytning",
"externalId": "1287567",
"type": "Henvendelse til mobbeombud"
}
]
?count=true only returns the count of returned documents
Example request
GET https://{statsurl}/api/Stats/Acos%20skjema?count=true
Example response
156
?filter={filter} only returns documents that match the filter
Supported logical operators:
- and
- or
- nor
Supported comparison operators:
- eq
- gt
- gte
- lt
- lte
- ne (Not implemented until we need it: in, nin)
When using several logical operators on one level - you must use parenthesis
Comparisons must be on the format
Examples
GET https://{statsurl}/api/Stats/Acos%20skjema?filter=createdTimestamp gt 2024-01-01 and createdTimestamp lt 2025-01-01
GET https://{statsurl}/api/Stats/Acos%20skjema?filter=createdTimestamp gt 2024-01-01 and createdTimestamp lt 2025-01-01 and (type eq 'type 1' or type ne type2)
GET https://{statsurl}/api/Stats/Acos%20skjema?filter=createdTimestamp gt 2024-01-01 and createdTimestamp lt 2025-01-01 and (type eq 'type 1' or type ne type2)&count=true
can be combined with query param "count"
The filter is parsed by the horrific function in parse-query.js
?select=property1,property2 only returns the selected properties
if omitted, uses default select (in backend): select=_id,system,engine,createdTimestamp,county,company,department,description,projectId,externalId,type
Example
GET https://{statsurl}/api/Stats/Acos%20skjema?select=createdTimestamp,type
Returns
[
{
"_id": "655f398962f1958a50d4eec5",
"createdTimestamp": "2023-11-23T11:37:45.025Z",
"type": "Søknad om tilrettelegging på fag, svenne eller kompetanseprøve"
},
{
"_id": "655f511e62f1958a50d4eec6",
"createdTimestamp": "2023-11-23T13:18:22.648Z",
"type": "Henvendelse til mobbeombud"
}
]
Example for getting all properties ('select=all') (cannot use '*' due to azure WAF)
GET https://{statsurl}/api/Stats/Acos%20skjema?select=all
Returns
[
{
"_id": "655f398962f1958a50d4eec5",
"system": "Acos skjema",
"engine": "azf-acos-interact 1.9.1",
"createdTimestamp": "2023-11-23T11:37:45.025Z",
"county": "VFK",
"company": "Opplæring",
"department": "EKSAMEN",
"description": "Sender til elevmappe",
"projectId": "ingen prosjekttilknytning",
"externalId": "1287555",
"type": "Søknad om tilrettelegging på fag, svenne eller kompetanseprøve",
"documentNumber": "24/00001-12" // Additional property is also returned
},
{
"_id": "655f511e62f1958a50d4eec6",
"system": "Acos skjema",
"engine": "azf-acos-interact 1.9.1",
"createdTimestamp": "2023-11-23T13:18:22.648Z",
"county": "VFK",
"company": "HRMU",
"department": "Mestring og utvikling",
"description": "Arkivering av henvendelse til mobbeombud. Skal opprettes en ny sak pr skjema",
"projectId": "ingen prosjekttilknytning",
"externalId": "1287567",
"type": "Henvendelse til mobbeombud",
"documentNumber": "25/00098-3", // Additional property is also returned
"skole": "Tullball barneskole" // Additional property is also returned
}
]
__from
and __to
is generated ISO DateTime UTC stamps from Grafana
Returns Grafana table stat for all systems in a timeframe
Example request GET https://{statusurl}/api/Grafana?start=2025-03-21T10:20:00Z&end=2025-03-21T10:25:00Z
[
{
"system": "MinElev",
"count": 42
},
{
"system": "Acos skjema",
"count": 13
}
]
Returns Grafana stats for {system} in given timeframe
Example request GET https://{statusurl}/api/Grafana?start=2025-03-21T10:20:00Z&end=2025-03-21T10:25:00Z
[
{
"system": "MinElev",
"count": 42
},
{
"system": "Acos skjema",
"count": 13
}
]
- Clone the repo
- Make sure you have azure function core tools installed
npm i
- Create a local.settings.json file
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "node",
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"MONGO_STATISTICS_CONNECTION_STRING": "connectionstring",
"MONGO_DB_STATISTICS_DATABASE": "statistics db name",
"DEFAULT_COUNTY": "county name",
"BETTERSTACK_URL": "URL to betterstack",
"BETTERSTACK_TOKEN": "token for betterstack",
"NODE_ENV": "development"
}
}
func start