I want to retrieve data from Zabbix API using ZabbixAPI.
So I made API JSON like below.
zabbixapi.problem.get(time_from=time_from,
time_till=time_till,
selectHosts = ["host","name"],
sortorder = "DESC",
output = "extend",
monitored = 1)
Result has no host information.
Result is below.
[{'eventid': '401154', 'source': '0', 'object': '0', 'objectid': '18265', 'clock': '1569375897', 'ns': '887610916', 'r_eventid': '0', 'r_clock': '0', 'r_ns': '0', 'correlationid': '0', 'userid': '0', 'name': 'Optical power is low on port 7', 'acknowledged': '0', 'severity': '3', 'suppressed': '0'}, {'eventid': '401456', 'source': '0', 'object': '0', 'objectid': '30714', 'clock': '1569401534', 'ns': '909385820', 'r_eventid': '0', 'r_clock': '0', 'r_ns': '0', 'correlationid': '0', 'userid': '0', 'name': 'Optical power is low on port 33', 'acknowledged': '0', 'severity': '3', 'suppressed': '0'}]
I think "selectHosts" does not work.
How can I get problem with host information?
According to the documentation, problem.get does not have a selectHosts parameter.
Every item of the returned object has a eventid value, you can use it in a event.get call, which supports selectHosts.
Or you can do a single event.get call with selectHosts plus a filter for value = 1, that corresponds to the "Problem" state (see the documentation for the event object)
Using curl.
To get problem event ids:
curl -H "Content-Type: application/json-rpc" -X POST my_zabbix_url -d '{"jsonrpc": "2.0","method": "problem.get","params": {},"auth": "my_token","id": 0}'
To get hosts based on event id:
curl -H "Content-Type: application/json-rpc" -X POST my_zabbix_url -d '{"jsonrpc": "2.0","method": "event.get","params": {"selectHosts": ["host","name"],"output": "extend","select_acknowledges": "extend","objectids": "my_event_object_id","sortfield": ["clock", "eventid"],"sortorder": "DESC"},"auth": "my_token","id": 0}'
Related
I try to run a mysql statement via docker exec api -> https://docs.docker.com/engine/api/v1.41/#operation/ContainerExec
My Statement looks like this
{
"AttachStdin": false,
"AttachStdout": true,
"AttachStderr": true,
"DetachKeys": "ctrl-p,ctrl-q",
"Tty": false,
"Cmd": [
"bin/bash","-c", "mysql -uroot -ptesttest -e 'INSERT INTO `mandator_1`.`terminal` (`serialNumber`, `name`, `isActive`, `status`, `profileId`, `businessId`, `divisionId`, `ipAddress`, `groupId`, `setupVersion`, `macAddress`, `authType`) VALUES ('54321', '54321', '1', NULL, '1', '1', NULL, '172.45.17.197', '1', NULL, 'E4-F1-D3-FD', '2');' mandator_1"
]
}
but when i run the statement i get an error
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '.17.197, 1, NULL, E4-F1-D3-FD, 2)' at line 1
i think my escaping is wrong but at which point?
Try to change quote by double quote:
VALUES (\"54321\", \"54321\", \"1\", ...., \"2\");
I have a languages tabel in mysql db where I have an Id that is autoincremented:
CREATE TABLE `languages` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
`Language` varchar(45) NOT NULL,
PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
When I run my sequelize-auto command:
sequelize-auto -h 127.0.0.1 -d DBNAME -u root -x PASSWORD -p 3306 --dialect mysql -c MYPATH\json/sequelize-auto-settings.json -o MODELSPATH\src\assets\models
I get the following modeL:
/* jshint indent: 1 */
module.exports = function(sequelize, DataTypes) {
return sequelize.define('languages', {
Id: {
type: DataTypes.INTEGER(11),
allowNull: false,
primaryKey: true,
field: 'Id'
},
Language: {
type: DataTypes.STRING(45),
allowNull: false,
field: 'Language'
}
}, {
tableName: 'languages'
});
};
Why am I missing the autoincrment : true on the Id field ?
I can add it manually but it defeates the purpose of using sequelize -auto
This took some time and I can honstly say I still dont know what the issue was.
I solved it by installing sequelize-auto v3 and then it worked as intended.
I want to use a json file for user management in ansible. Therefore I created a json file containing all the user and groups like this (user_group_management.json):
{
"linux_users": [
{
"name": "myuser",
"uid": 1003,
"group": "myuser",
"groups": "users,sudo",
"shell": "/bin/bash",
"password": <password as sha-512>,
"create_home": "yes",
"home": "/home/user",
"hosts": ["hostname1","hostname2","hostname3"]
},
{...},
...
],
"linux_groups": [...],
}
Now I wrote an ansible script for adding the users and groups (user_group_management.yml):
- name: User and group management
hosts: all
vars_files:
- user_group_management.json
tasks:
[part for adding groups (no problems here)]
- name: Add users
ignore_errors: yes
user:
name: item.name
uid: item.uid
group: item.group
groups: item.groups
shell: item.shell
password: item.password
create_home: item.create_home
home: item.home
state: present
when: ansible_hostname in item.hosts
loop: "{{ linux_users }}"
When running the ansible script using ansible-playbook --check user_management.yml I get these error messages concerning the "Add users" task:
"msg": "The value 'item.create_home' is not a valid boolean. Valid booleans include: 0, 'on', 'f', 'false', 1, 'no', 'n', '1', '0', 't', 'y', 'off', 'yes', 'true'"
I tried to fix this issue by replacing "create_home": "yes", with "create_home": 1, but it did not change anything. Now I added curly brackets around the variable (item.create_home -> "{{ item.create_home }}") which solved the issue. So now I do not get any error messages again.
Sadly I do not understand why this helped me. I thought that item.create_home is a string ("yes") in the first place and should be an integer (1) after editing the json file. But both give me the errors. Is there an explanation for this phenomenon?
If don't have a lot of experience with json manipulation in ansible however have you tried to change
"create_home": "yes",
to
"create_home": true,
Another solution it to convert the value you expect to be boolean with a jinja filter |bool when using it.
The official documentation provides
- debug:
msg: test
when: some_string_value | bool
as an example with when condition.
For your case it should be
create_home: item.create_home
should become
create_home: "{{ item.create_home | bool }}"
general advice: You should enclose your variables inside "{{ }}"
I'm trying to reset an app-server from an LDAP configuration to default values at the command line using REST but it appears to not be working. The external-security element does not exist on the JSON or the XML marklogic properties webpage located on the 8002 port if it is not set.
http://localhost:8002/manage/v2/servers/App-Services/properties?group\
-id=Default&format=json
I think this might be a bug. I've tried null, 0, \0, [], and many other forms of null in JSON. The XML form does not work either.
curl -X PUT --anyauth -u admin:$(cat pass) --header "Content-Type:application/json" \
-d '{"authentication":"digest", "internal-security":true,"default-user":"nobody", \
"external-security":"" }' \
http://localhost:8002/manage/v2/servers/App-Services/properties?group-id=Default
Returns:
{"errorResponse":{"statusCode":"500", "status":"Internal Server Error",
"messageCode":"XDMP-VALIDATEBADTYPE", "message":"XDMP-VALIDATEBADTYPE: (err:XQDY0027)
validate strict { $nsfix } -- Invalid node type: srvprop:external-security lexical value
\"\" invalid for expected type #srvprop:external-security at
/srvprop:http-server-properties/srvprop:external-security using schema
\"manage-server-properties.xsd\""}}
I just started getting this Error today while using MySQL workbench, and noticed it showing up in my application as far back as saturday. Anyone else getting it?
Have any idea what might be causing it?
ERROR
Error Code: 1290. The MySQL server is running with the --read-only option so it cannot execute this statement
Running just a simple insert generates the error. Eg..
INSERT INTO Job1111.SubsWeld
(fk_SubmissionId, WeldSpool1, WeldSpool2, WeldDrawingNumber, WeldLineNumber, WeldSheetNumber, WeldTimeInForm, WeldLineSpec, WeldNumber, WeldStencil, WeldSize, WeldThickness, WeldType, WeldPosition, WeldMaterial, WeldProcedure, WeldComplete, WeldShared, WeldPercentCompleted, WeldRework, ActivityType, Rev)
VALUES ('66', '5990-363-A', '5990-363-B', 'V-0020-3', '12-V-0020', '3', '0', 'A', '1059', '1059', '24.00', 'Sch. 40', 'BW', '5G', 'CS', '1013 Rev2', '1', '0', '100', '0', '22', '0');