Creating Zabbix trigger with item from different template - monitoring

I have an item in Template A and would like to have a trigger for only a subset of hosts that have the Template A configured for them.
I would not like to create the trigger on Template A and manually disable it for the hosts I don't need it for (I have too many hosts, might need additional triggers, might need to fine-tune (that re-enables them)), so I created Template B and assigned to the hosts I'd like to have the new trigger.
I tried to...
create a trigger with expression {Template B:item}>value, but Zabbix complained that Template B has no such item (which is true if only considering this template but Template A is also assigned to all hosts). And I cannot create the item in Template B as it conflicts with the other.
create a trigger on Template B and reference the item in Template A, but the trigger moved to Template A and got applied to all hosts.
create a macro for Template B, assigned it to the hosts I need, and added a new trigger to Template A with expression {$MACRO_NAME}=1 and {Template A:item}>limit.
What is the proper solution for this case?
(If it matters, the server and hosts are running Zabbix version 3.2.1 and Debian Linux.)

You can use Macro.
define a macro in your template and change value of this according of host.
you can change value of macro with zabbix api.

Normal flow is this:
Link Template B to Template A.
Apply Template B only on the required host.
Create a trigger for the item in Template A into Template B.
The trigger (of step 3) should be invoked only for the required host (of step 2) and not where Template B is not applied.
The claim that the trigger moved to Template A and got applied to all hosts doesn't seem correct.

Related

setting sdk_container_image in flex template

In order to provide hermetic builds and runtime, we currently build custom flex template and worker images. As part of deployment, we build the flex template and we can specify the custom flex template image but not the custom worker image - we have to pass it to dataflow separately when invoking the flex template. This creates hidden dependencies that we need to track as part of the release process elsewhere (and seems to go against the design of flex templates of being self-contained). Is there a way to bake at least a default for the worker image ( sdk_container_image ) into the template?
In general, if you want to have a default for a template parameter, you can just use the the #Default annotation on it and change the default value for every template version you build. Though in this particular case, since sdkContainerImage parameter is declared in DataflowPipelineOptions in Java SDK (or WorkerOptions in Python SDK), and you can't control its default from the user code, I'd try to set the parameter value programmatically in the template code.
I think something like this should work, but I haven't tested it:
DataflowPipelineOptions options =
PipelineOptionsFactory.fromArgs(args).as(DataflowPipelineOptions.class);
if (options.getSdkContainerImage() == null || options.getSdkContainerImage().isEmpty()) {
// Set the default if not already set by the template runner.
options.setSdkContainerImage("...");
}
Pipeline pipeline = Pipeline.create(options);
// ...
This is for Java, but you can do a similar thing with Python SDK.

Dynamic parameter selection on jenkins

I have a build/deploy job on jenkins, and user can select multiple items to be deployed with multi select parameter. I retrieve those values dynamically from db table with a groovy script.
Problem is that some of the variables should be linked. Meaning; when user selects item X, item A and item B also should be selected.
Is there a way of triggering a selection event on jenkins multi select? or should I use something else?
Thanks.
After spending some time I found a way to do this using Active Choices Plugin
1- I kept my initial extended choice parameter lets name it COMPONENTLIST
2- Then I created another paramateter as Active Choices Reactive Reference Parameter lets name it COMPONENT_IDS
2a- I added COMPONENTLIST as referenced parameter in COMPONENT_IDS. And set the Choice Type as Formatted HTML and also selected Omit value field
2b- I used following groovy script to collect initial selection and make modifications on it and returned as in step 2c
def output = COMPONENTLIST.split(',').collect{it as int}
2c- tricky part here! It is different how you pass the paramater to build stage. Following line helped me to pass COMPONENT_IDS to build.
output = output.join(",")
return "<b>${output}</b><input type=\"hidden\" name=\"value\" value=\"${output}\" />"

How can I show all Jenkins jobs in one view, even if they are contained in folders?

