DaanHoogland commented on a change in pull request #3232: Cadf events URL: https://github.com/apache/cloudstack/pull/3232#discussion_r280010037
########## File path: server/src/main/java/com/cloud/event/Cadf.java ########## @@ -0,0 +1,286 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package com.cloud.event; + +import com.cloud.exception.InvalidParameterValueException; +import com.google.gson.annotations.Expose; +import org.apache.log4j.Logger; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.text.SimpleDateFormat; +import java.util.HashMap; +import java.util.UUID; + +public class Cadf { + + //private class variables have no underscore prefix (as instructed in Coding conventions document - + // Naming Conventions - Instruction 6) because the whole class is being logged and is more readable + // without underscores + @Expose (serialize = false) + private static final Logger s_logger = Logger.getLogger(Cadf.class); + + @Expose + private String typeURI; + @Expose + private String id; + @Expose + private String eventType; + @Expose + private String action; + @Expose (serialize = false) + private Taxonomies.Action _tmpAction; + + @Expose + private String csaction; //CloudStack original Action + @Expose + private String outcome; + @Expose + private String eventTime; + + @Expose + private Resource observer; + @Expose + private Resource initiator; + @Expose + private Resource target; + + //TODO + private String measurement; + private String reason; + + @Expose (serialize = false) + public static HashMap<String, String> eventExtraInformation = new HashMap<String, String>(); + + /** + * @param event is the generic CS event + */ + public Cadf(EventVO event) { + String eventtarget; + String eventaction; + + typeURI = "http://schemas.dmtf.org/cloud/audit/1.0/event"; + + //Event unique identifier + id = event.getUuid(); + + if (!event.getType().contains(".")) { + eventaction = Taxonomies.Action.UNKNOWN.getValue(); + eventtarget = Taxonomies.Resource.UNKNOWN; + } else { + //Substrings "VM" from VM.CREATE, "ROLE.PERMISSION" from ROLE.PERMISSION.CREATE etc + eventtarget = new String(event.getType().substring(0, event.getType().lastIndexOf("."))); + + //Substrings "CREATE" from VM.CREATE, "CREATE" from ROLE.PERMISSION.CREATE etc. + // +1 is used to ignore the "." before substring + eventaction = new String(event.getType().substring(event.getType().lastIndexOf(".") + 1)); + + //eventtarget is event's Target Review comment: looks like these comments should be on the field declarations. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services