SNMP - Where is "TimeStamp" Syntax defined? - syntax

Where to import from the textual convention TimeStamp in SNMP MIB?
I have a MIB where I should add a timestamp, but I don't know where I can import its syntax from.

For an example MIB that uses TimeStamp, see
https://datatracker.ietf.org/doc/html/rfc4444#section-4
IMPORTS
TEXTUAL-CONVENTION, RowStatus, TruthValue, TimeStamp
FROM SNMPv2-TC -- RFC2579
It is defined in SNMPv2-TC, see
https://datatracker.ietf.org/doc/html/rfc2579

Related

Setting AWSDateTime for AppSync in AWS lambda function written in Python

I have a lambda function that needs to store an item in a DynamoDB table that is going to be used by AppSync. I want to add a createdAt and a updatedAt field to the item, as AWSDateTime types, and set them to the time of their creation. As explained here I need to use An extended ISO 8601 date and time string in the format YYYY-MM-DDThh:mm:ss.sssZ. I use:
import datetime from datetime
datetime.now().strftime('%Y-%m-%dT%H:%M:%SZ')
but what it gives me is something like 2022-03-26T18:23:47Z instead of 2022-03-26T18:23:47.210Z for example (The three number-places after the second are absent).
Could you please help me fix this?
Milliseconds are optional. Reduced precision formats are valid ISO 8601 timestamps and thus valid AWSDateTime types.
If milliseconds are meaningful to your use case, there are several ways to add them:
datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3] + 'Z'
datetime.now().isoformat(timespec='milliseconds') + 'Z'
# '2022-03-27T11:05:10.351Z'

Can anyone explain the difference between Uuid::generate and DB::generateKey?

Without thinking too hard about it I created a column of type [UUID] and successfully stored "strings" (as noted in the documentation, and generally referred to as a separate type altogether) returned from DB::generateKey in it.
Feels like I've done something I shouldn't have.
Can anyone share some light on this. Thanks in advance.
Mostly they return different types.
For clarity, DB::generateKey is equivalent to Uuid::generate |> toString
According to the standard library docs, it's the return type.
Uuid::generate() -> UUID
Generate a new UUID v4 according to RFC 4122
DB::generateKey() -> Str
Returns a random key suitable for use as a DB key
I believe the UUID type is a bitstring representation, that is, a specific sequence of bits in memory.
Whereas the Str type is a string representation of a UUID.

Choosing elasticsearch index dynamically python

How can I choose an index dynamically using python. My current code is as follows:
import os
import time
import datetime
from datetime import datetime
import shutil
from elasticsearch import Elasticsearch
from esindex import createIndex
client=Elasticsearch()
I have 1000's of images and the name of the image would be: 1559624525_cb704087042c76bf.jpg. I am splitting the name into two parts, timestamp (1559624525) and machid (cb704087042c76bf) and writing it into an es index.
path="/home/ubuntu/images/"
for root, dirs, files in os.walk(path):
for name in files:
try:
dat=name.split('_')[0]
machid=name.split('_')[1]
machid=machid.split('.')[0]
createIndex(machid) ##this creates index dynamically
dat=int(dat)
dat=datetime.utcfromtimestamp(dat).strftime('%d-%m-%Y %H:%M:%S')
dte=dat.split(' ')[0]
id=id+1
doc = {'sequence_id':id,'imagename': name, 'time_stamp': dat, 'date'=dte}
#print(doc)
client.index(index=machid, body=doc) ##this line is not working. If i comment this out, shutil works.
shutil.copy('/home/ubuntu/images/'+ name, '/home/ubuntu/test/')
os.remove('/home/ubuntu/images/' + name)
except Exception:
continue
how can i input a document into elasticsearch by dynamically choosing the index.
print the Exception in except block
Check machid is not empty
Since there is not any errors use Cat APIS to check any indeces created in your ES
curl -X GET "localhost:9200/_cat/indices"
Apparently I figured that my code works. In createIndex function I had a date field, which was set to date, however the above code parses the date as text. To test, when I changed the date to text in createIndex, everything fell in place. Replying this to complete the QA loop.

Is there a way to ensure that all data in a yaml string was parsed?

For testing, I often see go code read byte slices, which are parsed into structs using yaml, for example here:
https://github.com/kubernetes/kubernetes/blob/master/pkg/util/strategicpatch/patch_test.go#L74m
I just got bitten by not exporting my field names, resulting in an empty list which I iterated over in my test cases, thus assuming that all tests were passing (in hindsight, that should have been a red flag :)). There are other errors which are silently ignored by yaml unmarshaling, such as a key being misspelled and not matching a struct field exactly.
Is there a way to ensure that all the data in the byte slice was actually parsed into the struct returned by yaml.Unmarshal? If not, how do others handle this situation?
go-yaml/yaml
For anyone searching for a solution to this problem, the yaml.v2 library has an UnmarshalStrict method that returns an error if there are keys in the yaml document that have no corresponding fields in the go struct.
import yaml "gopkg.in/yaml.v2"
err := yaml.UnmarshalStrict(data, destinationStruct)
BurntSushi/toml
It's not part of the question, but I'd just like to document how to achieve something similar in toml:
You can find if there were any keys in the toml file that could not be decoded by using the metadata returned by the toml.decode function.
import "github.com/BurntSushi/toml"
metadata, err := toml.Decode(data, destinationStruct)
undecodedKeys := metadata.Undecoded()
Note that metadata.Undecoded() also returns keys that have not been decoded because of a Primitive value. You can read more about it here.
Json
The default go json library does not support this currently, but there is a proposal ready to be merged. It seems that it will be a part of go 1.10.

How to convert ISO 8601 time in golang?

What is the equivalent code in golang for the following shell command ?
date -u +%Y-%m-%dT%T%z
If you're looking for a simple, but not perfect solution consider using time.RFC3339 constant. But also know that there are differences between ISO8601 which are too complex for this answer.
See https://ijmacd.github.io/rfc3339-iso8601/ for differences and also has a handy test file generator to show differences. There is also a good discussion on SO here What's the difference between ISO 8601 and RFC 3339 Date Formats?
package main
import (
"time"
"fmt"
)
func main(){
fmt.Println(time.Now().Format(time.RFC3339))
}
golang Time.Format
package main
import (
"fmt"
"time"
)
func main() {
fmt.Println(time.Now().UTC().Format("2006-01-02T15:04:05-0700"))
}
I had the following spec:
YYYY-MM-DDThh:mm:ss.sssZ
with the final Z being explicitly present in the examples.
Here's how I dealt with it:
first I found the time.RFCxxx that was the closest to my target
I copied its value
I fiddled with it until I found the expected result
which is
2006-01-02T15:04:05.999Z
ISO8601 allows for variable levels of granularity. You can have just a year, year+month, year+month+day, add a time portion, and optionally have a timezone portion. Go's built-in time parsing, however, requires you to know ahead-of-time which parts will be included.
The github.com/btubbs/datetime library provides a more flexible parser that can handle all the commonly used ISO8601 formats. See https://github.com/btubbs/datetime
Disclosure: I wrote that library.
Replacing the sign in the format with a Z triggers the ISO 8601 behavior. Which is exactly time.RFC3339. If you are wanting the string output to end in 'Z' what you need to do is convert to the UTC zone.
package main
import (
"fmt"
"time"
)
func main() {
fmt.Println(time.Now().UTC().Format("2006-01-02T15:04:05Z07:00"))
}
// this is the same format used by RFC3339. just a note on why.

Resources