I want to see all jobs that are defined on our Jenkins.
We use folders to structure our jobs, yet we also would like to have an overview view of all jobs without this folder structure, i.e., a flattened list of our jobs.
The first step is to create a new view:
This view has to be named and as view type one has to select "List View":
In the configuration view, following points have to be set:
Recurse in subfolders: yes
Use a regular Expression to include jobs into the view: yes
Regular expression: .*
This lists all jobs running on Jenkins in one view.

How to select a node name as a parameter in jenkins using a selection list of some sort

I need to know if there is a plugin of some sort that you can select a node from a jenkins job and use that node name as a parameter to be passed to a Windows batch command
I have played with the Configuration Matrix using an Elastic-Axis or Slaves (Screenshot below where you can tick the names) plugins
But these all go and execute the Windows batch command on that selected node.
I don't want to execute it on that server but rather on the main node and only pass the value of the slave/label to the windows batch command.
I were able to do it as described here but that involves 2 jobs and a groovy scripts to interrogate the slaves/nodes config. Write it to a properties file and pass the properties file to the next job.
Jenkins: How to get node name from label to use as a parameter
I need to do about 30 jobs of these and hence would like to try to do all in one job - if I used my solution in the link above, 30 jobs would double in 60 jobs and maintenance would be kind of a nightmare.
I also would not like to have a string parameter and hard code the name of the slave/node as that will not ensure the use of only the available slaves/nodes but any server name can be entered and that would can be a problem where someone can mistype a server name for example pointing to a Production server instead of a test server.
https://wiki.jenkins-ci.org/display/JENKINS/NodeLabel+Parameter+Plugin
After installing this plugin you will have an option to add a Node parameter to Jenkins job. It will have a list of all slaves available on current master.
You can use the active choice parameter plugin
https://plugins.jenkins.io/uno-choice/
with a little groovy script to list node names in a parameter selection box.

How to use Extended Choice Parameter plugin for check box

Currently I am using Choice parameter to input the hostname in a drop-down like below.
server1
server2
server3
I am include the selected value in property.
Server=%Hostname%
Also I am invoking the same in post build actions-->Email Notification-->Subject-->Login success for $Hostname.
But my requirement is instead of a drop-down I need a check box option for server1, server2 & server3 so that I can select multiple servers at one time and build the job.
Also I need to include the hostname in property and in email subject. But the Email subject should not contain the actual hostname (server), instead it has to be a different name.
Let's say,
server1 = DEV
server2 = QA
The property should take "server1" value and the email suject should take "DEV".
I am trying to use Extended Choice Parameter plugin, but I am stuck, so any help would be really appreciated!
Extended Choice Parameter plugin is the way to go for such requirement. You need to select Extended Choice Parameter from the drop-down list as shown below.
Once you select that option, you will see another drop-down with the name Parameter Type as shown in the snapshot below. Select Multi Select from that drop-down. Enter the server names in Value box. Comma (,) is the delimiter.
Now if you run the command echo "Server: $Hostname" on *nix systems after selecting one (or more than one) server, you will get all the selected server(s) in the command output.
Now to address your query of displaying names such as Dev/QA instead of actual server names, you will obviously have to do some amount of scripting. Since you are taking the server names in a string, you will first have to split the string using comma (,) as delimiter to fetch individual values (servers). And then you will have do check each server and assign values to it. A pseudo code such as:
if ( str eq server1 ) {
host = QA;
} elsif ( str eq server 2 ) {
host = Dev;
} and so on...
I wrote a similar script in Perl few back back. You can use your language of choice (bash, batch etc.)
To pass these variables in subject line of your mail etc., you will have to use EnvInject Plugin as suggested by Slav. You can write the value (QA/Dev) in some file while running your if...else code so that it could be later used by the EnvInject plugin. Just in case, if you want an alternative way, you can simply use the system's mail command depending on the flavor you have.
With the Extended Choice Parameter, you can change between dropdown/multiselect/checkbox/radio-button by selecting the value called "Parameter Type". If you don't see that, you probably have a very old version of that plugin.
As for the second part of your question: you are going to have to do that mapping in your scripts, inject it using EnvInject plugin, and then use the injected value in your email

Resources