mardi 1 octobre 2019

JIRA - find a plugin usage in a Workflow (groovy Script Runner + SQL version)

 Know where/if  a plugin is used. Both have to be adapted to match a specific plugin.

First version gives more data but requires ScriptRunner.

Second version only uses SQL, but is less extensive.


You need to know what you're looking for : com.innovalog.jmwe.jira-misc-workflow-extensions


Script Groovy

Adapted from :  https://answers.atlassian.com/questions/205094/how-to-find-all-workflows-which-are-using-postfunctions-of-a-plugin

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.workflow.JiraWorkflow
import com.atlassian.jira.workflow.WorkflowManager
import java.util.regex.Matcher
  
String searchText = 'com.innovalog.jmwe.jira-misc-workflow-extensions'
  
WorkflowManager workflowManager = ComponentAccessor.getWorkflowManager()
Collection<JiraWorkflow> workflows = workflowManager.getWorkflows()
  
String result = "Workflow;Function;Type;Action;Step\r\n<br/>"
  
workflows.each{workflow ->
    def workflowXml = workflow.descriptor.asXML()
    Matcher m = workflowXml =~ /${searchText}/
    if (m.find()) {
        String workflow_name = "${workflow.name}${if(!workflow.isActive()){";(inactive)"} else ';active'}${if(workflow.isDraftWorkflow()){"(draft)"} else ''}"
        def wf = new XmlParser().parseText(workflowXml)
        List<Node> wf_flat = wf.depthFirst()
        wf_flat.each{
            if (it.text() ==~ /.*${searchText}.*/){
                result += "$workflow_name;${getNodeInfo(it,searchText)}\n\n<br/>"
            }
        }
    }
}
result
  
String getNodeInfo(Node n, String search) {
    String nodetext = ''
    nodetext += "${n.text() - search}"
    def p = n.parent()
    while (p) {
        switch (p.name()) {
            case '"post-functions"':
                nodetext += ";post-function "; break
            case 'validators':
                nodetext += ";validator "; break
            case 'conditions':
                nodetext += ";condition "; break
            case 'action':
                nodetext += ";${p.attribute('name')} (${p.attribute('id')})"; break
            case 'step':
                nodetext += ";${p.attribute('name')} (${p.attribute('id')})"; break
            case 'global-actions':
                nodetext += ";GLOBAL "; break
            case 'initial-actions':
                nodetext += ";INITIAL "; break
  
        }
        p = p.parent()
    }
    return nodetext
}

 

SQL Query

SELECT
  workflowscheme.name,
  workflowschemeentity.scheme,
  issuetype.pname,
  workflowschemeentity.issuetype
FROM
  issuetype,
  workflowschemeentity,
  workflowscheme
WHERE
issuetype.id = workflowschemeentity.issuetype and
workflowscheme.id = workflowschemeentity.scheme and
  workflowschemeentity.workflow in
    (SELECT
        jiraworkflows.workflowname
    FROM
        jiraworkflows
    WHERE
        jiraworkflows.descriptor like '%com.company.plugin%');

mercredi 21 août 2019

JIRA Python script : iterate to get the JQL result

Python 2.7 script to :

  • query the result of a JIRA search query in JQL
  • iterate so that we do not get all the data at once but only by small batches
  • print the result list

Pre-requesites :

  • python
  • https://pypi.org/project/atlassian-python-api/
  • https://atlassian-python-api.readthedocs.io/en/latest/index.html
  • some JIRA Server or JIRA Cloud + credentials
    • Note that the auth for JIRA Cloud might change a bit



from atlassian import Jira
import json

#auth for JIRA Server
jira = Jira(
    url='https://support.valiantys.com',
    username='username',
    password='password')
# Get the SERVER issues that are Running
JQL = 'project = DEMO AND resolution = Unresolved AND issuetype = "Story" AND status = "In Progress" ORDER BY cf[16032] DESC, cf[15857] DESC'

data_tmp = {}   # data we progressively get each interation
issues_all = [] # full list of issues
issues_tmp = {} # list of issues during this iteration

next_start = 0
size = 50

while size > 0 :
        print("-------- trying to get issues:%s..%s" % (next_start, next_start+size))
        data_tmp = jira.jql(JQL, start=next_start, limit=size)
        next_start += size
        issues_tmp = data_tmp['issues']
        size = len(data_tmp['issues'])
        issues_all.extend(issues_tmp)

print ("(final) #issues=%s" % len(issues_all))

# now we can do things with the data
for x in issues_all:
print("%s %s %s %s" % (x['key'], x['fields']['customfield_16032'], x['fields']['customfield_15862'], x['fields']['customfield_15857']))

samedi 17 août 2019

Stress-ng - workload for testing

 (src = https://www.loggly.com/blog/performance-monitoring-aws-cloudwatch-metrics/ )

Step 1. Installing and Running Stress-ng

Stress-ng is a load simulator available for the Ubuntu operating system. The utility has a wide variety of command line switches used for customizing the load. The installation is fairly simple as well:

# apt-get install stress-ng

More details about stress-ng can be found on the Ubuntu man page.

Once the tool is installed, it can be run as a command to simulate a CPU load with the following:

4 worker threads
80% load
Timeout after 25 minutes (1,500 seconds)

# stress-ng --timeout 1500 --cpu 4 --cpu-load 80

CloudWatch Dashboard EC2 CPUUtilizationAs the CPU becomes more and more loaded, the the CPUUtilization metric in CloudWatch also reflects it:

jeudi 15 août 2019

HAR analyser

https://toolbox.googleapps.com/apps/har_analyzer/

vendredi 7 juin 2019

JIRA Script Runner log debug

snippet of code to use the output logs in ScriptRunner Adaptavist groovy scripts  

ScriptRunner log.debug

tool

ScriptRunner for JIRA

version

8.1.1

use case
log.debug SR script


/***********/
import org.apache.log4j.Logger
import org.apache.log4j.Level
 
def log = Logger.getLogger("com.scriptname")
log.setLevel(Level.DEBUG)
/***********/
 
//and then, for example to print the variable trem
log.debug "trem=${trem}"


example : 



mardi 9 avril 2019

Mac OS X : show (hidden) .files in the finder.

Finder options:
  1.  CMD + Shift + .
Terminal options + restart finder:
  1. Open Terminal found in Finder > Applications > Utilities.
  2. In Terminal, paste the following:
      defaults write com.apple.finder AppleShowAllFiles YES.
  3. Press return.
  4. Hold the 'Option/alt' key, then right click on the Finder icon in the dock and click Relaunch.


from :
https://ianlunn.co.uk/articles/quickly-showhide-hidden-files-mac-os-x-mavericks/



vendredi 18 janvier 2019

Curl : get cert and connect using it

 Obtain cert from self signed site

openssl s_client -showcerts -connect 75.74.58.21:443 </dev/null 2>/dev/null | sed -n '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/p' | grep -m1 -B-1 -- '-----END CERTIFICATE-----'  > cert.pem


Connect with cert

curl --cacert cert.pem https://hostname.com