opsrampcli 1.7.3__tar.gz → 1.8.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: opsrampcli
3
- Version: 1.7.3
3
+ Version: 1.8.0
4
4
  Summary: A command line interface for OpsRamp
5
5
  License: MIT
6
6
  Author: Michael Friedhoff
@@ -107,7 +107,7 @@ class DataSource():
107
107
  logger.info('Validating job dedup precedences')
108
108
  for precedence in precedences:
109
109
  if precedence['field'] not in df.columns:
110
- msg = f'Field {field} is specified in deduplicate.precedence[].field in the job file, but is not a valid field name. In the job file check source.urlsource.query_parameters.fields and fieldname_mapping.'
110
+ msg = f'Field {precedence["field"]} is specified in deduplicate.precedence[].field in the job file, but is not a valid field name. In the job file check source.urlsource.query_parameters.fields and fieldname_mapping.'
111
111
  logger.error(msg)
112
112
  raise DataSource.DataSourceException(msg)
113
113
  if precedence['operation'] not in DataSource.DEDUP_PRECEDENCE_OPERATIONS:
@@ -125,27 +125,30 @@ class DataSource():
125
125
 
126
126
  for idx,dup in dups.iterrows():
127
127
  dedup_done = False
128
- query_str_base = ' & '.join([f'`{key}` == "{val}"' for key,val in dup.drop('count').items()])
129
- for precedence in precedences:
128
+ query_str_base = ' & '.join([f'`{key}` == "{val.replace("\"","\\\"")}"' for key,val in dup.drop('count').items()])
129
+ local_vars = {}
130
+ for i, precedence in enumerate(precedences):
131
+ var = f"value_{i}"
130
132
  if dedup_done:
131
133
  break
132
- if precedence['operation'] == 'EQUALS':
133
- query_str = query_str_base + f' & `{precedence["field"]}` == "{precedence["value"]}"'
134
+ if precedence['operation'] == 'EQUALS':
135
+ local_vars[var] = precedence["value"]
136
+ query_str = query_str_base + f' & `{precedence["field"]}` == @{var}'
134
137
  elif precedence['operation'] == 'MAX':
135
- maxval = df.query(query_str_base)[precedence["field"]].max()
136
- query_str = query_str_base + f' & `{precedence["field"]}` == "{maxval}"'
138
+ local_vars[var] = df.query(query_str_base)[precedence["field"]].max()
139
+ query_str = query_str_base + f' & `{precedence["field"]}` == @{var}'
137
140
  elif precedence['operation'] == 'MIN':
138
- minval = df.query(query_str_base)[precedence["field"]].min()
139
- query_str = query_str_base + f' & `{precedence["field"]}` == "{minval}"'
141
+ local_vars[var] = df.query(query_str_base)[precedence["field"]].min()
142
+ query_str = query_str_base + f' & `{precedence["field"]}` == @{var}'
140
143
 
141
- match_check_df = df.query(query_str)
144
+ match_check_df = df.query(query_str, local_dict=local_vars)
142
145
  remaining = len(match_check_df.index)
143
146
  if remaining == 1:
144
- df = df.query(f'not ({query_str_base}) or ({query_str})')
147
+ df = df.query(f'not ({query_str_base}) or ({query_str})', local_dict=local_vars)
145
148
  dup['count'] = 1
146
149
  dedup_done = True
147
150
  elif remaining > 1 and remaining < dup['count']:
148
- df = df.query(f'not ({query_str_base}) or ({query_str})')
151
+ df = df.query(f'not ({query_str_base}) or ({query_str})', local_dict=local_vars)
149
152
  dup['count'] = remaining
150
153
  if not dedup_done:
151
154
  logger.warn(f'Unable to deduplicate with current job settings: {dup.to_json()}')
@@ -315,7 +315,7 @@ async def bulk_update_static_attributes(ops, job, df: pd.DataFrame, resource_map
315
315
 
316
316
  if resource_id:
317
317
  if (
318
- "tags" in existing_resources_by_id[resource_id]
318
+ "tags" in existing_resources_by_id[resource_id] and existing_resources_by_id[resource_id]["tags"]
319
319
  and any(
320
320
  attr['name'] == cleaned_static_attr_name and attr['value'] == df[static_attr_name][0]
321
321
  for attr in existing_resources_by_id[resource_id]['tags']
@@ -405,7 +405,7 @@ async def set_non_static_attributes_on_resource(ops:OpsRampEnv, args, job:dict,
405
405
  if args.writeblanks:
406
406
  if is_new:
407
407
  continue
408
- if "tags" in existing_resources_by_id[resourceId] and any(attr['name']==column for attr in existing_resources_by_id[resourceId]['tags']):
408
+ if "tags" in existing_resources_by_id[resourceId] and existing_resources_by_id[resourceId]["tags"] and any(attr['name']==column for attr in existing_resources_by_id[resourceId]['tags']):
409
409
  # There are one or more values and we need to remove it/them
410
410
  remove_values = [obj['value'] for obj in existing_resources_by_id[resourceId]['tags'] if obj['name'] == column]
411
411
  for remove_value in remove_values:
@@ -414,14 +414,14 @@ async def set_non_static_attributes_on_resource(ops:OpsRampEnv, args, job:dict,
414
414
 
415
415
  else:
416
416
  continue
417
- elif not is_new and "tags" in existing_resources_by_id[resourceId] and any(attr['name']==column and attr['value']==resource[columnhead] for attr in existing_resources_by_id[resourceId]['tags']):
417
+ elif not is_new and "tags" in existing_resources_by_id[resourceId] and existing_resources_by_id[resourceId]["tags"] and any(attr['name']==column and attr['value']==resource[columnhead] for attr in existing_resources_by_id[resourceId]['tags']):
418
418
  # It already has the same value for this attr, no need to update
419
419
  continue
420
420
  else:
421
421
  # It has no value or a different value for this attr so we need to update
422
422
 
423
423
  # If it has a different value we need to remove it first
424
- if not is_new and "tags" in existing_resources_by_id[resourceId] and any(attr['name']==column for attr in existing_resources_by_id[resourceId]['tags']):
424
+ if not is_new and "tags" in existing_resources_by_id[resourceId] and existing_resources_by_id[resourceId]["tags"] and any(attr['name']==column for attr in existing_resources_by_id[resourceId]['tags']):
425
425
  await ops.unset_custom_attr_on_devices_async(attrinfo[attrname]['id'], resourceId)
426
426
 
427
427
  logger.info(f'Setting tag {attrname} = {resource[columnhead]} on resource "{resource["resourceName"]}"')
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "opsrampcli"
3
- version = "1.7.3"
3
+ version = "1.8.0"
4
4
  description = "A command line interface for OpsRamp"
5
5
  authors = ["Michael Friedhoff <michael.friedhoff@opsramp.com>"]
6
6
  license = "MIT"
File without changes