SharpSNMP: Error running VB.NET code for snmpget - sharp-snmp

I am trying to run the snmpget code sample in VB.NET available at:
https://github.com/lextm/sharpsnmplib/blob/master/Samples/VB.NET/snmpget/
When I try to run the code, I get the following exception:
http://i.stack.imgur.com/S5s9Z.png
The text on the exception indicates that the length of the string used to instantiate ObjectIdentifier is less than 2. However, this is not the case as seen in the watch window.
Could you let me know:
Any suggestions to fix this error. Am I not passing the command line args correctly?
Could you provide a sample command line argument string for SNMP v3?
Thank you for all the support!

The error message is clear enough that you cannot pass "0", or any other string that contains a single number. A valid OID requires at least two portion, such as "0.0".
https://sharpsnmplib.codeplex.com/wikipage?title=600001&referringTitle=KB
Command line tool usage can be found in KB6000001 and you can find other documentation on CodePlex too,
https://sharpsnmplib.codeplex.com/documentation

Related

open() throwing mypy issues which reading an image file

I have the following line of code which reads an image (which is fed into a POST request):
files = {"image": (image_path, open(image_path, "rb"))}
While trying to run this through mypy, it keeps throwing the following error:
Argument 1 to "open" has incompatible type "Optional[str]"; expected "Union[Union[str, bytes, PathLike[str], PathLike[bytes]], int]"
I've tried searching this, but I've not found a solution for similar problems.
Is there a different way to read filepaths in order to avoid these issues?
Not the correct answer but if you want to temporarily make it go away to move ahead:
# type: ignore
at the end of the erroring line should work.

Throws error when passing argument with space in JAVA_OPTS in Linux

I am passing command line parameters to gatling script.
This works and executes my test in Windows operating system:
set JAVA_OPTS="-DuserCount=2 -DflowRepeatCount=3 -DdefinitionId=102168 -DtestServerUrl=https://someURL -DenvAuthenticationHeaderFromPostman="Basic UWRZm9aGwsxFsB1V7RXK0OlB5cmZvcm1hbmNldGVzdDE="
It works and takes input which is passed
**********************INPUT*************************************
User Count ====>> 2
Repeat Count ====>> 3
Definition ID ====>> 102168
Environment URL ====>> https://someURL
Authentication Header ====>> Basic UWRZm9aGwsxFsB1V7RXK0OlB5cmZvcm1hbmNldGVzdDE=
***********************************************************
I want to do this same thing on Linux System.
While if I use this command in Linux then it throws error or takes Null or Binary values as input
(Passing arguments with ./gatling.sh)
JAVA_OPTS="-DuserCount=2 -DflowRepeatCount=3 -DdefinitionId=102168 -DtestServerUrl='https://someURL' -DenvAuthenticationHeaderFromPostman='Basic UWRZm9aGwsxFsB1V7RXK0OlB5cmZvcm1hbmNldGVzdDE='" ./gatling.sh
Gives this error,
GATLING_HOME is set to /opt/gatling-charts-highcharts-2.0.3 Error:
Could not find or load main class
UWRZm9aGwsxFsB1V7RXK0OlB5cmZvcm1hbmNldGVzdDE='
Here the problem is the space given in argument of -DenvAuthenticationHeaderFromPostman='Basic UWRZm9aGwsxFsB1V7RXK0OlB5cmZvcm1hbm='.
What is the solution?
The problem is that the $JAVA_OPTS variable is probably not surrounded by quotes. See this question: Passing a space-separated System Property via a shell script doesn't work
The gatling guys clearly forgot to do that.
I would file a bug and/or just edit gatling.sh.
Ideally though you might just want to consider seeing if Gatling takes a properties file or some other way to configure.

IMAP fetch() returns command error: BAD [b' Command Argument Error. 12']

