how nagios disable contact_groups? - monitoring

In Nogios configurations, I have 2 contacts and 1 contact_group which just include 1 contact, like bellow:
define contact{
contact_name one
}
define contact{
contact_name two
}
define contactgroup{
contactgroup_name admins
members one
}
I set my service like this
define service {
name xxx-service
...
contacts two
}
when the service trigger, I got two email one is from "one" the other one is from "two".
is there default contact_group or something make this happen? and how can I do to make it just send message to "two"?

The generic-service in Nagios has this setting in it:
define service{
name generic-service
contact_groups admins
; ... more stuff
}
So emails are sent to the admins group (for you it's contact one) AND to your contact two.
You need to create a new contact group for contact two and override the contact_groups in your service.
For example:
define contact{
contact_name one
}
define contact{
contact_name two
}
define contactgroup{
contactgroup_name admins
members one
}
define contactgroup{
contactgroup_name helpers
members two
}
define service {
name xxx-service
...
contact_group helpers
}

Related

How to define Grails Domain Objects Relationships

Hi I am new to Grails and I would like to seek your expert advise on how to define the domain class in Grails for the following scenario:
A buyer can buy many items
A delivery can contain many items, not necessary all the items the buyer has bought, as some items will be delivered at a later time.
A delivery cannot contain any new items that the buyer hasn't purchased.
So the following is the relationships between them:
One buyer can have many items
One buyer can have many deliveries
One delivery can have many items
I have defined the domain classes as such; but the result. Can the experts point out to me what I have done wrong? Thank you so much!
class Buyer {
static constraints = {
}
String buyerName
static hasMany = [purchases : GoodsPurchased]
}
class GoodsPurchased {
static constraints = {
delivery nullable:true
}
String goodsName
static belongsTo = [ buyer: Buyer, delivery : Delivery ]
}
class Delivery {
static constraints = {
}
Date deliveryDate
static belongsTo = [ buyer : Buyer ]
static hasMany = [ purchases : GoodsPurchased ]
}
A delivery can have one or multiple items that the buyer purchased; as not all the items are necessary for delivery. How do we define in the domain class that - a delivery can only contain items have have been purchased by the buyer before? How do we do that restriction in Grails?
If you want to achieve this in the Domain Class, you can check these business rules in the beforeInsert() and the beforeUpdate() that gets fired before the objects are inserted or updated in the domain class.
You can get more information about this here: http://gorm.grails.org/6.0.x/hibernate/manual/
However, the best place to implement these business logics are still in Services, or restrict the list in GSP for the users to select.
Hope this helps.

Grails 3: find domains that were added to another one in many-to-many relationship (No value specified for parameter 1

I'm a Grails newbie and I found the following obstacle:
I have 2 domains: Course and Student, they have a many-to-many relationship (a Course can have several students, a student can enroll in several courses) and the student belongs to the course.
So, when I add a student to a course, I want to be able to find what Courses have added a specific student.
I tried to use:
def s = Student.get(id)
def c = Course.findAllByStudents(s)
But grails keeps telling me "No value specified for parameter 1".
Can you guys throw some light into this?
Course.findAllByStudents expects as parameter Set of Students but you are supplying it with single instance of Student, that's why you are getting "No value specified for parameter 1".
To find in what Courses is Student. If you created domain classes like this:
class Course {
//some Course attributes
static hasMany = [students: Student]
}
class Student {
//some Student attributes
static hasMany = [courses: Course]
static belongsTo = Course
}
then you can simply use s.courses.
If you are not two-way mapping that relationship. You can create criteria like this:
Course.withCriteria {
createAlias 'students', 's'
eq 's.elements', s
}

Grails - Mapping and Data Binding multiple collections of the same Domain Class

I have a domain class (let's call it security) and it needs three "one to many" relationships with another domain class (let's call it role). The three relationships are "current", "previous", and "new".
Basically I'm hoping to do something like this (in reality it's more complicated, but this will do to illustrate things):
class Security
{
static hasMany = [current: Role, previous: Role, new: Role]
Set current
Set previous
Set new
}
class Role
{
static belongsTo = [security: Security]
String name
}
Unfortunately something like this doesn't work since the Role domain class maps to only one table and that one table has only one column for the Security class' ID.
Is this possible without creating three separate Role classes and instead just map one class to multiple tables?
I'm also looking at the possibility of simply including a flag in the Role class to signal whether the role is current, previous, or new and only having one "one to many" relationship in the Security class. However, this approach is causing issues with data binding, since my HTML form would need to send two pieces of information for each role (the name property and also the type). Since these roles are listed in a HTML select statement I can only send one piece of information (the name).
If you do not depend on the belongsTo in Role (you have to remove it) you can use joinTable:
class Security {
static hasMany = [current: Role, previous: Role, next: Role]
static mapping = {
current joinTable: [name:'current']
previous joinTable: [name:'previous']
next joinTable: [name:'next']
}
}
You could use Grails mappedBy, just like below, if creating 3 fields inside the Role is not an issue:
class Security {
static hasMany = [current: Role, previous: Role, new: Role]
static mappedBy = [current: 'securityForCurrent',
previous: 'securityForPrevious', new: 'securityForNew']
}
class Role {
String name
Security securityForCurrent
Security securityForPrevious
Security securityForNew
}

How to track changes to a GORM-managed collection?

Imagine the following domain classes:
class User {
static hasMany = [ roles: Role ]
List<Role> roles
User() {
roles = new ObservableList<>()
roles.addPropertyChangeListener({ event -> ... } as PropertyChangeListener)
}
}
class Role {
String name
}
My intention is to perform some actions each time an element is added to / removed from the roles collection; this includes 1) populating roles from database, and 2) further manipulation by a user. If a User instance is just created (and not persisted), I am able to catch notifications. After the call to save() method, the ObservableList is still intact. But later, for example, when I perform a User.find...() from a controller, the original ObservableList is replaced by Hibernate's org.hibernate.collection.PersistentList, and obviously there are no notifications anymore.
How can I implement a change-aware list that would be compatible with GORM?

GORM/Grails - add extra column to a joinTable expression

I have a Domain Class setup similar to this
class NewsStory {
String headline
static hasMany = [channels:Channel]
static mapping = {
table 'NewsStory'
addresses joinTable:[name:'Article_Channel', key:'ArticleId', column:'ChannelId']
}
}
in the Article_Channel table i need to have an extra column populated called ArticleType say. Its value will always be the same e.g. 'news' for this domain class, but will be differnt for others e.g. 'blog'
Channel is just something like 'Security' etc
Is there a way?
Thanks
One option would be be to create your own many-to-many mapping class and add the field in there.
http://grails.org/Many-to-Many+Mapping+without+Hibernate+XML
So, for example:
class ArticleChannel {
NewsStory newsStory
Channel channel
String articleType
}
Then, your NewsStory and Channel classes would hasMany the ArticleChannel class.

Resources