I'm having trouble finding examples/troubleshooting tips online, and am not quite sure that I'm interpreting the documentation correctly. Any assistance would be greatly appreciated.
I'm connecting to an e-mail server, and want to read the e-mail subjects, and bodies. I first make my connection like so:
import imaplib
c = imaplib.IMAP4_SSL(hostname, port)
c.login(username, password)
foldername = 'INBOX/SSR'
c.select(str.encode(foldername), readonly = True)
today = datetime.date.today().strftime('%d-%b-%Y')
searchcriteria = '(SENTON '{}')'.format(today)
typ, msg_ids = c.search(None, searchcriteria)
msg_ids = [s.decode('ascii') for s in msg_ids]
for idnumber in msg_ids:
print(c.fetch(idnumber, "(BODY.PEEK[HEADER])"))
The code and works and output looks as expected, up until the last line, at which point, I get
imaplib.error: FETCH command error: BAD [b' Command Argument Error. 12']
My line of thought, and subsequent testing examined the following possible issues:
bytes vs. string. I converted input back to bytes, but the error remained constant
improper syntax: I tried other commands, such as BODY, SUBJECT, and ENVELOPE but still got the same message.
I'm not sure how to interpret the error, and don't really know where to start. Referencing https://www.rfc-editor.org/rfc/rfc3501.html from pp. 102+, I noticed that the values are labeled differently, but don't understand what the issue is with my implementation. How should I interpret the error? What is wrong with my syntax?
P.S. Correct me if I'm wrong, but the c.search shouldn't change my directory, yes? As in, by selecting foldername, I "navigate" to the selected folder, but just searching only returns values and shouldn't change my location?
I encountered the same problem while I tried to list or select a new mailbox - BAD [b' Command Argument Error. 12'], in my case, it didn't work with “Sent Box”, but it worked well with “Outbox”, so the space symbol is the point.
So it worked with c.select('"{}"'.format("Sent Box")...
Hope this information could help you.
Your last line is not correct msg_ids = [s.decode('ascii') for s in msg_ids]
msg_ids is a list with bytes string, not with elements of a list - example: [b'123 124 125']
Change the last line into msg_ids = msg_ids[0].split(b' ') and it will work as expected.

linux - running system command in R and then writing output to a file

I have R code as below. Below code resides in a file called 'iot.R'. I am executing it in Linux.
I want to print content of variable 'fileinformation' to a file mentioned by file=fileConn...
I thought that the 3rd line will solve the issue, but it is not giving the required output :(
fileinformation = system(paste("file", filenames[1]))
#print(fileinformation)
cat(print(fileinformation),"\r\n","\r\n", file=fileConn)
When I run the file, i get below result. It prints to my screen, rather than writing to the file :(
> source('iot.R')
CH7Data_20130401T135010.csv: ASCII text, with CRLF line terminators
[1] 0
--------------------update1
I also tried below command, but didnt get the expected rsult
cat(capture.output(fileinformation),"\r\n","\r\n", file=fileConn)
You need to set the intern argument to TRUE in your call to system. For instance:
fileinformation<-system("file cinzia_2.gif",intern=TRUE)
fileinformation
#[1] "cinzia_2.gif: GIF image data, version 89a, 640 x 640"
Of course I tried a file on my pc. Setting intern to TRUE the return value of system becomes the console output of the command. Then, when you call cat, you don't need to enclose fileinformation into print, but a simple cat(fileinformation,"\r\n","\r\n", file=fileConn) will suffice.
Hi Just a comment as I dont have enough rep to comment in the normal way. but cant you use
write.table
to save the output to a file? It may be easier?

learnyounode 'My First I/O' example

This program puzzles me. The goal of this program is to count the number of newlines in a file and output it in command prompt. Learnyounode then runs their own check on the file and sees if their answer matches your answer.
So I start with the answer :
var fs = require('fs');
var filename = process.argv[2];
file = fs.readFileSync(filename);
contents = file.toString();
console.log(contents.split('\n').length - 1);
learnyounode verifies that this program correctly counts the number of new lines. But when I change the program to any of the following, it doesn't print out the same number as learnyounode prints out.
file = fs.readFileSync(C:/Nick/test.txt);
file = fs.readFileSync(test.txt);
Shouldn't nodejs readFileSync be able to input an address and read it correctly?
Lastly, this program is supposed to print out the # of newlines in a program. Why does both the correct program and learnyounode print out the same number that is different from the amount of newlines everytime I run this program?
For example, the number of newlines in test.txt is 3. But running this program prints out a different number everytime, like 45, 15, 2, etc. Yet at the same time, it is verified as a correct program by learnyounode because both their answers match! What is going on?
EDIT:
test.txt looks like this
ok
testing
123
So, I tried your program on my local machine and your program works fine. I am not an expert on learnyounode. I just tried it after your question but I think I understand how it works. As such, here are the answers to your questions:
Shouldn't nodejs readFileSync be able to input an address and read it correctly?
This method from nodejs is working fine. You can try printing the contents of the file and you'll see that there are no problems.
Why does both the correct program and learnyounode print out the same number that is different from the amount of newlines everytime I run this program.
learnyounode is running your program with a different filename as input each time. It verifies the output of your program by running its own copy of correct code against the same file.
But when I change the program to any of the following, it doesn't print out the same number as learnyounode prints out.
That is because at this point, your code is processing a fixed file whereas learnyounode is still processing different files on each iteration.
This tripped me up too. If you read the learnyounode instructions closely they explicitly say...
"The full path to the file to read will be provided as the first command-line argument."
This means they are providing the path to their own file.
When you use process.argv[2], this is passing in the 3rd array item (the learnyounode test txt file) into your script. If you run a console.log(process.argv); you'll see the full array object looks something like this:
[ '/usr/local/bin/node',
'/Users/user/pathstuff/learnyounode/firstio.js',
'/var/folders/41/p2jvc80j26l7nty0sk0zs1z40000gn/T/_learnyounode_1613.txt' ]
The reason the validation numbers begin to mismatch when you substitute your own text file for their is because your file always has 3 lines whereas their unit tests keep passing in different length files via process.argv.
Hope that helps.
when you are using process.argv[2] in learnyounode, the argument is provided by learnyounode automatically, so it prints different number of lines like 45, 15, 2 etc at multiple times verification.
If you remember the second challenge "BABYSTEPS" carefully this was given:
learnyounode will be supplying arguments to your program when you run
learnyounode verify program.js so you don't need to supply them yourself.
That's why different line numbers at program.js verification on multiple times.
there are two different ways.
if you run program like:
node program_name.js
than you need to add path to text file:
node program_name.js text_file.txt
in this case make sure that files are in the same directory.
or you can run it with command:
learnyounode program_name.js
and than default text file will be provided by learnyounode. You can watch content of this text file by using
console.log(buffer)
Problem statement says
The full path to the file to read will be provided as the first
command-line argument.
So you've to pass the path/to/file as an argument.
Remember process.argv
you should use the following method to execute .js files
node program_name.js /path/to/text_file_name
rather than
learnyounode run program_name.js /path/to/text_file_name
on this method, Node.js will run your program with specify files of you enter on the command-line-interface.
wish this answer can help you programming. :)

Resources